Kevin McCarthy [Tue, 23 May 2017 22:53:30 +0000 (15:53 -0700)]
Fix memory leak when closing mailbox and using the sidebar.
The code updating the sidebar counts decremented the msgcount, but did
not set it back to the original value. Which means fastclose was not
freeing all the headers.
Update the sidebar only when something is deleted, since I don't
believe it's required otherwise and the code is a bit cleaner that
way.
Kevin McCarthy [Fri, 12 May 2017 16:15:00 +0000 (09:15 -0700)]
Turn IMAP_EXPUNGE_EXPECTED back off when syncing. (closes #3940).
imap_sync_mailbox() turned on IMAP_EXPUNGE_EXPECTED when issuing a
EXPUNGE command during a sync. However, it forgot to turn it back off.
That meant that an unexpected EXPUNGE that occurred during a
mx_check_mailbox -> imap_check_mailbox() -> imap_cmd_finish() call was
not setting
idata->check_status = IMAP_EXPUNGE_PENDING;
and so imap_check_mailbox() was not returning MUTT_REOPENED.
This meant that although the Context had been changed, the index did
not run update_index(), resulting in a possible segfault.
Thanks to Uroš Juvan for reporting the issue, and his invaluable
description of how to reproduce the problem.
Kevin McCarthy [Fri, 5 May 2017 20:55:31 +0000 (13:55 -0700)]
Don't modify LastFolder/CurrentFolder upon aborting a change folder operation.
Set LastFolder and CurrentFolder after mx_close_mailbox() has
successfully completed. Otherwise, if the close is aborted, they will
have incorrect values.
Kevin McCarthy [Fri, 5 May 2017 01:05:06 +0000 (18:05 -0700)]
Fix sidebar count updates when closing mailbox. (closes #3938)
The context unread and flagged counts were being updated too early in
mx_close_mailbox(). Cancelling at any of the following prompts would
leave them in an incorrect state. Additionally, $move could increase
the delete count (for flagged messages), and $delete, if answered no,
could turn off message deletion.
Move all the sidebar buffy stat updating to the bottom of the
function, after all the prompts and processing.
Kevin McCarthy [Sun, 30 Apr 2017 21:24:37 +0000 (14:24 -0700)]
Fix unused function warnings when sidebar is disabled. (closes #3936)
parse_path_list/unlist are currently only used by the
un/sidebar_whitelist commands. Add an ifdef around them to stop an
unused function warning. Add a comment too, so it's clear why they
are ifdef'ed.
Kevin McCarthy [Fri, 28 Apr 2017 04:22:08 +0000 (21:22 -0700)]
Fix km_error_key() infinite loop and unget buffer pollution.
'bind pager \Ch help' produces an infinite loop when an unbound key is
pressed in the pager. The reason is because km_error_key() tries to
verify that the key sequence is really bound to the OP_HELP operation.
It does this by using km_expand_key(), tokenize_unget_string() on the
resulting buffer, then checking if the next km_dokey() returns OP_HELP.
The problem is that km_expand_key() does not always produce a string
that is properly reparsed by tokenize_unget_string(). Control-h
sequences are expanded to ^H. tokenize_unget_string() recognizes this
as two characters '^' and 'H'. km_error_key() checks the OP returned,
which is OP_PAGER_TOP for the '^'. This is not OP_HELP, so it prints
a generic error and returns. This leaves the 'H' in the input buffer!
Since 'H' (by default) is unbound in the pager, it retriggers
km_error_key(), resulting in an infinite loop.
The same issues can occur without control sequences:
bind generic ? noop
bind generic dq help
In the index, hitting an unbound key will end up leaving 'q' in the unget
buffer, because 'd' is bound in the index menu and will be read by km_dokey().
A simple approach to fix this would be to just use the same code as in
mutt_make_help(), which has no double-check. This would be no worse
than the help menu, but can generate an inaccurate error message (e.g
if '?' were bound to noop)
This patch instead uses OP_END_COND as a barrier in the unget buffer.
It directly inserts the keys in the OP_HELP keymap, instead of using
km_expand_key() + tokenize_unget_string(). After calling km_dokey()
it flushes the unget buffer to the OP_END_COND barrier.
Thanks to Walter Alejandro Iglesias for reporting the bug.
Roger Cornelius [Wed, 26 Apr 2017 22:40:34 +0000 (15:40 -0700)]
Fix error message when opening a mailbox with no read permission. (closes #3934)
ctx->mx_ops ends up being NULL for both the case that ctx->magic is 0
and -1. This meant the mutt_perror() error message was never being
printed, because the check for ctx->mx_ops == NULL was taking place
first.
Move the "ctx->magic == -1" check first, so mutt will print out an
appropriate perror message in that case.
Kevin McCarthy [Tue, 18 Apr 2017 19:25:17 +0000 (12:25 -0700)]
Fix GPG_TTY to be added to envlist. (closes #3931)
Changeset 37209157e33c converted filters to use the envlist.
Unfortunately, I missed that pgp.c sets GPG_TTY when using the GnuPG
agent. Convert to add GPG_TTY to the envlist too.
Kevin McCarthy [Sat, 8 Apr 2017 21:18:26 +0000 (14:18 -0700)]
Silence imap progress messages for pipe-message. (see #3929)
_mutt_pipe_message() calls endwin(), and then calls pipe_msg(). If an
imap message body hasn't already been downloaded, this can end up
calling imap_fetch_message().
The progress messages in imap_fetch_message() were restoring curses,
just after extract_url was running. This was leading to a condition
where mutt curses didn't think the screen had changed after
extract_url exited.
There was already a check for isendwin() inside imap_fetch_message(),
but it wasn't wrapped around the progressbar creation/usage. Add a
check for those places too.
Kevin McCarthy [Sun, 26 Mar 2017 19:27:15 +0000 (12:27 -0700)]
Fix mutt_refresh() pausing during macro events.
Changeset a07e8215a0ef split input buffering into two pools.
Unfortunately, the mutt_refresh() was not changed to check the correct
buffer count, resulting in unnecessary refreshes during macros.
The SSL interactive certificate prompts set OPTIGNOREMACROEVENTS and
then put up a confirmation menu. Perhaps we've just been lucky, but
it seems we should refresh the screen in those cases if we're in the
middle of a macro. Add a check for this option in mutt_refresh() too.
Kevin McCarthy [Mon, 20 Mar 2017 17:16:03 +0000 (10:16 -0700)]
Fix setenv overwriting to not truncate the envlist. (see #3922)
The refactor in 2b9c40f13e13 exposed a bug I hadn't noticed. The
match loop performed a FREE() on the slot. Then, below, it was
checking if (*envp) to see whether it was overwriting or creating a
new slot. However, FREE() nulls out *envp. This would end up
truncating the envlist just after the set slot!
Move the free down, using a mutt_str_replace(), when overwriting the
slot.
Kevin McCarthy [Sun, 5 Mar 2017 23:24:45 +0000 (15:24 -0800)]
Increase ACCOUNT.pass field size. (closes #3921)
#3921 reported his password token used for Google XOAUTH2 is size 129.
The ACCOUNT structure currently uses a size 128 buffer. Who knew a
password field would ever be bigger than that?
Since the ACCOUNT structure has no allocation/dellocation routines,
the easiest fix is to increase the size. Bump the size up to 256.
Prevent null pointer exception for h->ai_canonname
The getaddrinfo call in line 54 sets &h to a struct addrinfo. If a
canonical name cannot be found for the node argument of getaddrinfo,
h->ai_canonname is set to NULL. In that case, the strchr call in line
58 can lead to segfault. This behavior was observed on a macos sierra
while the hostname was 192.168.1.3 (unfortunately this happens quite
often in macos).
The fix is simple, just check h->ai_canonname for the NULL value.
Kevin McCarthy [Sun, 12 Feb 2017 20:24:51 +0000 (12:24 -0800)]
Fix potential cert memory leak in check_certificate_by_digest().
Thanks to Matthias Andree's debugging, it appears the cert is not
freed when PEM_read_X509() encounters EOF. Change the return value
check to not overwrite cert. It is already updated via the second
parameter.
Matthias Andree [Sun, 12 Feb 2017 17:59:48 +0000 (09:59 -0800)]
Plug memory leak in weed-expired-certs code.
X509_STORE_add_cert() creates a copy of the certificate we're offering,
so we need to free our copy afterwards. This isn't documented, but from
observed behaviour in OpenSSL 1.0.2 and its master branch source code.
Change PEM_read_X509() call to reuse cert to avoid free/reallocation
overhead.
Kevin McCarthy [Sun, 12 Feb 2017 17:59:41 +0000 (09:59 -0800)]
Filter expired local certs for OpenSSL verification.
OpenSSL has trouble establishing the chain and verifying when
duplicate expired certs are loaded in from $certificate_file. A
warning about this is mentioned in
SSL_CTX_load_verify_locations(3SSL).
Filter out expired certs when loading verify certs. Note that the
full certicates file is still used for verification in
check_certificate_by_digest().
Kevin McCarthy [Fri, 10 Feb 2017 21:01:21 +0000 (13:01 -0800)]
Change "allow_dups" into a flag at hash creation.
Instead of having an "allow_dups" parameter for hash_insert(), add a
flag, MUTT_HASH_ALLOW_DUPS, to hash_create().
Currently ReverseAlias, subj_hash, and thread_hash allow duplicate
keys. Change those hashes to pass the flag at creation, and remove
the last parameter from all callers of hash_insert().
Kevin McCarthy [Sat, 4 Feb 2017 20:53:38 +0000 (12:53 -0800)]
Add LMDB backend support for header cache. (see #3691)
Based on the original from JP Mens:
https://gist.github.com/jpmens/15969d9d678a3d450e4e
The following performance patch was manually applied on top of the
original patch:
https://github.com/neomutt/neomutt/commit/7e5380cd4c40d119ff83b2cf5f51f2cdb8a95ab3
Kevin McCarthy [Tue, 31 Jan 2017 22:27:36 +0000 (14:27 -0800)]
Simplify mutt_label_complete().
It was derived from mutt_command_complete(), which had more complex
requirements. For labels, we just need to skip whitespace and
complete based on the passed in buffer.
Therefore, we don't need the pos parameter, or to work backwards from
the end of the buffer.
Kevin McCarthy [Tue, 31 Jan 2017 22:27:28 +0000 (14:27 -0800)]
Permit tab completion of pattern expressions with ~y (labels).
Thanks to David Champion for the original patch. This version is
slightly different, as I couldn't get the original patch working.
This version simply scans backward for the first ~, and if it is ~y,
invokes completion.
Kevin McCarthy [Sun, 29 Jan 2017 19:02:50 +0000 (11:02 -0800)]
Fix the x-label update code check location.
The x-label comparison was outside the "beginning of header" block.
This meant that it could theoretically match a continuation line.
Additionally, the continuation lines of x-labels would not be
stripped, because the comparison was after the ignore variable was
reset.
Move the comparison inside the block and before the ignore reset.
David Champion [Sun, 29 Jan 2017 02:47:57 +0000 (18:47 -0800)]
Adds label completion.
A global label hash is added, to which labels are added as they're parsed
from a mailbox file or edited manually by the user. Reference counts are
kept in the hash table so that unused labels are removed from available
completions. Completion is available in the label editor only, but it
may be feasible to add for search expressions if the preceding text ends
with '~y'.
David Champion [Tue, 24 Jan 2017 03:01:50 +0000 (19:01 -0800)]
Add subjectrx command to replace matching subjects with something else.
This lets you define regular expressions-replacement pairs for subject
display. When a Subject: matches the regular expression, the replacement
value will be displayed instead in the message index. Backreferences
are supported.
This is especially nice for simplifying subjects that are overly wordy,
such as mailing list posts (with [Listname] tags, etc), mail from
ticketing systems or bug trackers, etc. It lets you reduce clutter in
your mutt display without altering the messages themselves.
David Champion [Tue, 24 Jan 2017 03:01:36 +0000 (19:01 -0800)]
Abstract the SPAM_LIST as a generic REPLACE_LIST
REPLACE_LIST can be used more generally as a list of pattern
match-replace settings. SPAM_LIST was a special case of this, so
spam handling has been been changed to use REPLACE_LIST instead, and
SPAM_LIST was removed.
A generic function for performing a REPLACE_LIST replacement has
been added in mutt_apply_replace().
Commited by Kevin McCarthy with some buffer overflow fixes in
mutt_apply_replace().
Kevin McCarthy [Tue, 24 Jan 2017 02:46:16 +0000 (18:46 -0800)]
Improve Reply-to vs From comparison when replying. (closes #3909)
Prior to this patch, if the Reply-to mailbox matched the From mailbox,
mutt would always use the From address. This was probably done to
preserve the display name, as the Reply-to address is often missing one.
Unfortunately, there are circumstances where the Reply-to display-name
has significance, such as in ticket 3909.
Change mutt so that it only uses the From address if the Reply-To has
no display-name.
Kevin McCarthy [Wed, 18 Jan 2017 00:09:16 +0000 (16:09 -0800)]
Fix several alias hashtable issues.
Convert to use the strdup keys hash. Addresses can be converted back
and forth from intl to local forms. This frees and recreates a new
addr->mailbox string, resulting in the hash table key being a dangling
pointer.
Change alias hash table insert/remove to ensure the address is in intl
form. The alias menu (previously) converted address entries to local
form when performing a completion. Even with the pointer issue fixed,
the entries may not be removed from the hash if the intl and local
forms are different.
Lastly, there is no reason for the alias menu to manually convert to
local form before writing the address to the output buffer.
rfc822_write_address() has a display parameter that will call
mutt_addr_for_display() instead when set. Change to set the display
parameter and remove the conversion calls.
This last change obviates the first two changes, but they are a good idea
in any case.
Kevin McCarthy [Wed, 18 Jan 2017 00:09:11 +0000 (16:09 -0800)]
Add casecmp and strdup_key flags to hash_create()
Aliases and (in the future), X-Label hashes will require a hash that
strdups the key. Convert the casecmp parameter of hash_create() to a
flags parameter, and add a flag to strdup the keys.
David Champion [Sun, 15 Jan 2017 03:18:45 +0000 (19:18 -0800)]
Allow initial blank lines in local mailboxes.
Some mailbox-creation tools erroneously append a blank line to a file
before appending a UNIXv7-format mail message, resulting in mailboxes
that are intended to be valid "mbox" folders but are not. Notably old
versions of Mailman do this, making archive files that cannot be read by
mutt.
This patch causes mutt to skip leading NLs and CRs when detecting magic.
Kevin McCarthy [Fri, 6 Jan 2017 22:17:10 +0000 (14:17 -0800)]
Convert HASH to be indexable by unsigned int. (see #3905)
Convert the HASH to be usable for either string or unsigned int keys,
so that a uid hash can be added for imap.
To keep hash-usage code disruption to a minimum, this introduces new
create/insert/find/delete functions for the int hash, but keeps the
old function names for string keys.
This implementation makes the key a union. It may have been a better
idea to introduce a whole new structure, but this way allows minimum
changes to and maximum reuse of the existing hash code.
Kevin McCarthy [Thu, 5 Jan 2017 03:45:59 +0000 (19:45 -0800)]
Fix imap server-side search to call uid2msgno() only once. (see #3905)
After performing a UID SEARCH, the results are parsed in
cmd_parse_search(). This was accidentally calling uid2msgno() twice.
Since that function does a linear search, this has a noticable impact
on large search results.
Kevin McCarthy [Tue, 3 Jan 2017 02:08:17 +0000 (18:08 -0800)]
Add a pattern_cache_t to speed up a few repeated matches.
Vincent Lefèvre reported experiencing an index display performance
issue. This occurred with messages containing many recipients. He
had many index color lines containing ~l. The ~l ended up being run
over and over on these messages, resulting in a noticable slowdown
displaying the index.
This patch adds caching for just a few of the pattern operations (~l,
~u, ~p, ~P) that are potentially expensive and also don't have
arguments. The caching is only enabled for operations repeatedly
matching against the same message: color, hooks, scoring.
The caching is fairly targeted, but isn't that invasive or
complicated.
Kevin McCarthy [Sun, 1 Jan 2017 03:57:07 +0000 (19:57 -0800)]
Canonicalize line endings for GPGME S/MIME encryption. (closes #3904)
This matches the behavior for S/MIME classic mode: OpenSSL converts
the line endings to cr/lf before encrypting. Although Mutt always
canonicalizes the line endings before verifying the signature, some
clients do not do this for encrypted messages.
Michał Kępień [Tue, 13 Dec 2016 19:16:10 +0000 (11:16 -0800)]
Rework OpenSSL certificate verification to support alternative chains. (closes #3903)
The way Mutt currently verifies SSL certificates using OpenSSL does
not support alternative chains, which may cause confusion when some
popular mail providers (e.g. Gmail) are used with specific sets of
trusted CA certificates.
Replace the "manual" verification done by mutt in
check_certificate_by_signer() with SSL_set_verify() using a callback.
OpenSSL then does the certificate verification, including properly
looking at alternative chains. The callback still provides the
opportunity to override using ~/.mutt_certificates or an interactive
prompt.