Kevin McCarthy [Fri, 11 Aug 2017 16:04:48 +0000 (09:04 -0700)]
Fix parent_hdr usage in mutt_attach_reply(). (see #3728)
If the selected attachments are not messages and no (common) parent is
found, parent_hdr is set to the passed in hdr. In that case, parent
will still be NULL, but parent_hdr and parent_fp will be set.
Change the test to parent_hdr being NULL, not parent, to check for
this case.
Kevin McCarthy [Fri, 11 Aug 2017 01:18:28 +0000 (18:18 -0700)]
Add edit-content-type helper and warning for decrypted attachments. (closes #3728)
Regenerating the actx index will overwrite any changes made to a
decrypted attachment. Change the mutt_edit_content_type() function to
return 1 when a structural change is made. Add a warning message when
that is the case and a decrypted message was edited, so the user is
not surprised.
Note: mutt_edit_content_type() appeared to regenerate multipart
subparts every time, leading to a memory leak. I believe this was an
oversite, and it should have regenerated only when there were no
subparts, so have "fixed" this.
Kevin McCarthy [Fri, 11 Aug 2017 01:18:25 +0000 (18:18 -0700)]
Fix shared attachment functions. (see #3728)
With nested decryption, the correct FP is associated with the
ATTACHPTR entry. Also, the BODY entries are not continguous, so the
functions need to iterate over the actx index, not the BODY structure.
Kevin McCarthy [Fri, 11 Aug 2017 01:18:20 +0000 (18:18 -0700)]
Add helpers to add and remove actx entries. (see #3728)
Use the helper in compose update_idx(), to consolidate the resize
logic and simplify the code.
Separate out the actx "free" routine from a routine to empty out the
idx. The index regeneration routines should flush and rebuild the
index without having to renerate the actx structure.
Kevin McCarthy [Fri, 11 Aug 2017 01:18:18 +0000 (18:18 -0700)]
Create ATTACH_CONTEXT to hold attachment index. (see #3728)
Move the idx and idxlen into ATTACH_CONTEXT. In subsequence patches,
this structure will hold more useful items, such as the virtual index.
The swap out is straightforward, except for:
* update_idx() in compose.c, which post-increments the idxlen in the
call and again in the function.
* mutt_gen_attach_list() which doesn't need to returns the new values.
Kevin McCarthy [Sun, 23 Jul 2017 02:48:50 +0000 (19:48 -0700)]
Add $imap_poll_timeout to allow mailbox polling to time out.
Enable the polling flag for the NOOP in imap_check_mailbox(), the
STATUS command in imap_buffy_check(), and the LOGOUT command.
This is not intended to handle all blocking-IO related issues.
However, the periodic NOOP and STATUS are the most frequent places for
mutt to freeze up, especially after a laptop is sleep/woken.
Since these are quick operations with little data, this is a good place
to check if the connection is still working before hanging on a read.
Kevin McCarthy [Fri, 21 Jul 2017 00:30:05 +0000 (17:30 -0700)]
When guessing an attachment type, don't allow text/plain if there is a null character. (see #2933)
Type text/plain should not contain any null characters. Slightly
improve the type guesser by forcing an attachment with any null
characters to be application/octet-stream.
Note the type guesser could use much more improvement, but this is an
easy and obvious fix.
Kevin McCarthy [Wed, 19 Jul 2017 21:04:39 +0000 (14:04 -0700)]
Change imap_cmd_start() to return OK when the cmd_queue is finished. (closes #3956)
Some response handlers can end up recursively calling
imap_cmd_start(), processing all the command completions. If the
outer call was an imap_exec(), this would result in the loop never
being terminated (or just blocking reading a server that has already
finished all the commands).
Change the callers that are simply using it to read a response,
without having called cmd_start(), to check for IMAP_CMD_OK instead.
Currently this is just the open connection function.
When using alloca(), the built-in regexp library limited the failure
stack to 20,000 entries. This value is too large, and causes alloca()
to segfault in the example provided in the ticket.
Decrease the limit to 8000.
Thanks to Thorsten Wißmann for the excellent bug report, which made
debugging this much easier.
Kevin McCarthy [Wed, 12 Jul 2017 19:38:22 +0000 (12:38 -0700)]
Fix crash when $postponed is on another server.
imap_mxcmp() translates NULL to "INBOX". When $postponed points to a
URL with an empty or "INBOX" path, this will end up matching against a
NULL idata->mailbox in imap_status(). This resulted in a crash
because idata->ctx is also NULL.
Thanks to Olaf Hering for the detailed bug report and suggested fix.
Kevin McCarthy [Wed, 14 Jun 2017 22:12:45 +0000 (15:12 -0700)]
Enable all header fields in the compose menu to be translated.
While it is suggested they need not be, for some locales it might be
preferable to be able to localize the fields.
For instance, fr_FR may want to change the punctuation to have a space
in front of the colon. ja_JP may be more comfortable with a native
character set description of the field when using it every day.
Kevin McCarthy [Tue, 13 Jun 2017 01:29:48 +0000 (18:29 -0700)]
Force hard redraw after $sendmail instead of calling mutt_endwin. (closes #3952) (see #3948)
Adding a mutt_endwin() seemed like a clean solution to allowing
ncurses pinentry for $sendmail, but it leaves other users watching a
blank screen. This change is extremely likely to generate a large
number of complaints and bug reports. So instead, force a hard
refresh afterwards.
Vincent expressed some legitimate concerns about exporting this to all
programs lauched by mutt. The user can always set GPG_TTY in their
.bashrc if needed for $sendmail. cf90bf5989f3 should resolve the
refresh issue.
Kevin McCarthy [Wed, 7 Jun 2017 01:38:47 +0000 (18:38 -0700)]
Add a mutt_endwin() before invoking $sendmail. (closes #3948)
This is to support invoking a program such as msmtp that can use gpg
to decrypt a password. The ncurses pinentry can corrupt the screen
unless we exit curses.
Kevin McCarthy [Thu, 1 Jun 2017 22:17:01 +0000 (15:17 -0700)]
Change km_dokey() to return -2 on a timeout/sigwinch.
In some cases, such as tag-prefix or _mutt_enter_string(), it is
desirable to be able to distinguish between a timeout/sigwinch event
and an input error/abort/ctrl-g.
Kevin McCarthy [Wed, 31 May 2017 23:18:29 +0000 (16:18 -0700)]
Add note about message scoring and thread patterns. (see #3947)
Because scoring occurs before the mailbox is sorted, thread patterns
don't work. Document a suggested workaround of pushing the score
command in a folder hook.
Also, fix the link target for the score command synopsis.
Kevin McCarthy [Mon, 29 May 2017 18:48:43 +0000 (11:48 -0700)]
Change $postpone_encrypt to use self-encrypt variables first.
The concept of postpone encryption is similar to self-encrypting on
send. The problem is the $postpone_encrypt_as option doesn't take
into account whether PGP or S/MIME is being used.
Since we need to add the new options for self-encryption, modify
$postpone_encrypt to use them by default instead, falling back to
$postpone_encrypt_as if they are unset. Note $postpone_encrypt_as is
deprecated in the documentation.
$pgp_sign_as and $smime_default_key are inappropriate to use, as they
specify signing key/certs. In some cases, this is a different value
than the encryption key/cert.
Kevin McCarthy [Mon, 29 May 2017 18:48:41 +0000 (11:48 -0700)]
Convert classic s/mime to space delimit findKeys output.
Unlike gpgme and classic pgp, smime used a "cert\ncert\n" pattern.
Convert to use a space-delimited format, so the self-encrypt option
code can be uniform across pgp, s/mime, and gpgme.
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 [Mon, 22 May 2017 11:43:24 +0000 (04:43 -0700)]
Fix mfc overflow check and uninitialized variable.
The check borrowed from mx_alloc_memory() works because it is
incremented 25 at a time. I don't believe it will work for the direct
set case used in imap_alloc_msn_index(). Instead, use a more
conservative check.
In imap_read_headers(), make sure mfhrc is initialized. It would be
tested without being set if imap_cmd_step() returned OK right away.
Kevin McCarthy [Mon, 22 May 2017 01:45:08 +0000 (18:45 -0700)]
Small imap fetch fixes. (see #3942)
Add an integer overflow test, pulled from mx_alloc_memory(), since the
count comes from a potentially hostile server.
After reviewing the RFC a bit, it turns out the server is not supposed
to send EXPUNGE responses during a FETCH. Change the comment, but
keep the conservative code.
Kevin McCarthy [Sun, 21 May 2017 17:51:38 +0000 (10:51 -0700)]
Properly adjust fetch ranges when handling new mail. (see #3942)
When pulling down headers, it is possible for expunge responses to
happen too. If we get a new mail count, we need to take into account
changes to the max_msn due to the expunges.
Kevin McCarthy [Sun, 21 May 2017 01:52:18 +0000 (18:52 -0700)]
Add msn_index and max_msn to find and check boundaries by MSN. (see #3942)
Since there can be gaps in MSNs, the largest MSN in the context is not
necessarily ctx->msgcount.
Use max_msn instead of ctx->msgcount for:
- the starting MSN of new mail header fetching
- boundary checking in fetch, expunge, and other places
Use msn_index to efficiently look up headers by MSN. This makes the
expunge code slightly more efficient. It also makes FETCH handling, and
duplicate FETCH FLAG handling efficient.
Kevin McCarthy [Sun, 21 May 2017 01:52:16 +0000 (18:52 -0700)]
Start fixing imap_read_headers() to account for MSN gaps. (see #3942)
Change the parameters to pass MSN instead of index, to make a bit
simpler.
Change header cache evaluation to look at the largest MSN retrieved
instead of ctx->msgcount for the next fetch start point. This still
depends on the assumption that MSNs are retrieved in ascending order,
which needs to be fixed.
Simplify the header cache inner loop termination and memory cleanup
logic. Fix a memory leak if a hole in the header cache occured.
Fix the header retrieval logic to take into account MSN gaps in the
results. Loop only as long as we get IMAP_CMD_CONTINUE instead of
over a fixed count. Simplify the inner loop termination and memory
cleanup logic too.
Simplify the "new mail while fetching" logic by creating a third outer
loop to handle re-fetches.
Fix msg_fetch_header() to return -2 if msg_parse_fetch() encounters a
corrupt FETCH response. Previously it would pass on the rc of
msg_parse_fetch(), meaning it would return -1 even though the response
was corrupt.
Kevin McCarthy [Sun, 21 May 2017 01:52:13 +0000 (18:52 -0700)]
Fix imap expunge to match msn and fix index. (see #3942)
The expunge needs to match against the MSN now. Since
cmd_parse_expunge() does not automatically fix h->index anymore,
change imap_expunge_mailbox() to fix up the h->index values.
Kevin McCarthy [Sun, 21 May 2017 01:52:12 +0000 (18:52 -0700)]
Move the IMAP msn field to IMAP_HEADER_DATA. (see #3942)
Ticket 3942 revealed that it is possible for a FETCH to have gaps in
the MSN numbers of the results. The code makes many assumptions that
equate context index counts and MSN. This is the first in a series of
commits fixing that assumption.
The header->index field is supposed to hold the SORT_ORDER index
number of the message. If there are gaps in the MSN, than the highext
MSN can in fact be out of the range 0..ctx->msgcount-1.
After studying the code, I believe curs_main.c would actually work
with header->index values out of the range, at least for IMAP. But
some other parts of the code, such as mutt_reopen_mailbox(), do rely
on the values being a valid index to ctx->hdrs[]. And the
intertwining of menu->oldcurrent with header->index values makes me
nervous about future changes.
So, to be safe, move the MSN to its own field in IMAP_HEADER_DATA.
Kevin McCarthy [Sat, 13 May 2017 16:48:28 +0000 (09:48 -0700)]
Don't filter new entries when compacting history save file.
If new entries are added between the two passes, they won't be in the
dup_hash. The original intent was to filter added duplicates, but the
check would also filter brand new entries.
Kevin McCarthy [Sat, 13 May 2017 01:31:36 +0000 (18:31 -0700)]
Add $history_remove_dups option to remove dups from history ring.
When set, duplicate entries will be removed from the history ring when
a new entry is added. The duplicate removal rearranges the history
ring such that created empty slots are right after the "last" position
in the ring, preserving the most history.
Rewrite the next/prev functions to take into account that blank slots can
now be in the middle of the array.
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 [Tue, 9 May 2017 23:07:46 +0000 (16:07 -0700)]
Create R_PAGER_FLOW config variable flag.
Use this for $header_color_partial, $markers, and $smart_wrap. When
these options are changed in the pager, this flag will force a
recalculation of lineInfo.
Remove the manual checks in OP_ENTER_COMMAND for $markers and
$smart_wrap, and instead use the same REDRAW_FLOW processing used for
a SigWinch.
Kevin McCarthy [Tue, 9 May 2017 23:07:42 +0000 (16:07 -0700)]
Rename REDRAW_SIGWINCH to REDRAW_FLOW.
The next patch will attach this redraw flag to pager settings. The
former name becomes somewhat confusing with the expanded usage, so
rename it to something more relevant to what is being redrawn.
Kevin McCarthy [Tue, 9 May 2017 01:48:25 +0000 (18:48 -0700)]
Add $header_color_partial to allow partial coloring of headers.
When set, a regexp match will color only the matched text in the
header. When unset (the default), the entire header will have color
applied.
With appropriate regexps, this allows coloring of just the header
field name. Of course, it can also be used to highlight arbitrary
phrases in the headers too.