summaryrefslogtreecommitdiff
path: root/alot/helper.py
Commit message (Collapse)AuthorAge
* 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).
* Fix "superflous paren" warnings from pylintDylan Baker2016-12-21
| | | | | | | | | In alot/helper.py this is a fairly obvious change. In alot/buffers.py I've taken the liberty of replacing a somewhat odd use of multiplication that relies on the bool class (True and False) implementing an __int__ method. These are used to add the 's' to the end of 'message' if there are more than one message (thus messages), this is much clearer (and more correct) when implemented as a ternary instead.
* Use raw strings with backslashesDylan Baker2016-12-21
| | | | This just adds the `r` prefix to a few strings.
* Drop little used helperDylan Baker2016-12-19
| | | | | | | | The safely_get helper is just a wrapper around try/except, and is used twice in the whole code base, in the same function. It really doesn't even end up saving code because to get around line wrapping a lambda is assigned (which is not the greatest style wise), it ends up saving one line of code when it's called, and the function itself is 16 lines long.
* Simplify arithmetic comparisonLucas Hoffmann2016-12-17
|
* use open as a context manager instead of oneline open().read()Dylan Baker2016-12-14
| | | | | | | | While open().read() is nice for its terseness it has the problem that it causes an fd to leak until the gc collects it. For short lived scripts this isn't a big deal, but for a program like alot that run for long periods of time it's better to be correct and ensure that the fd is closed.
* Clean up importsLucas Hoffmann2016-12-09
| | | | | | - use relative imports if possible - group imports into standard library, third party, and alot modules - sort imports alphabetically
* Use logging's native string interpolationLucas Hoffmann2016-12-09
|
* Add and update several docstrings.Lucas Hoffmann2016-03-11
|
* fix #841Patrick Totzke2016-02-21
|
* Fix parsing of mailto addressesjosch2014-10-02
| | | | | - the key has been capitalized so compare with "Body" and not "body" - comparison between strings is better done with == than with "is"
* fix small stuff in the docsPatrick Totzke2014-08-02
|
* Move email_as_string function from crypto to helper moduleYann Rouillard2014-08-02
| | | | | | | | | The email_as_string function, and the related RFC3156_canonicalize function, are now used by the ForwardCommand and are not specific anymore to the crypto routine. So we move them to the global helper module. fix an import removal mistake while moving email_as_string function: StringIO was not only used by email_as_string
* always return new Envelope in helper.mailto_to_envelopePatrick Totzke2014-03-21
|
* add mailto helpersPatrick Totzke2014-03-21
| | | | | | parse_mailto parses mailto strings into headers,body and mailto_to_envelope constructs an alot.db.envelope.Envelope for a give mailto string
* add mailto-helperPatrick Totzke2013-12-01
|
* helper: do not strip in string_sanitizeSiim Põder2013-08-07
| | | | | | | | | Stripping the string causes leading whitespace on the first line of a message to be removed leading to weird indentation in thread view for some html messages. string_sanitize is also used for mail header parsing but I would not expect them to contain undesired whitespace too often either.
* add a generic function to test libmagic versionYann Rouillard2013-07-18
|
* add a rough check on the libmagic library version for the libmagic bug ↵Yann Rouillard2013-07-18
| | | | workaround
* workaround a libmagic mimetype detection bug for office documentsYann Rouillard2013-07-18
|
* pep8&pyflakes fixesPatrick Totzke2013-07-07
| | | | mostly automatically fixed
* fix: call_cmd properly read return value from...Patrick Totzke2013-07-07
| | | | subprocess.CalledProcessError
* properly read stderr in call_command helperPatrick Totzke2013-07-07
|
* fix command line escaping for arguments containing spacesYann Rouillard2013-07-03
|
* fix typoPatrick Totzke2013-05-12
|
* Fix guess_encoding()Hamish Downer2013-04-24
| | | | | | | | Turns out commit 7a9da3b0f obliterated a difference that mattered - the different argument to magic.open() in guess_mimetype() and guess_encoding() This commit reinstates that difference, and has a correct use of the pip python-magic library to get the encoding.
* Add inline comments around magic API hackeryHamish Downer2013-04-04
|
* Support two different versions of magicHamish Downer2013-04-02
| | | | | | The API for magic has changed at some point. Debian and Ubuntu still have an old version, but only the new version can be installed via pip. This commit allows us to use either version.
* Reuse magic mime codeHamish Downer2013-04-02
| | | | | The same lines are in guess_encoding() and guess_mimetype() - so have guess_mimetype() call guess_encoding()
* escape double quotes as wellJohannes Kulick2013-02-19
|