summaryrefslogtreecommitdiff
path: root/alot/helper.py
Commit message (Collapse)AuthorAge
* db/utils: move formataddr to helperAnton Khirnov2020-03-05
| | | | | | | It has no relation to database, so helper seems like a better place for it. As there is nothing left in db/utils, it is removed.
* Remove unicode escape codesLucas Hoffmann2019-11-06
|
* Remove unicode literals syntax from python2Lucas Hoffmann2019-11-06
|
* Fix UnboundLocalErrorLucas Hoffmann2019-08-16
| | | | The local variable proc was not defined in these branches.
* remove unused importsPatrick Totzke2019-08-11
|
* adjust to variable python-magic APIMichael J Gruber2019-06-02
| | | | | | | | Depending on the libmagic/ctypes version, magic_version is a function or a constant. So far, the code expected a constant and fails on the function variant with a TypeError. Test with callable() und use the magic_version attribute accordingly.
* addressbook: add logging statementsMatthieu Coudron2019-02-06
| | | | to help troubleshoot problems
* helper: remove unused GeneratorDylan Baker2018-08-06
|
* helper: replace email_as_* with email builtinsDylan Baker2018-08-02
| | | | | | | | | | | | | | Python 3.3 added a new feature to the email module, policies (https://docs.python.org/3.5/library/email.policy.html). Policy objects allow precise control over how numerous features work when converting to and from str or bytes. With the `email.policy.SMTP` the behavior of email_as_bytes and email_as_string can be achieved using the builtin `.as_string()` and `.as_bytes()` methods, without custom code or the need to test it. Additionally these methods handle corner cases that we don't currently handle, such as multi-part messages with different encodings. Fixes #1257
* remove workaround for python issuePatrick Totzke2018-08-02
| | | | that was solved upstream: https://bugs.python.org/issue14983
* helper: use asyncio.subprocess instead of twistedDylan Baker2018-07-26
|
* Merge pull request #1266 from mjg/message-from-bytesDylan Baker2018-07-17
|\ | | | | Message from bytes
| * Revert "require chardet"Michael J Gruber2018-07-11
| | | | | | | | | | | | | | | | This reverts commit 0b5f8bf143e76be7ac989e8c8ec6e4a7dc08a78a. Chardet takes prohibitively long on large blobs (such as attachments). It will be replaced by functions from the email module in subsequent commits.
* | alot/helper: parse_mailto: unquote is in urllib.parse in Python 3Johannes Löthberg2018-07-16
|/ | | | Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
* Remove old __future__ importsLucas Hoffmann2018-06-19
| | | | They are not needed for python >= 3.0.
* alot/helper: allow call_cmd to take bytes or strings as stdinDylan Baker2018-05-15
| | | | | This might be a little sloppy, but there are legitimate cases where stdin is bytes, and cases where it is a string.
* Raise an exception with a meaningful message.Ben Finney2018-04-23
| | | | | | The `assert` statement is not always executed (it can be optimised away) so is not a suitable run-time check. Also, an exception allows for a better error message.
* helper: add debug for what encoding was guessed.Dylan Baker2018-04-06
|
* require chardetDylan Baker2018-03-06
| | | | | | | magic struggles to decode a number of encodings, particularly it struggles with windows-1252, which Exchange *loves* to silently re-encode mail in, without updated the charset of the payload. Chardet successfully guesses these oddball encodings much more often.
* fix sending encrypted messages in py3kDylan Baker2018-03-01
|
* fix a bunch of utils tests for py3kDylan Baker2018-03-01
| | | | | There are a few that are still broken because of bytes to unicode conversion, and this may not all be correct, but most of the tests pass
* helper: py3k fixesDylan Baker2018-03-01
|
* helper: add a helper to guess the encoding a of a blob and decode itDylan Baker2018-03-01
|
* py3k: only pass str instances to shlexDylan Baker2018-03-01
|
* py3k: don't covert to bytes for shlexDylan Baker2018-03-01
| | | | shlex expectes unicode in python3
* py3k: remove basestring and unicode.Dylan Baker2018-03-01
| | | | This probably isn't completely right, but it's a start.
* py3k: use StringIO from io module instead of cStringIODylan Baker2018-03-01
| | | | | cStringIO doesn't exist in python 3.x, instead one simply uses io.StringIO and python provided a C accelerated version if possible.
* Rename get_env to get_xdg_env and clarify docstring.Julian Mehne2018-01-23
|
* Fix empty XDG_* environment variables.Julian Mehne2018-01-21
| | | | | | | | | | | | Use fallback, if an enviroment variable is unset *or* empty. Bug: - XDG_CONFIG_HOME='' alot Problem: Does not find the configuration file (among others), because os.environ.get('XDG_CONFIG_HOME', '~/.config') returns '', instead of '~/.config'.
* Fix some spelling mistakesLucas Hoffmann2017-09-02
|
* alot/helper: Fix call_cmd_async polluting global environmentDylan Baker2017-08-22
| | | | | | | | | | An assignment `e = os.environ` creates a reference not a copy, which means that modifying one necessarily modifies the other. Using `dict.copy` creates a shallow copy (the keys and values are references, but the dicts are different objects), which means only modifications to mutable objects are shared. In the case of os.environ which only contains immutable objects like strings, bools, and numbers this isn't an issue.
* alot/helper: print ellipsis in codeDylan Baker2017-08-22
| | | | | Since the file is encoded in utf-8 we can actually print the ellipsis. Most people can more readily read that than the raw utf-8 escape.
* Use cStringIO.StringIO to fix #1132Lucas Hoffmann2017-08-21
| | | | | | | | | This undoes a small subset of the changes from fa3dd1b04567c4ea03fa658c3838b569531c79f5 and thus fixes #1132. The io.BytesIO object was not able to handle the unicode header names that where returned by envelope.construct_mail, which in turn did just copy them from the envelope header.
* Use io.BytesIO and io.StringIODylan Baker2017-08-19
| | | | | | | | In python3 StringIO and cStringIO are gone. In their place are io.BytesIO and io.StringIO. They are somewhat different in that they are not separated on implementation, but on the type they emulated. BytesIO works like the bytes class (str in python 2), while StringIO works like the str class (unicode in python2).
* helper: Do not add a newline to the end of a signed sectionDylan Baker2017-07-17
| | | | | | | | | | | | | | | | The spec is very clear here: (2) An appropriate Content-Transfer-Encoding is then applied; see section 3. In particular, line endings in the encoded data MUST use the canonical <CR><LF> sequence where appropriate (note that the canonical line ending may or may not be present on the last line of encoded data and MUST NOT be included in the signature if absent). That very last MUST NOT is what's important here, we shouldn't be adding newlines if they weren't there to begin with. Because we do it causes signed blobs that have newlines to be invalid since we've changed the substance of the signed code.
* Extend docstringLucas Hoffmann2017-06-21
|
* Move Popen.communicate call out of try-except blockLucas Hoffmann2017-02-19
| | | | | The OSError that is being caught should only be raised by the Popen constructor: https://docs.python.org/3/library/subprocess.html#exceptions
* alot/helper: simplify call_cmd and fix testDylan Baker2017-02-07
| | | | | This both fixes a test that failed (since stderr wasn't being set) and simplifies the function to only have one path that uses a ternary.
* Merge pull request #1009 from dcbaker/pr/remove_cmpPatrick Totzke2017-01-30
|\ | | | | Remove remaining uses of cmp
| * Replace cmp with rich comparisonsDylan Baker2017-01-27
| | | | | | | | | | | | This is both a performance issue (since cmp is slower than rich comparisons), and a python3 issue since cmp (and __cmp__) are gone in python 3.
* | Merge pull request #1012 from dcbaker/pr/future_divisionPatrick Totzke2017-01-28
|\ \ | | | | | | Use __future__.division
| * | helper: Use __future__ divisionDylan Baker2017-01-27
| |/
* / helper: Use kibi and mibibytes instead of kilo and megabytesDylan Baker2017-01-27
|/ | | | | | | | | | | | Technically a kilobyte (and it's derivatives like megabytes and gigabytes) are defined as powers of 1000, while a kibibyte (and it's derivatives like mibibytes and gibibytes) are defined as powers of 1024. This patch fixes incorrect language and formatting in the humanize_size function which defined a kilobyte as 1024. See this wikipedia article for more information: https://en.wikipedia.org/wiki/Kibibyte
* Merge pull request #984 from lucc/future/absolute-importsLucas Hoffmann2017-01-21
|\ | | | | Use absolute_imports from __future__
| * Use absolute_imports from __future__Lucas Hoffmann2017-01-18
| |
* | Add docstrings to some methods and functions.Lucas Hoffmann2017-01-20
|/
* Merge pull request #975 from lucc/tests/doctestsPatrick Totzke2017-01-18
|\ | | | | Porting old doctests to unittest
| * Port old doctests to unittest: alot.helper.shorten_author_string()Lucas Hoffmann2017-01-18
| |
* | helper: Don't rely on GNU extensions for strftimeDylan Baker2017-01-17
|/ | | | | | | | While the reality is that most alot users probably have glibc as their C library and can therefore rely on %P, it is possible that there are users or potential users who run a *BSD or other unix-like OS. This leaves only non-GNU extensions, though some of the extensions are specified in later POSIX, unix or C specifications.
* Replace unused arguments with _Dylan Baker2016-12-21
| | | | | | | | | | This patch replaces a large number (but not all) unused arguments with the standard ``_`` placeholder. This has the advantage of signaling that these values are unused. There are a number of places that I've chosen not to apply this, largely in methods that have publicly define signatures that they inherit (usually from urwid).