code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
if hasattr(magic, 'open'): magic_wrapper = magic._libraries['magic'] elif hasattr(magic, 'from_buffer'): magic_wrapper = magic.libmagic else: raise Exception('Unknown magic API') if not hasattr(magic_wrapper, 'magic_version'): # The magic_version function has been i...
def libmagic_version_at_least(version)
checks if the libmagic library installed is more recent than a given version. :param version: minimum version expected in the form XYY (i.e. 5.14 -> 514) with XYY >= 513
5.247622
5.695603
0.921346
with open(path, 'rb') as f: content = f.read() if not ctype: ctype = guess_mimetype(content) # libmagic < 5.12 incorrectly detects excel/powerpoint files as # 'application/msword' (see #179 and #186 in libmagic bugtracker) # This is a workaround, based on file exten...
def mimewrap(path, filename=None, ctype=None)
Take the contents of the given path and wrap them into an email MIME part according to the content type. The content type is auto detected from the actual file contents and the file name if it is not given. :param path: the path to the file contents :type path: str :param filename: the file name t...
2.822806
2.851906
0.989796
for factor, format_string in ((1, '%i'), (1024, '%iKiB'), (1024 * 1024, '%.1fMiB')): if size / factor < 1024: return format_string % (size / factor) return format_string % (size / factor)
def humanize_size(size)
Create a nice human readable representation of the given number (understood as bytes) using the "KiB" and "MiB" suffixes to indicate kibibytes and mebibytes. A kibibyte is defined as 1024 bytes (as opposed to a kilobyte which is 1000 bytes) and a mibibyte is 1024**2 bytes (as opposed to a megabyte which...
3.279661
3.450397
0.950517
nt_list = tmplate.split('%s') template_prefix = '' template_suffix = '' if len(nt_list) == 2: template_suffix = nt_list[1] template_prefix = nt_list[0] else: template_suffix = tmplate return (template_prefix, template_suffix)
def parse_mailcap_nametemplate(tmplate='%s')
this returns a prefix and suffix to be used in the tempfile module for a given mailcap nametemplate string
2.488853
2.280304
1.091457
if mailto_str.startswith('mailto:'): import urllib.parse to_str, parms_str = mailto_str[7:].partition('?')[::2] headers = {} body = u'' to = urllib.parse.unquote(to_str) if to: headers['To'] = [to] for s in parms_str.split('&'): ...
def parse_mailto(mailto_str)
Interpret mailto-string :param mailto_str: the string to interpret. Must conform to :rfc:2368. :type mailto_str: str :return: the header fields and the body found in the mailto link as a tuple of length two :rtype: tuple(dict(str->list(str)), str)
2.466221
2.377586
1.03728
from alot.db.envelope import Envelope headers, body = parse_mailto(mailto_str) return Envelope(bodytext=body, headers=headers)
def mailto_to_envelope(mailto_str)
Interpret mailto-string into a :class:`alot.db.envelope.Envelope`
8.312203
3.760185
2.210584
text = re.sub("\r?\n", "\r\n", text) text = re.sub("^From ", "From=20", text, flags=re.MULTILINE) return text
def RFC3156_canonicalize(text)
Canonicalizes plain text (MIME-encoded usually) according to RFC3156. This function works as follows (in that order): 1. Convert all line endings to \\\\r\\\\n (DOS line endings). 2. Encode all occurrences of "From " at the beginning of a line to "From=20" in order to prevent other mail programs to...
4.709352
3.315403
1.420447
env = os.environ.get(env_name) return env if env else fallback
def get_xdg_env(env_name, fallback)
Used for XDG_* env variables to return fallback if unset *or* empty
3.213256
3.48797
0.921239
res = [] query = re.compile('.*%s.*' % re.escape(query), self.reflags) for name, email in self.get_contacts(): if query.match(name) or query.match(email): res.append((name, email)) return res
def lookup(self, query='')
looks up all contacts where name or address match query
3.883124
3.595094
1.080118
"Set the focus in the underlying body widget." logging.debug('setting focus to %s ', pos) self.body.set_focus(pos)
def set_focus(self, pos)
Set the focus in the underlying body widget.
10.928678
5.992333
1.823777
mid = self.get_selected_mid() newpos = self._tree.parent_position(mid) if newpos is not None: newpos = self._sanitize_position((newpos,)) self.body.set_focus(newpos)
def focus_parent(self)
move focus to parent of currently focussed message
6.777732
6.146414
1.102713
mid = self.get_selected_mid() newpos = self._tree.first_child_position(mid) if newpos is not None: newpos = self._sanitize_position((newpos,)) self.body.set_focus(newpos)
def focus_first_reply(self)
move focus to first reply to currently focussed message
6.611762
5.675159
1.165036
mid = self.get_selected_mid() newpos = self._tree.last_child_position(mid) if newpos is not None: newpos = self._sanitize_position((newpos,)) self.body.set_focus(newpos)
def focus_last_reply(self)
move focus to last reply to currently focussed message
6.675682
5.688576
1.173524
mid = self.get_selected_mid() newpos = self._tree.next_sibling_position(mid) if newpos is not None: newpos = self._sanitize_position((newpos,)) self.body.set_focus(newpos)
def focus_next_sibling(self)
focus next sibling of currently focussed message in thread tree
6.285106
5.648629
1.112678
mid = self.get_selected_mid() localroot = self._sanitize_position((mid,)) if localroot == self.get_focus()[1]: newpos = self._tree.prev_sibling_position(mid) if newpos is not None: newpos = self._sanitize_position((newpos,)) else: ...
def focus_prev_sibling(self)
focus previous sibling of currently focussed message in thread tree
4.806347
4.695998
1.023498
mid = self.get_selected_mid() newpos = self._tree.next_position(mid) if newpos is not None: newpos = self._sanitize_position((newpos,)) self.body.set_focus(newpos)
def focus_next(self)
focus next message in depth first order
6.727513
6.142136
1.095305
mid = self.get_selected_mid() localroot = self._sanitize_position((mid,)) if localroot == self.get_focus()[1]: newpos = self._tree.prev_position(mid) if newpos is not None: newpos = self._sanitize_position((newpos,)) else: newp...
def focus_prev(self)
focus previous message in depth first order
5.011666
4.872224
1.02862
newpos = self.get_selected_mid() newpos = direction(newpos) while newpos is not None: MT = self._tree[newpos] if prop(MT): newpos = self._sanitize_position((newpos,)) self.body.set_focus(newpos) break ne...
def focus_property(self, prop, direction)
does a walk in the given direction and focuses the first message tree that matches the given property
6.5945
6.024095
1.094687
self.focus_property(lambda x: x._message.matches(querystring), self._tree.next_position)
def focus_next_matching(self, querystring)
focus next matching message in depth first order
20.165548
15.332022
1.315257
self.focus_property(lambda x: x._message.matches(querystring), self._tree.prev_position)
def focus_prev_matching(self, querystring)
focus previous matching message in depth first order
20.544886
15.25019
1.347189
self.focus_property(lambda x: not x.is_collapsed(x.root), self._tree.next_position)
def focus_next_unfolded(self)
focus next unfolded message in depth first order
17.064932
14.236121
1.198707
self.focus_property(lambda x: not x.is_collapsed(x.root), self._tree.prev_position)
def focus_prev_unfolded(self)
focus previous unfolded message in depth first order
17.727304
15.435942
1.148443
MT = self._tree[msgpos] MT.expand(MT.root)
def expand(self, msgpos)
expand message at given position
19.302757
19.351433
0.997485
MT = self._tree[msgpos] MT.collapse(MT.root) self.focus_selected_message()
def collapse(self, msgpos)
collapse message at given position
19.626493
20.542688
0.9554
for MT in self.messagetrees(): MT.collapse(MT.root) self.focus_selected_message()
def collapse_all(self)
collapse all messages in thread
20.041468
15.366904
1.304197
first = None for MT in self.messagetrees(): msg = MT._message if msg.matches(querystring): MT.expand(MT.root) if first is None: first = (self._tree.position_of_messagetree(MT), MT.root) self.body.set...
def unfold_matching(self, querystring, focus_first=True)
expand all messages that match a given querystring. :param querystring: query to match :type querystring: str :param focus_first: set the focus to the first matching message :type focus_first: bool
6.908522
6.408489
1.078027
if not isinstance(other, TagWidget): return NotImplemented self_len = len(self.translated) oth_len = len(other.translated) if (self_len == 1) is not (oth_len == 1): return comparitor(self_len, oth_len) return comparitor(self.translated.lower(), ...
def __cmp(self, other, comparitor)
Shared comparison method.
3.455588
3.471139
0.99552
'''Add pseudo headers to the mail indicating whether the signature verification was successful. :param mail: :class:`email.message.Message` the message to entitle :param sigs: list of :class:`gpg.results.Signature` :param error_msg: An error message if there is one, or None :type error_msg: :cl...
def add_signature_headers(mail, sigs, error_msg)
Add pseudo headers to the mail indicating whether the signature verification was successful. :param mail: :class:`email.message.Message` the message to entitle :param sigs: list of :class:`gpg.results.Signature` :param error_msg: An error message if there is one, or None :type error_msg: :class:`st...
3.649087
2.626386
1.389394
'''Get Content-Type parameters as dict. RFC 2045 specifies that parameter names are case-insensitive, so we normalize them here. :param mail: :class:`email.message.Message` :param failobj: object to return if no such header is found :param header: the header to search for parameters, default ...
def get_params(mail, failobj=None, header='content-type', unquote=True)
Get Content-Type parameters as dict. RFC 2045 specifies that parameter names are case-insensitive, so we normalize them here. :param mail: :class:`email.message.Message` :param failobj: object to return if no such header is found :param header: the header to search for parameters, default :par...
4.00449
1.637803
2.445038
malformed = None if len(message.get_payload()) != 2: malformed = u'expected exactly two messages, got {0}'.format( len(message.get_payload())) else: ct = message.get_payload(1).get_content_type() if ct != _APP_PGP_SIG: malformed = u'expected Content-Type:...
def _handle_signatures(original, message, params)
Shared code for handling message signatures. RFC 3156 is quite strict: * exactly two messages * the second is of type 'application/pgp-signature' * the second contains the detached signature :param original: The original top-level mail. This is required to attache special headers to :t...
4.609241
4.012705
1.148662
malformed = False ct = message.get_payload(0).get_content_type() if ct != _APP_PGP_ENC: malformed = u'expected Content-Type: {0}, got: {1}'.format( _APP_PGP_ENC, ct) want = 'application/octet-stream' ct = message.get_payload(1).get_content_type() if ct != want: ...
def _handle_encrypted(original, message, session_keys=None)
Handle encrypted messages helper. RFC 3156 is quite strict: * exactly two messages * the first is of type 'application/pgp-encrypted' * the first contains 'Version: 1' * the second is of type 'application/octet-stream' * the second contains the encrypted and possibly signed data :param ori...
5.929532
5.644768
1.050447
'''Detect and decrypt OpenPGP encrypted data in an email object. If this succeeds, any mime messages found in the recovered plaintext message are added to the returned message object. :param m: an email object :param session_keys: a list OpenPGP session keys :returns: :class:`email.message.Mess...
def decrypted_message_from_message(m, session_keys=None)
Detect and decrypt OpenPGP encrypted data in an email object. If this succeeds, any mime messages found in the recovered plaintext message are added to the returned message object. :param m: an email object :param session_keys: a list OpenPGP session keys :returns: :class:`email.message.Message` po...
4.180449
2.88791
1.447569
return decrypted_message_from_message( email.message_from_bytes(bytestring, policy=email.policy.SMTP), session_keys)
def decrypted_message_from_bytes(bytestring, session_keys=None)
Create a Message from bytes. :param bytes bytestring: an email message as raw bytes :param session_keys: a list OpenPGP session keys
3.87301
4.504388
0.85983
headertext = u'' if headers is None: headers = mail.keys() for key in headers: value = u'' if key in mail: value = decode_header(mail.get(key, '')) headertext += '%s: %s\n' % (key, value) return headertext
def extract_headers(mail, headers=None)
returns subset of this messages headers as human-readable format: all header values are decoded, the resulting string has one line "KEY: VALUE" for each requested header present in the mail. :param mail: the mail to use :type mail: :class:`email.Message` :param headers: headers to extract :type...
2.767918
2.769957
0.999264
ctype = part.get_content_type() raw_payload = remove_cte(part) rendered_payload = None # get mime handler _, entry = settings.mailcap_find_match(ctype, key=field_key) if entry is not None: tempfile_name = None stdin = None handler_raw_commandstring = entry['view'] ...
def render_part(part, field_key='copiousoutput')
renders a non-multipart email part into displayable plaintext by piping its payload through an external script. The handler itself is determined by the mailcap entry for this part's ctype.
6.09903
5.361257
1.137612
enc = part.get_content_charset() or 'ascii' cte = str(part.get('content-transfer-encoding', '7bit')).lower().strip() payload = part.get_payload() sp = '' # string variant of return value bp = b'' # bytestring variant logging.debug('Content-Transfer-Encoding: "{}"'.format(cte)) if cte...
def remove_cte(part, as_string=False)
Interpret MIME-part according to it's Content-Transfer-Encodings. This returns the payload of `part` as string or bytestring for display, or to be passed to an external program. In the raw file the payload may be encoded, e.g. in base64, quoted-printable, 7bit, or 8bit. This method will look for one of...
4.270075
4.099331
1.041652
preferred = 'text/plain' if settings.get( 'prefer_plaintext') else 'text/html' has_preferred = False # see if the mail has our preferred type if types is None: has_preferred = list(typed_subpart_iterator( mail, *preferred.split('/'))) body_parts = [] for part ...
def extract_body(mail, types=None, field_key='copiousoutput')
Returns a string view of a Message. If the `types` argument is set then any encoding types there will be used as the prefered encoding to extract. If `types` is None then :ref:`prefer_plaintext <prefer-plaintext>` will be consulted; if it is True then text/plain parts will be returned, if it is false t...
4.794396
4.69993
1.020099
# some mailers send out incorrectly escaped headers # and double quote the escaped realname part again. remove those # RFC: 2047 regex = r'"(=\?.+?\?.+?\?[^ ?]+\?=)"' value = re.sub(regex, r'\1', header) logging.debug("unquoted header: |%s|", value) # otherwise we interpret RFC2822 enc...
def decode_header(header, normalize=False)
decode a header value to a unicode string values are usually a mixture of different substrings encoded in quoted printable using different encodings. This turns it into a single unicode string :param header: the header value :type header: str :param normalize: replace trailing spaces after new...
7.348948
7.428117
0.989342
self.set_position_collapsed( self.root, self._message.matches(querystring))
def collapse_if_matches(self, querystring)
collapse (and show summary only) if the :class:`alot.db.Message` matches given `querystring`
25.183577
18.858906
1.335368
if self.ro: raise DatabaseROError() if self.writequeue: # read notmuch's config regarding imap flag synchronization sync = settings.get_notmuch_setting('maildir', 'synchronize_flags') # go through writequeue entries while self.writequ...
def flush(self)
write out all queued write-commands in order, each one in a separate :meth:`atomic <notmuch.Database.begin_atomic>` transaction. If this fails the current action is rolled back, stays in the write queue and an exception is raised. You are responsible to retry flushing at a later time if...
4.519431
4.223277
1.070124
if self.ro: raise DatabaseROError() if remove_rest: self.writequeue.append(('set', afterwards, querystring, tags)) else: self.writequeue.append(('tag', afterwards, querystring, tags))
def tag(self, querystring, tags, afterwards=None, remove_rest=False)
add tags to messages matching `querystring`. This appends a tag operation to the write queue and raises :exc:`~errors.DatabaseROError` if in read only mode. :param querystring: notmuch search string :type querystring: str :param tags: a list of tags to be added :type tag...
6.538084
4.668082
1.400593
if self.ro: raise DatabaseROError() self.writequeue.append(('untag', afterwards, querystring, tags))
def untag(self, querystring, tags, afterwards=None)
removes tags from messages that match `querystring`. This appends an untag operation to the write queue and raises :exc:`~errors.DatabaseROError` if in read only mode. :param querystring: notmuch search string :type querystring: str :param tags: a list of tags to be added ...
17.836195
7.816918
2.281743
query = self.query('thread:' + tid) try: return next(query.search_threads()) except StopIteration: errmsg = 'no thread with id %s exists!' % tid raise NonexistantObjectError(errmsg)
def _get_notmuch_thread(self, tid)
returns :class:`notmuch.database.Thread` with given id
5.770431
5.439461
1.060846
mode = Database.MODE.READ_ONLY db = Database(path=self.path, mode=mode) try: return db.find_message(mid) except: errmsg = 'no message with id %s exists!' % mid raise NonexistantObjectError(errmsg)
def _get_notmuch_message(self, mid)
returns :class:`notmuch.database.Message` with given id
6.081974
5.309783
1.145428
db = Database(path=self.path) return [t for t in db.get_all_tags()]
def get_all_tags(self)
returns all tagsstrings used in the database :rtype: list of str
6.242723
4.943669
1.262771
db = Database(path=self.path) return {k[6:]: v for k, v in db.get_configs('query.')}
def get_named_queries(self)
returns the named queries stored in the database. :rtype: dict (str -> str) mapping alias to full query string
10.641587
10.629247
1.001161
# create two unix pipes to redirect the workers stdout and # stderr stdout = os.pipe() stderr = os.pipe() # create a multiprocessing pipe for the results pipe = multiprocessing.Pipe(False) receiver, sender = pipe process = FillPipeProcess(cbl(),...
def async_(self, cbl, fun)
return a pair (pipe, process) so that the process writes `fun(a)` to the pipe for each element `a` in the iterable returned by the callable `cbl`. :param cbl: a function returning something iterable :type cbl: callable :param fun: an unary translation function :type fun:...
4.969511
4.87671
1.019029
assert sort in self._sort_orders q = self.query(querystring) q.set_sort(self._sort_orders[sort]) if exclude_tags: for tag in exclude_tags: q.exclude_tag(tag) return self.async_(q.search_threads, (lambda a: a.get_thread_id()))
def get_threads(self, querystring, sort='newest_first', exclude_tags=None)
asynchronously look up thread ids matching `querystring`. :param querystring: The query string to use for the lookup :type querystring: str. :param sort: Sort order. one of ['oldest_first', 'newest_first', 'message_id', 'unsorted'] :type query: str :param ex...
4.500284
4.572863
0.984128
mode = Database.MODE.READ_ONLY db = Database(path=self.path, mode=mode) q = db.create_query(querystring) # add configured exclude tags for tag in settings.get('exclude_tags'): q.exclude_tag(tag) return q
def query(self, querystring)
creates :class:`notmuch.Query` objects on demand :param querystring: The query string to use for the lookup :type query: str. :returns: :class:`notmuch.Query` -- the query object.
6.181333
6.966818
0.887253
tags = tags or [] if self.ro: raise DatabaseROError() if not is_subdir_of(path, self.path): msg = 'message path %s ' % path msg += ' is not below notmuchs ' msg += 'root path (%s)' % self.path raise DatabaseError(msg) ...
def add_message(self, path, tags=None, afterwards=None)
Adds a file to the notmuch index. :param path: path to the file :type path: str :param tags: tagstrings to add :type tags: list of str :param afterwards: callback to trigger after adding :type afterwards: callable or None
8.760017
8.855889
0.989174
if self.ro: raise DatabaseROError() path = message.get_filename() self.writequeue.append(('remove', afterwards, path))
def remove_message(self, message, afterwards=None)
Remove a message from the notmuch index :param message: message to remove :type message: :class:`Message` :param afterwards: callback to trigger after removing :type afterwards: callable or None
22.037094
25.788704
0.854525
if self.ro: raise DatabaseROError() self.writequeue.append(('setconfig', afterwards, 'query.' + alias, querystring))
def save_named_query(self, alias, querystring, afterwards=None)
add an alias for a query string. These are stored in the notmuch database and can be used as part of more complex queries using the syntax "query:alias". See :manpage:`notmuch-search-terms(7)` for more info. :param alias: name of shortcut :type alias: str :param queryst...
28.314201
34.276421
0.826055
if self.ro: raise DatabaseROError() self.writequeue.append(('setconfig', afterwards, 'query.' + alias, ''))
def remove_named_query(self, alias, afterwards=None)
remove a named query from the notmuch database. :param alias: name of shortcut :type alias: str :param afterwards: callback to trigger after adding the alias :type afterwards: callable or None
33.518967
33.869354
0.989655
# hash_algo will be something like SHA256, but we need pgp-sha256. algo = gpg.core.hash_algo_name(hash_algo) if algo is None: raise GPGProblem('Unknown hash algorithm {}'.format(algo), code=GPGCode.INVALID_HASH_ALGORITHM) return 'pgp-' + algo.lower()
def RFC3156_micalg_from_algo(hash_algo)
Converts a GPGME hash algorithm name to one conforming to RFC3156. GPGME returns hash algorithm names such as "SHA256", but RFC3156 says that programs need to use names such as "pgp-sha256" instead. :param str hash_algo: GPGME hash_algo :returns: the lowercase name of of the algorithm with "pgp-" prep...
6.095676
5.71057
1.067437
ctx = gpg.core.Context() try: key = ctx.get_key(keyid) if validate: validate_key(key, encrypt=encrypt, sign=sign) except gpg.errors.KeyNotFound: raise GPGProblem('Cannot find key for "{}".'.format(keyid), code=GPGCode.NOT_FOUND) except gp...
def get_key(keyid, validate=False, encrypt=False, sign=False, signed_only=False)
Gets a key from the keyring by filtering for the specified keyid, but only if the given keyid is specific enough (if it matches multiple keys, an exception will be thrown). If validate is True also make sure that returned key is not invalid, revoked or expired. In addition if encrypt or sign is True al...
4.189654
3.841222
1.090709
ctx = gpg.core.Context() return ctx.keylist(hint, private)
def list_keys(hint=None, private=False)
Returns a generator of all keys containing the fingerprint, or all keys if hint is None. The generator may raise exceptions of :class:gpg.errors.GPGMEError, and it is the caller's responsibility to handle them. :param hint: Part of a fingerprint to usee to search :type hint: str or None :param...
15.027194
15.319258
0.980935
ctx = gpg.core.Context(armor=True) ctx.signers = keys (sigblob, sign_result) = ctx.sign(plaintext_str, mode=gpg.constants.SIG_MODE_DETACH) return sign_result.signatures, sigblob
def detached_signature_for(plaintext_str, keys)
Signs the given plaintext string and returns the detached signature. A detached signature in GPG speak is a separate blob of data containing a signature for the specified plaintext. :param bytes plaintext_str: bytestring to sign :param keys: list of one or more key to sign with. :type keys: list[g...
8.010996
7.520598
1.065207
assert keys, 'Must provide at least one key to encrypt with' ctx = gpg.core.Context(armor=True) out = ctx.encrypt(plaintext_str, recipients=keys, sign=False, always_trust=True)[0] return out
def encrypt(plaintext_str, keys)
Encrypt data and return the encrypted form. :param bytes plaintext_str: the mail to encrypt :param key: optionally, a list of keys to encrypt with :type key: list[gpg.gpgme.gpgme_key_t] or None :returns: encrypted mail :rtype: str
6.125678
6.257675
0.978906
return ", ".join("{}: {}".format(s.fpr, "Bad signature for key(s)") for s in error.result.signatures if s.status != NO_ERROR)
def bad_signatures_to_str(error)
Convert a bad signature exception to a text message. This is a workaround for gpg not handling non-ascii data correctly. :param BadSignatures error: BadSignatures exception
14.534396
18.359579
0.791652
ctx = gpg.core.Context() try: verify_results = ctx.verify(message, signature)[1] return verify_results.signatures except gpg.errors.BadSignatures as e: raise GPGProblem(bad_signatures_to_str(e), code=GPGCode.BAD_SIGNATURE) except gpg.errors.GPGMEError as e: raise GPG...
def verify_detached(message, signature)
Verifies whether the message is authentic by checking the signature. :param bytes message: The message to be verified, in canonical form. :param bytes signature: the OpenPGP signature to verify :returns: a list of signatures :rtype: list[gpg.results.Signature] :raises alot.errors.GPGProblem: if the...
5.113465
4.217702
1.212382
if session_keys is not None: try: return _decrypt_verify_session_keys(encrypted, session_keys) except GPGProblem: pass ctx = gpg.core.Context() return _decrypt_verify_with_context(ctx, encrypted)
def decrypt_verify(encrypted, session_keys=None)
Decrypts the given ciphertext string and returns both the signatures (if any) and the plaintext. :param bytes encrypted: the mail to decrypt :param list[str] session_keys: a list OpenPGP session keys :returns: the signatures and decrypted plaintext data :rtype: tuple[list[gpg.resuit.Signature], str...
4.268324
3.94799
1.081138
for key in session_keys: ctx = gpg.core.Context() ctx.set_ctx_flag("override-session-key", key) try: return _decrypt_verify_with_context(ctx, encrypted) except GPGProblem: continue raise GPGProblem("No valid session key", code=GPGCode.NOT_FOUND)
def _decrypt_verify_session_keys(encrypted, session_keys)
Decrypts the given ciphertext string using the session_keys and returns both the signatures (if any) and the plaintext. :param bytes encrypted: the mail to decrypt :param list[str] session_keys: a list OpenPGP session keys :returns: the signatures and decrypted plaintext data :rtype: tuple[list[gpg...
6.917803
6.283036
1.101029
try: (plaintext, _, verify_result) = ctx.decrypt( encrypted, verify=True) sigs = verify_result.signatures except gpg.errors.GPGMEError as e: raise GPGProblem(str(e), code=e.getcode()) except gpg.errors.BadSignatures as e: (plaintext, _, _) = ctx.decrypt(e...
def _decrypt_verify_with_context(ctx, encrypted)
Decrypts the given ciphertext string using the gpg context and returns both the signatures (if any) and the plaintext. :param gpg.Context ctx: the gpg context :param bytes encrypted: the mail to decrypt :returns: the signatures and decrypted plaintext data :rtype: tuple[list[gpg.resuit.Signature], ...
4.910778
4.149518
1.183457
if key.revoked: raise GPGProblem('The key "{}" is revoked.'.format(key.uids[0].uid), code=GPGCode.KEY_REVOKED) elif key.expired: raise GPGProblem('The key "{}" is expired.'.format(key.uids[0].uid), code=GPGCode.KEY_EXPIRED) elif key.inva...
def validate_key(key, sign=False, encrypt=False)
Assert that a key is valide and optionally that it can be used for signing or encrypting. Raise GPGProblem otherwise. :param key: the GPG key to check :type key: gpg.gpgme._gpgme_key :param sign: whether the key should be able to sign :type sign: bool :param encrypt: whether the key should be ...
1.715753
1.518355
1.130008
def check(key_uid): return (email == key_uid.email and not key_uid.revoked and not key_uid.invalid and key_uid.validity >= gpg.constants.validity.FULL) return any(check(u) for u in key.uids)
def check_uid_validity(key, email)
Check that a the email belongs to the given key. Also check the trust level of this connection. Only if the trust level is high enough (>=4) the email is assumed to belong to the key. :param key: the GPG key to which the email should belong :type key: gpg.gpgme._gpgme_key :param email: the email ...
6.528046
7.017139
0.9303
if self.proc: if self.proc.is_alive(): self.proc.terminate()
def kill_filler_process(self)
terminates the process that fills this buffers :class:`~alot.walker.PipeWalker`.
4.119905
4.680089
0.880305
threadlinewidget = self.get_selected_threadline() thread = None if threadlinewidget: thread = threadlinewidget.get_thread() return thread
def get_selected_thread(self)
returns currently selected :class:`~alot.db.Thread`
4.064562
3.916286
1.037861
keys = ['dfg', 'dbg', '1fg', '1bg', '16fg', '16bg', '256fg', '256bg'] acc = {} if not isinstance(value, (list, tuple)): value = value, if len(value) > 6: raise VdtValueTooLongError(value) # ensure we have exactly 6 attribute strings attrstrings = (value + (6 - len(value)) * ...
def attr_triple(value)
Check that interprets the value as `urwid.AttrSpec` triple for the colour modes 1,16 and 256. It assumes a <6 tuple of attribute strings for mono foreground, mono background, 16c fg, 16c bg, 256 fg and 256 bg respectively. If any of these are missing, we downgrade to the next lower available pair, defa...
3.899262
3.07546
1.267863
if value is None: res = 'fit', 0, 0 elif not isinstance(value, (list, tuple)): raise VdtTypeError(value) elif value[0] not in ['fit', 'weight']: raise VdtTypeError(value) if value[0] == 'fit': if not isinstance(value[1], int) or not isinstance(value[2], int): ...
def width_tuple(value)
test if value is a valid width indicator (for a sub-widget in a column). This can either be ('fit', min, max): use the length actually needed for the content, padded to use at least width min, and cut of at width max. Here, min and max are positive integers or 0 to ...
2.476702
2.318466
1.068251
if not re.match(r'.*://.*', value): raise VdtTypeError(value) mburl = urlparse(value) uri_scheme_to_mbclass = { 'mbox': mailbox.mbox, 'maildir': mailbox.Maildir, 'mh': mailbox.MH, 'babyl': mailbox.Babyl, 'mmdf': mailbox.MMDF, }...
def mail_container(value)
Check that the value points to a valid mail container, in URI-style, e.g.: `mbox:///home/username/mail/mail.box`. `~`-expansion will work, e.g.: `mbox://~/mail/mail.box`. The value is cast to a :class:`mailbox.Mailbox` object.
3.775645
3.212096
1.175446
try: return crypto.get_key(value) except GPGProblem as e: raise ValidateError(str(e))
def gpg_key(value)
test if value points to a known gpg key and return that key as a gpg key object.
6.905661
7.318663
0.943569
checks = checks or {} try: config = ConfigObj(infile=configpath, configspec=specpath, file_error=True, encoding='UTF8') except ConfigObjError as e: msg = 'Error when parsing `%s`:\n%s' % (configpath, e) logging.error(msg) raise ConfigError(msg...
def read_config(configpath=None, specpath=None, checks=None, report_extra=False)
get a (validated) config object for given config file path. :param configpath: path to config-file or a list of lines as its content :type configpath: str or list(str) :param specpath: path to spec-file :type specpath: str :param checks: custom checks to use for validator. see `validate doc...
2.975133
3.051962
0.974826
if a is None: return fallback if a.background in ['default', '']: bg = fallback.background else: bg = a.background if a.foreground in ['default', '']: fg = fallback.foreground else: fg = a.foreground return AttrSpec(fg, bg)
def resolve_att(a, fallback)
replace '' and 'default' by fallback values
2.927616
2.67873
1.092912
start = original.rfind(sep, 0, pos) + 1 end = original.find(sep, pos - 1) if end == -1: end = len(original) return original[start:end], start, end, pos - start
def relevant_part(self, original, pos, sep=' ')
calculates the subword in a `sep`-splitted list of substrings of `original` that `pos` is ia.n
2.48303
2.481885
1.000461
start = original.rfind(self._separator, 0, pos) if start == -1: start = 0 else: start = start + len(self._separator) end = original.find(self._separator, pos - 1) if end == -1: end = len(original) return original[start:end], st...
def relevant_part(self, original, pos)
calculates the subword of `original` that `pos` is in
2.17886
2.118887
1.028304
commands = split_commandline(line) + [''] i = 0 start = 0 end = len(commands[i]) while pos > end: i += 1 start = end + 1 end += 1 + len(commands[i]) return start, end
def get_context(line, pos)
computes start and end position of substring of line that is the command string under given position
4.08707
3.410265
1.198461
@functools.wraps(check) def validator(paths): if isinstance(paths, str): check(paths) elif isinstance(paths, collections.Sequence): for path in paths: check(path) else: raise Exception('expected either basestr or sequenc of basstr...
def _path_factory(check)
Create a function that checks paths.
4.308422
4.150639
1.038014
if (os.path.exists(path) and not (os.path.isfile(path) or stat.S_ISFIFO(os.stat(path).st_mode) or stat.S_ISCHR(os.stat(path).st_mode))): raise ValidationFailed( '{} is not a valid file, character device, or fifo.'.f...
def optional_file_like(path)
Validator that ensures that if a file exists it regular, a fifo, or a character device. The file is not required to exist. This includes character special devices like /dev/null.
3.13504
2.394823
1.30909
fname = self.part.get_filename() if fname: extracted_name = decode_header(fname) if extracted_name: return os.path.basename(extracted_name) return None
def get_filename(self)
return name of attached file. If the content-disposition header contains no file name, this returns `None`
4.881993
3.894724
1.253489
ctype = self.part.get_content_type() # replace underspecified mime description by a better guess if ctype in ['octet/stream', 'application/octet-stream', 'application/octetstream']: ctype = guess_mimetype(self.get_data()) return ctype
def get_content_type(self)
mime type of the attachment part
6.587218
6.082038
1.083061
filename = self.get_filename() path = os.path.expanduser(path) if os.path.isdir(path): if filename: basename = os.path.basename(filename) file_ = open(os.path.join(path, basename), "wb") else: file_ = tempfile.Named...
def save(self, path)
save the attachment to disk. Uses :meth:`~get_filename` in case path is a directory
2.844077
2.577393
1.10347
part = deepcopy(self.part) part.set_param('maxlinelen', '78', header='Content-Disposition') return part
def get_mime_representation(self)
returns mime part that constitutes this attachment
15.263766
10.735332
1.421825
thmble = self._config[mode][name] if part is not None: thmble = thmble[part] thmble = thmble or DUMMYDEFAULT return thmble[self._colours.index(colourmode)]
def get_attribute(self, colourmode, mode, name, part=None)
returns requested attribute :param mode: ui-mode (e.g. `search`,`thread`...) :type mode: str :param name: of the atttribute :type name: str :param colourmode: colour mode; in [1, 16, 256] :type colourmode: int :rtype: urwid.AttrSpec
6.338542
6.718626
0.943428
def pickcolour(triple): return triple[self._colours.index(colourmode)] def matches(sec, thread): if sec.get('tagged_with') is not None: if not set(sec['tagged_with']).issubset(thread.get_tags()): return False if sec.get('q...
def get_threadline_theming(self, thread, colourmode)
look up how to display a Threadline wiidget in search mode for a given thread. :param thread: Thread to theme Threadline for :type thread: alot.db.thread.Thread :param colourmode: colourmode to use, one of 1,16,256. :type colourmode: int This will return a dict mapping ...
3.416273
2.885528
1.183933
logging.debug("Got key (%s, %s)", keys, raw) # work around: escape triggers this twice, with keys = raw = [] # the first time.. if not keys: return # let widgets handle input if key is virtual window resize keypress # or we are in "passall" mode ...
def _input_filter(self, keys, raw)
handles keypresses. This function gets triggered directly by class:`urwid.MainLoop` upon user input and is supposed to pass on its `keys` parameter to let the root widget handle keys. We intercept the input here to trigger custom commands as defined in our keybindings.
4.973988
4.694045
1.059638
# remove initial spaces cmdline = cmdline.lstrip() # we pass Commands one by one to `self.apply_command`. # To properly call them in sequence, even if they trigger asyncronous # code (return Deferreds), these applications happen in individual # callback function...
async def apply_commandline(self, cmdline)
interprets a command line string i.e., splits it into separate command strings, instanciates :class:`Commands <alot.commands.Command>` accordingly and applies then in sequence. :param cmdline: command line to interpret :type cmdline: str
9.557766
9.401036
1.016672
self.mainloop.widget = w self._unlock_key = key self._unlock_callback = afterwards self._locked = True
def show_as_root_until_keypress(self, w, key, afterwards=None)
Replaces root widget by given :class:`urwid.Widget` and makes the UI ignore all further commands apart from cursor movement. If later on `key` is pressed, the old root widget is reset, callable `afterwards` is called and normal behaviour is resumed.
7.942673
8.421474
0.943145
history = history or [] fut = asyncio.get_event_loop().create_future() oldroot = self.mainloop.widget def select_or_cancel(text): self.mainloop.widget = oldroot self._passall = False fut.set_result(text) def cerror(e): ...
def prompt(self, prefix, text=u'', completer=None, tab=0, history=None)
prompt for text input. This returns a :class:`asyncio.Future`, which will have a string value :param prefix: text to print before the input field :type prefix: str :param text: initial content of the input field :type text: str :param completer: completion object to use ...
5.009398
5.182745
0.966553
exit_msg = None try: loop = asyncio.get_event_loop() loop.stop() except Exception as e: logging.error('Could not stop loop: %s\nShutting down anyway..', str(e))
def exit()
shuts down user interface without cleaning up. Use a :class:`alot.commands.globals.ExitCommand` for a clean shutdown.
4.731138
4.852278
0.975034
self.mainloop.stop() try: yield finally: self.mainloop.start() # make sure urwid renders its canvas at the correct size self.mainloop.screen_size = None self.mainloop.draw_screen()
def paused(self)
context manager that pauses the UI to allow running external commands. If an exception occurs, the UI will be started before the exception is re-raised.
7.5495
6.624144
1.139694
# call pre_buffer_open hook prehook = settings.get_hook('pre_buffer_open') if prehook is not None: prehook(ui=self, dbm=self.dbman, buf=buf) if self.current_buffer is not None: offset = settings.get('bufferclose_focus_offset') * -1 currentin...
def buffer_open(self, buf)
register and focus new :class:`~alot.buffers.Buffer`.
3.00503
2.760538
1.088567
# call pre_buffer_close hook prehook = settings.get_hook('pre_buffer_close') if prehook is not None: prehook(ui=self, dbm=self.dbman, buf=buf) buffers = self.buffers success = False if buf not in buffers: logging.error('tried to close un...
def buffer_close(self, buf, redraw=True)
closes given :class:`~alot.buffers.Buffer`. This it removes it from the bufferlist and calls its cleanup() method.
3.277684
3.152257
1.039789
# call pre_buffer_focus hook prehook = settings.get_hook('pre_buffer_focus') if prehook is not None: prehook(ui=self, dbm=self.dbman, buf=buf) success = False if buf not in self.buffers: logging.error('tried to focus unknown buffer') els...
def buffer_focus(self, buf, redraw=True)
focus given :class:`~alot.buffers.Buffer`.
3.26822
3.103633
1.05303
if not startfrom: startfrom = self.current_buffer if 'get_focus' in dir(startfrom): focus = startfrom.get_focus() if isinstance(focus, tuple): focus = focus[0] if isinstance(focus, urwid.Widget): return self.get_dee...
def get_deep_focus(self, startfrom=None)
return the bottom most focussed widget of the widget tree
2.834379
2.654734
1.06767
return [x for x in self.buffers if isinstance(x, t)]
def get_buffers_of_type(self, t)
returns currently open buffers for a given subclass of :class:`~alot.buffers.Buffer`. :param t: Buffer class :type t: alot.buffers.Buffer :rtype: list
3.782524
6.487998
0.583003
newpile = self._notificationbar.widget_list for l in messages: if l in newpile: newpile.remove(l) if newpile: self._notificationbar = urwid.Pile(newpile) else: self._notificationbar = None self.update()
def clear_notify(self, messages)
Clears notification popups. Call this to ged rid of messages that don't time out. :param messages: The popups to remove. This should be exactly what :meth:`notify` returned when creating the popup
4.372223
5.047545
0.866208
choices = choices or {'y': 'yes', 'n': 'no'} assert select is None or select in choices.values() assert cancel is None or cancel in choices.values() assert msg_position in ['left', 'above'] fut = asyncio.get_event_loop().create_future() # Create a returned future ...
def choice(self, message, choices=None, select=None, cancel=None, msg_position='above', choices_to_return=None)
prompt user to make a choice. :param message: string to display before list of choices :type message: unicode :param choices: dict of possible choices :type choices: dict: keymap->choice (both str) :param choices_to_return: dict of possible choices to return for the ...
3.835784
3.92585
0.977058
def build_line(msg, prio): cols = urwid.Columns([urwid.Text(msg)]) att = settings.get_theming_attribute('global', 'notify_' + prio) return urwid.AttrMap(cols, att) msgs = [build_line(message, priority)] if not self._notificationbar: self....
def notify(self, message, priority='normal', timeout=0, block=False)
opens notification popup. :param message: message to print :type message: str :param priority: priority string, used to format the popup: currently, 'normal' and 'error' are defined. If you use 'X' here, the attribute 'global_notify_X' is used t...
5.344664
4.908041
1.088961
# get the main urwid.Frame widget mainframe = self.root_widget.original_widget # body if self.current_buffer: mainframe.set_body(self.current_buffer) # footer lines = [] if self._notificationbar: # .get_text()[0] != ' ': lines.a...
def update(self, redraw=True)
redraw interface
4.242778
4.153759
1.021431
info = {} cb = self.current_buffer btype = None if cb is not None: info = cb.get_info() btype = cb.modename info['buffer_no'] = self.buffers.index(cb) info['buffer_type'] = btype info['total_messages'] = self.dbman.count_m...
def build_statusbar(self)
construct and return statusbar widget
3.865729
3.826734
1.01019