summaryrefslogtreecommitdiffstats
path: root/mh.c
AgeCommit message (Collapse)Author
2021-10-08Remove trailing slashes when opening maildir/mh mailboxes.Kevin McCarthy
IMAP cleans this up already (and file-based mailboxes don't allow it). It's easy to have this happen by tab-completing a maildir mailbox at the change folder prompt. Removing the slash makes the display more uniform, and prevents some problems such as $trash folder comparison.
2021-01-27Convert all mutt_atoX functions to behave strictly.Kevin McCarthy
* Remove the automatic conversion of NULL and '\0' to 0. Add a flag for the cases that require lax evaluation. * Make trailing characters generate an error by default for the mutt_atouX functions. Add a flag for that case. Most of the IMAP code parses numbers out of a stream, so add the flag to those calls. * The mutt_atouX functions were also behaving incorrectly with invalid input, e.g. "ABC", returning and setting 0. Fix them to return an error in those cases. * Add a mutt_atoll() function, to be used in the next commit. * Change converters to store 0 on error. atos, atoi, and atoui were already doing this, but the others were not.
2020-12-22Merge branch 'stable'Kevin McCarthy
2020-12-22Fix offset to use LOFF_T in a couple places.Kevin McCarthy
The BODY->hdr_offset was incorrectly of type long, which could result in corrupted >2gb mbox files in some circumstances. The uses in mh_rewrite_message() are not as serious, but they should still be of type LOFF_T. I found both of these fixes in a patch file, bug-676388-largefile.patch, in the openSUSE mutt src rpm. It looks like Harald Koenig was the original author of a larger patch in that openSUSE ticket, which was reduced over time as fixes were made to Mutt. Note that patch file also incorrectly adjusted old_hdr_lines in mh.c. I've removed that part, as HEADER->lines is type int. Unfortunately, the BODY->hdr_offset type change will result in a header cache change (i.e. invalidation). I'm not enthused about doing that during a stable release, but the change is important enough to merit it.
2020-12-12Add "headers" parameter to mx_open_message().Kevin McCarthy
This will allow some operations to retrieve only headers, such as ~h pattern matching or the new list menu. Modify the IMAP and POP3 implementation to retrieve only headers when the parameter is set. Headers-only will use the message cache if one exists, but will not populate the message cache (since the body of the message is not downloaded.)
2020-05-08Add utime() loop for _maildir_commit_message().Kevin McCarthy
While fixing up mutt_decrease_mtime(), I thought about creating a helper function to loop for EINTR. However, there is only one other place in the code that cares enough about utime succeeding to check the return value. maildir_commit_message() is used fairly often, so it's possible I might be writing useless error handling. However there are reports (easily found by internet search) of some systems returning EINTR, so might as well fix this place too.
2019-09-30Memcpy header cache fetch values to ensure alignment.Kevin McCarthy
While testing the hcache buffer pool changes, I noticed a misaligned pointer warning when using LMDB. The other header cache backends must ensure alignment of the pointer they return, but LMDB apparently does not. Instead of directly assigning and dereferencing the pointer fetched, use memcpy to the appropriate type, just as the header cache restore operation does.
2019-04-16Convert BUFFER->path to a BUFFER.Kevin McCarthy
Rename to BUFFER->pathbuf to make it clear the field is a BUFFER, and to make sure to catch and review all usages. There are still uses of pathbuf that are truncating and need to be fixed, for example in browser.c and buffy.c. Fix up sidebar usage in one place, that was pointing inside the BUFFY->path with a char *. At the same time, change their "short folder" computation to also use a BUFFER.
2019-01-04Clean up formatting.Kevin McCarthy
Add spaces after if, else, while, for, switch. Unify the brace placement style. The vast majority of the code uses Allman style so convert the relatively few K&R braces over.
2019-01-04Clean up code indentation.Kevin McCarthy
These are mostly automated changes corresponding to the emacs settings: (c-set-style "linux") (setq c-basic-offset 2) (c-set-offset 'case-label '+) Most of the code follows the convention: (add-to-list 'c-cleanup-list 'space-before-funcall) but this is not enforced by this indentation cleanup. Also, I personally dislike tabs, so I have: (setq-default indent-tabs-mode nil) in my own configuration. However I have no desire to change every line just for that effect. So this cleanup does nothing about the mix issue. Some of the secondary files (e.g. regex.c) have been skipped. I've also skipped crypt-gpgme.c, because I need to think about that file. Werner Koch and the GnuPG team contributed most it, and it follows the Gnu indentation settings. It should probably be made uniform with Mutt, but I don't want to discourage future GnuPG contribution to the file. I manually reverted a few unsightly cleanups, and added a few tweeks when I saw things that could be improved.
2018-12-31Remove trailing whitespace.Kevin McCarthy
The result of find . -name "*.[ch]" -exec emacs -batch {} \ --eval="(progn (delete-trailing-whitespace) (and (buffer-modified-p) (save-buffer)))" \;
2018-12-29Change x-label editing flag to be in the envelope.Kevin McCarthy
Handle like In-Reply-To and References editing. Change the flag setting to be inside mutt_copy_header(). The resetting of the changed flag occurs explicitly in the imap and maildir/mh sync_mailbox code. It occurs for mbox in the mx_update_tables() call in mx_sync_mailbox().
2018-12-29Create envelope->changed to mark all field changes.Kevin McCarthy
In subsequent commits, we're going to add the x-label and subject headers changed flags into the envelope. To avoid the list of checks exploding everywhere, just use a single field to check and reset those values. Several places in the code are checking for a null header->env. I wasn't aware this was possible, so I've added todo notes to track down when this occurs.
2018-12-17Add mx operation save_to_header_cache.Kevin McCarthy
This will be used when reading protected headers, to store the encrypted subject in the header cache so it can be searched with.
2018-10-11Convert the rest of mh.c to use BUFFER for file paths.Kevin McCarthy
* mh_read_sequences * mh_sequences_changed * mh_already_notified * mh_mkstemp * mh_update_sequences * mh_sequences_add_one * maildir_update_time * maildir_delayed_parsing * maildir_open_mailbox_append * mh_open_mailbox_append * maildir_mh_open_message * maildir_open_new_message * _mh_commit_message * mh_rewrite_message * mh_sync_mailbox * mh_check_mailbox * maildir_check_empty * mx_is_maildir * mx_is_mh()
2018-10-08Convert maildir_canon_filename() and callers to use BUFFER.Kevin McCarthy
Callers are maildir_check_mailbox(), _maildir_open_find_message(), and maildir_open_find_message().
2018-10-08Convert maildir_sync_message to use BUFFERs.Kevin McCarthy
2018-10-08Convert _maildir_commit_message to use BUFFER.Kevin McCarthy
2018-10-08Convert maildir_parse_dir to use BUFFER.Kevin McCarthy
Note: the uses of buf and tmp don't overlap, so we only use a single BUFFER.
2018-06-25Work around open mailbox monitor code check issue.Kevin McCarthy
The monitor code is too fast, and can result in all the changes for a single directory stat update being missed. Work around this issue by not recording stat time updates when the check_mailbox() is triggered by the monitor. This will cause the next subsequent check to take another look.
2018-06-18Convert context and buffy to use nanosecond timestamps.Kevin McCarthy
The inotify interface has an unfortunate side effect of making Mutt react too quickly to new mail. Sometimes, the mail is only half-delivered when the mailbox is checked. Because Mutt is using the stat mtime - seconds resolution - this means it won't realize there are more messages delivered during the same second. Nanosecond resolution fields were standardized in POSIX.1-2008, so check for and use those if they are available.
2018-06-01Correct spelling mistakes.Edward Betts
2017-09-25Change maildir and mh check_mailbox to use dynamic sized hash. (closes #3973)Kevin McCarthy
The original patch is by Matt Fleming, originally posted at http://www.codeblueprint.co.uk/2017/01/15/a-kernel-devs-approach-to-improving2 The comments there indicate Matt tried to submit to trac and mutt-dev, but ran into registration problems. Thank you for the patch, and sorry for those problems, Matt. I modified the patch by making the same change to the mh_check_mailbox() code too.
2017-05-07Improve maildir and mh to report flag changes in mx_check_mailbox() (closes ↵Kevin McCarthy
#3865) mx_check_mailbox() would update the header flags, but was not returning MUTT_FLAGS back to the index loop. That meant a screen redraw was needed to be notified of externally modified flags. Change maildir_update_flags() to return 1 if the flags were actually changed. Change maildir_check_mailbox() and mh_check_mailbox() to return MUTT_FLAGS when that happens. Thanks to jcdenton and mike-burns for the original patch.
2017-02-10Change "allow_dups" into a flag at hash creation.Kevin McCarthy
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().
2017-02-07Create function to free header cache data.Kevin McCarthy
Kyoto Cabinet documents that data from it should be freed via kcfree(). LMDB claims ownership of the data returned, so convert its free operation to be a noop and remove the malloc from its fetch function.
2017-01-28Adds capability to edit x-labels inside mutt, and to sort by label.David Champion
2016-11-16When $flag_safe is set, flagged messages cannot be deleted.David Champion
This saves them from bulk operations on threads and tagged messages. To remove a flagged message, first unflag it.
2016-11-13Create mx_ops.sync operation. Refactor compress to use the mx_ops.sync.Kevin McCarthy
Change compress.sync_mailbox() to lock the compressed mailbox around both the tempfile sync and compress operations. This will prevent changes made inbetween the two syncs from being overwritten. Thanks to Damien Riegel for his original patch refactoring mx_ops.sync, which this patch is partially based upon.
2016-08-05Fix memleak in mh_read_dir() when sequence parsing fails.Kevin McCarthy
2016-08-01Use a different flag in mx_open_mailbox_append() when mailbox doesn't exist.Kevin McCarthy
The previous commit re-used MUTT_NEWFOLDER, but the meaning of that flag is slightly different: it causes mbox to use fopen with mode "w", and is used only for the case of a brand-new mktemp-generated mbox. Setting it for other non-existing mbox files leads to a race condition between the stat and the fopen/lock, and so could end up truncating an existing mailbox created in-between! Create a different flag, MUTT_APPENDNEW to notify the open_append() functions that the mailbox doesn't exist. Change maildir and mh to check for that flag to create their directory structures.
2016-08-01Convert mx_open_mailbox_append() to use ctx->mx_ops.Kevin McCarthy
Set the flag MUTT_NEWFOLDER to signal Maildir and MH to create the directory structure. Distribute the "open append" code to mbox, mh, and imap/imap.c. Set pop's mx_ops handler to NULL to signal it is not supported.
2016-06-18add commit_msg to struct mx_opsDamien Riegel
2016-06-18add maildir_commit_message functionDamien Riegel
This commit adds a maildir_commit_message with a prototype consistent with other kind of mailboxes, to simplify upcoming refactoring.
2016-06-18prepend maildir_commit_message function name with an underscoreDamien Riegel
Basically, rename maildir_commit_message to _maildir_commit_message. This commit is preparatory to make the maildir_commit_message symbol available for further use. Symbols starting with underscore should be avoided but this one is long enough to prevent collision.
2016-06-18remove unused HEADER parameter in mh_commit_messageDamien Riegel
mh_commit_message is only called in one place with the header parameter set to NULL. To make the commit function consistent with other mailboxes, which only takes ctx and msg as parameters, remove this unused parameter.
2016-06-18add close_msg to struct mx_opsDamien Riegel
2016-06-18pass context in mx_close_messageDamien Riegel
The mx_close_message is one of the few mx_* functions that don't have a context as parameter. To make them more consistent, pass the context.
2016-06-17Add open_msg to struct mx_opsDamien Riegel
Add the callback to open an existing message to struct mx_ops. For mbox, mmdf, maildir, and mh, the code was implemented directly into mx_open_message, so it is moved in their respective source files. For imap and pop, there were already <mailbox>_fetch_message functions, but their argument order has been changed to pass the context as a first argument.
2016-06-17Combine the basic and extended buffy functions.Kevin McCarthy
Add a check_stats parameter to the mbox, maildir, and mh buffy functions. Use that parameter to determine whether to also count total, new, and flagged messages. This makes the functions a bit more complicated, but improves efficiency (for maildir and mh). Also includes the following cleanup/fixes: * Move the orig-value counter reset to the beginnining of the loop, (before tmp->new is set to 0). * Change trashed maildir messages to not be counted in msg_count * Remove an incorrect setting of mailbox->new based on msg_count in maildir. (I missed this one for 1f840760e6e0) * Change mbox to use the context->mtime for stats_last_checked, removing a race condition. * Fix mh to actually count the messages in order to generate msg_count. mh_sequences only covers the range of messages with some sort of flag.
2016-06-07Make extended buffy independent of the sidebar.Kevin McCarthy
Add new boolean option $mail_check_stats (default off) and $mail_check_stats_interval. The first turns extended buffy on. The second sets the amount of time in between extended buffy checks (defaulting to 60 seconds). Remove the option $sidebar_refresh_time. Change mutt_buffy_check() to only notify the sidebar to redraw if a mailbox buffy value changes. Remove the #ifdefs around the extended buffy functions. The next patch will merge these functions with the basic functions and pass a parameter instead. Imap is a special case, because it sends out the status in one batch. Change this to perform the comparisons inside cmd_parse_status() and flag the sidebar there. It was previously directly assigning the status counters (unsigned int) to the buffy->new (short). Change this to assign 1/0.
2016-06-04Start to fix sidebar buffy modifications.Kevin McCarthy
The extended buffy for mh had incorrect placement of the loop brackets. The counters weren't being incremented in the loop. Fix extended buffy for maildir to count a maildir message as new if it doesn't have the info delimeter. Remove shortcircuits added to the basic buffy stating there is new mail when (msg_unread > 0). This is not necessarily true, depending on $mail_check_recent. Note: the extended buffy still needs more fixes, which will be done when it is refactored into its own option.
2016-06-04Add neomutt version of sidebar patch. (closes #3829)Richard Russon
This is the patch from neomutt; branch 'devel/win-sidebar'; commit c796fa85f9cacefb69b8f7d8545fc9ba71674180 with the following changes: - move the sample muttrc and vimrc to contrib. - remove the README.sidebar. - empty out the PATCHES file.
2016-05-26add check operation to struct mx_opsDamien Riegel
In mx_check_mailbox switch case, we simply call <mailbox>_check_mailbox, so this operation can be move into the mx_ops structure pretty easily. This commit adds a mandatory "check" operation to struct mx_ops and change all mailboxes to use it. Check functions are made static as they are only used in their respective source files now.
2016-05-25add open_new_msg operation to struct mx_opsDamien Riegel
The code was already using a function pointer to do this operation. This commit moves this function pointer to the mx_ops structure and the open_new_message functions to their respective source files if it needs to.
2016-05-12Start decoupling mailbox operations.Damien Riegel
Introduce a dedicated structure for mailbox operations: struct mx_ops. Move the open and close operations into that structure. Assign this structure to the context in mx_open_mailbox. This is currently based on the "magic" for the mailbox type, but may be refactored in the future. Add a stub mbox_close_mailbox function. This function does nothing, the main purpose is to introduce a mx_ops structure for mbox, so its usage is similar to mh/imap/pop. We reuse the name that was made available by the previous commmit. Note that the actual closing of the descriptor is done in mx.c. To be more consistent with other mailboxes, introduce functions mh_open_mailbox and maildir_open_mailbox, and create a dedicated structure for mmdf.
2016-05-09Change M_* symbols to MUTT_*Derek Martin
Changeset 23334e967dd7 created a workaround for a namespace conflict with Solaris and derivatives. After some discussion, the team decided it would be best to move away from using the "M_" prefix for macros. This patch was automatically generated by running: perl -wpi -e 's/\bM_(\w+)\b/MUTT_$1/g' `find . -name '*.[ch]' -print` with the exception that sys_socket.h was exempted. (That file will be backed out subsequent to this commit.) Thanks to Andras Salamon for supplying the perl script used to make this change.
2016-01-01Update copyright notices.Kevin McCarthy
This patch only updates existing copyright notices in the source files, using commit dates since the last copyright update in commits e3af935cdb1a and f8fd60d8d3f2. Add a notice to the COPYRIGHT file to refer to our mercurial repository for the full commit history. Add myself to the COPYRIGHT file and smime_keys.pl file.
2015-12-08Fix hash table key "use after free" in mh_check_mailbox(). (closes #3797)Kevin McCarthy
The fnames hash uses the maildir->header->path as the key. As matches are found, the headers are freed. This inadvertantly also freed the key to the hashtable entry; the next hash_find() going to the same bucket might end up comparing keys with a freed string. This patch stores the path in the struct maildir canon_fname field (just as maildir_check_mailbox() does) and uses that as the hash key instead. This field isn't used outside of maildir_check_mailbox(), and is automatically freed for us in the maildir_move_to_context() call at the bottom of both functions. Note there are other ways to fix this problem: - Add a new mode to the hash table, causing it to strdup the keys and free them itself. - Delete the entries in the fnames hash, rather leaving them there. The first seems the cleanest, but would end up touching much more code. The second is also clean, but might have a negative performance impact. Additionally, peeking back in history to changeset 1d45a50b6f9b, it looks like the canon_fname used to be used by mh too, so perhaps removing the strdup may have been a mistake during refactoring at some point.
2015-01-26Corrected various spelling mistakes (most of them reported by codespell).Vincent Lefevre