Mailspring/internal_packages/keybase/lib/passphrase-popover.cjsx
Jackie Luo b323275d24 fix(composer): Stop parsing quoted text on each keystroke to prevent composer lag
Summary: We used to parse the quoted text on each keystroke in the composer for a reply so that we could continue to determine what was quoted text. However, that resulted in dramatically slow typing for replies to complex HTML emails. Now, the quoted text isn't a part of the reply until `prepareDraftForSyncback`, after all of the extensions have run their transformations—we use a marker to determine whether quoted text should be appended or not. The quoted text control is now a one-way operation—you can't hide the quoted text after showing it (Gmail-style).

Test Plan: Tested locally (but didn't run unit tests because they won't run on my machine...)

Reviewers: bengotow, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3106
2016-07-21 11:11:14 -07:00

81 lines
2.6 KiB
CoffeeScript

{React, Actions} = require 'nylas-exports'
Identity = require './identity'
PGPKeyStore = require './pgp-key-store'
_ = require 'underscore'
fs = require 'fs'
pgp = require 'kbpgp'
module.exports =
class PassphrasePopover extends React.Component
constructor: ->
@state = {
passphrase: ""
placeholder: "PGP private key password"
error: false
mounted: true
}
componentDidMount: ->
@_mounted = true
componentWillUnmount: ->
@_mounted = false
@propTypes:
identity: React.PropTypes.instanceOf(Identity)
addresses: React.PropTypes.array
render: ->
classNames = if @state.error then "key-passphrase-input form-control bad-passphrase" else "key-passphrase-input form-control"
<div className="passphrase-popover">
<input type="password" value={@state.passphrase} placeholder={@state.placeholder} className={classNames} onChange={@_onPassphraseChange} onKeyUp={@_onKeyUp} />
<button className="btn btn-toolbar" onClick={@_validatePassphrase}>Done</button>
</div>
_onPassphraseChange: (event) =>
@setState
passphrase: event.target.value
placeholder: "PGP private key password"
error: false
_onKeyUp: (event) =>
if event.keyCode == 13
@_validatePassphrase()
_validatePassphrase: =>
passphrase = @state.passphrase
for emailIndex of @props.addresses
email = @props.addresses[emailIndex]
privateKeys = PGPKeyStore.privKeys(address: email, timed: false)
for keyIndex of privateKeys
# check to see if the password unlocks the key
key = privateKeys[keyIndex]
fs.readFile(key.keyPath, (err, data) =>
pgp.KeyManager.import_from_armored_pgp {
armored: data
}, (err, km) =>
if err
console.warn err
else
km.unlock_pgp { passphrase: passphrase }, (err) =>
if err
if parseInt(keyIndex, 10) == privateKeys.length - 1
if parseInt(emailIndex, 10) == @props.addresses.length - 1
# every key has been tried, the password failed on all of them
if @_mounted
@setState
passphrase: ""
placeholder: "Incorrect password"
error: true
else
# the password unlocked a key; that key should be used
@_onDone()
)
_onDone: =>
if @props.identity?
@props.onPopoverDone(@state.passphrase, @props.identity)
else
@props.onPopoverDone(@state.passphrase)
Actions.closePopover()