IMAP helper functions. More...
#include "config.h"#include <arpa/inet.h>#include <errno.h>#include <netdb.h>#include <signal.h>#include <stdbool.h>#include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/wait.h>#include <unistd.h>#include "private.h"#include "mutt/lib.h"#include "config/lib.h"#include "email/lib.h"#include "core/lib.h"#include "conn/lib.h"#include "lib.h"#include "bcache/lib.h"#include "question/lib.h"#include "store/lib.h"#include "adata.h"#include "edata.h"#include "globals.h"#include "mdata.h"#include "msn.h"#include "hcache/lib.h"Go to the source code of this file.
Functions | |
| int | imap_adata_find (const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata) |
| Find the Account data for this path. | |
| void | imap_mdata_cache_reset (struct ImapMboxData *mdata) |
| Release and clear cache data of ImapMboxData structure. | |
| void | imap_get_parent (const char *mbox, char delim, char *buf, size_t buflen) |
| Get an IMAP folder's parent. | |
| void | imap_get_parent_path (const char *path, char *buf, size_t buflen) |
| Get the path of the parent folder. | |
| void | imap_clean_path (char *path, size_t plen) |
| Cleans an IMAP path using imap_fix_path. | |
| static const char * | imap_get_field (enum ConnAccountField field, void *gf_data) |
| Get connection login credentials - Implements ConnAccount::get_field() -. | |
| static void | imap_msn_index_to_uid_seqset (struct Buffer *buf, struct ImapMboxData *mdata) |
| Convert MSN index of UIDs to Seqset. | |
| static void | imap_hcache_namer (const struct StoreOps *store_ops, const char *path, struct Buffer *dest) |
| Generate a filename for the header cache - Implements hcache_namer_t -. | |
| void | imap_hcache_open (struct ImapAccountData *adata, struct ImapMboxData *mdata, bool create) |
| Open a header cache. | |
| void | imap_hcache_close (struct ImapMboxData *mdata) |
| Close the header cache. | |
| struct Email * | imap_hcache_get (struct ImapMboxData *mdata, unsigned int uid) |
| Get a header cache entry by its UID. | |
| int | imap_hcache_put (struct ImapMboxData *mdata, struct Email *e) |
| Add an entry to the header cache. | |
| int | imap_hcache_del (struct ImapMboxData *mdata, unsigned int uid) |
| Delete an item from the header cache. | |
| int | imap_hcache_store_uid_seqset (struct ImapMboxData *mdata) |
| Store a UID Sequence Set in the header cache. | |
| int | imap_hcache_clear_uid_seqset (struct ImapMboxData *mdata) |
| Delete a UID Sequence Set from the header cache. | |
| char * | imap_hcache_get_uid_seqset (struct ImapMboxData *mdata) |
| Get a UID Sequence Set from the header cache. | |
| int | imap_parse_path (const char *path, struct ConnAccount *cac, char *mailbox, size_t mailboxlen) |
| Parse an IMAP mailbox name into ConnAccount, name. | |
| int | imap_mxcmp (const char *mx1, const char *mx2) |
| Compare mailbox names, giving priority to INBOX. | |
| void | imap_pretty_mailbox (char *path, size_t pathlen, const char *folder) |
| Prettify an IMAP mailbox name. | |
| enum QuadOption | imap_continue (const char *msg, const char *resp) |
| Display a message and ask the user if they want to go on. | |
| void | imap_error (const char *where, const char *msg) |
| Show an error and abort. | |
| char * | imap_fix_path (const char *mailbox, char *path, size_t plen) |
| Fix up the imap path. | |
| char * | imap_fix_path_with_delim (const char delim, const char *mailbox, char *path, size_t plen) |
| Fix up the imap path. | |
| void | imap_cachepath (char delim, const char *mailbox, struct Buffer *dest) |
| Generate a cache path for a mailbox. | |
| int | imap_get_literal_count (char *buf, unsigned int *bytes) |
| Write number of bytes in an IMAP literal into bytes. | |
| char * | imap_get_qualifier (char *buf) |
| Get the qualifier from a tagged response. | |
| char * | imap_next_word (char *s) |
| Find where the next IMAP word begins. | |
| void | imap_qualify_path (char *buf, size_t buflen, struct ConnAccount *cac, char *path) |
| Make an absolute IMAP folder target. | |
| void | imap_buf_qualify_path (struct Buffer *buf, struct ConnAccount *cac, char *path) |
| Make an absolute IMAP folder target to a buffer. | |
| void | imap_quote_string (char *dest, size_t dlen, const char *src, bool quote_backtick) |
| Quote string according to IMAP rules. | |
| void | imap_unquote_string (char *s) |
| Equally stupid unquoting routine. | |
| void | imap_munge_mbox_name (bool unicode, char *dest, size_t dlen, const char *src) |
| Quote awkward characters in a mailbox name. | |
| void | imap_unmunge_mbox_name (bool unicode, char *s) |
| Remove quoting from a mailbox name. | |
| void | imap_keep_alive (void) |
| Poll the current folder to keep the connection alive. | |
| int | imap_wait_keep_alive (pid_t pid) |
| Wait for a process to change state. | |
| void | imap_allow_reopen (struct Mailbox *m) |
| Allow re-opening a folder upon expunge. | |
| void | imap_disallow_reopen (struct Mailbox *m) |
| Disallow re-opening a folder upon expunge. | |
| bool | imap_account_match (const struct ConnAccount *a1, const struct ConnAccount *a2) |
| Compare two Accounts. | |
| struct SeqsetIterator * | mutt_seqset_iterator_new (const char *seqset) |
| Create a new Sequence Set Iterator. | |
| int | mutt_seqset_iterator_next (struct SeqsetIterator *iter, unsigned int *next) |
| Get the next UID from a Sequence Set. | |
| void | mutt_seqset_iterator_free (struct SeqsetIterator **ptr) |
| Free a Sequence Set Iterator. | |
IMAP helper functions.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file util.c.
| int imap_adata_find | ( | const char * | path, |
| struct ImapAccountData ** | adata, | ||
| struct ImapMboxData ** | mdata ) |
Find the Account data for this path.
| 0 | Success |
| -1 | Failure |
Definition at line 73 of file util.c.
| void imap_mdata_cache_reset | ( | struct ImapMboxData * | mdata | ) |
Release and clear cache data of ImapMboxData structure.
| mdata | Imap Mailbox data |
Definition at line 111 of file util.c.
| void imap_get_parent | ( | const char * | mbox, |
| char | delim, | ||
| char * | buf, | ||
| size_t | buflen ) |
Get an IMAP folder's parent.
| mbox | Mailbox whose parent is to be determined |
| delim | Path delimiter |
| buf | Buffer for the result |
| buflen | Length of the buffer |
Definition at line 127 of file util.c.
| void imap_get_parent_path | ( | const char * | path, |
| char * | buf, | ||
| size_t | buflen ) |
Get the path of the parent folder.
| path | Mailbox whose parent is to be determined |
| buf | Buffer for the result |
| buflen | Length of the buffer |
Provided an imap path, returns in buf the parent directory if existent. Else returns the same path.
Definition at line 168 of file util.c.
| void imap_clean_path | ( | char * | path, |
| size_t | plen ) |
Cleans an IMAP path using imap_fix_path.
| path | Path to be cleaned |
| plen | Length of the buffer |
Does it in place.
Definition at line 195 of file util.c.
|
static |
Convert MSN index of UIDs to Seqset.
Generates a seqseq of the UIDs in msn_index to persist in the header cache. Empty spots are stored as 0.
Definition at line 238 of file util.c.
| void imap_hcache_open | ( | struct ImapAccountData * | adata, |
| struct ImapMboxData * | mdata, | ||
| bool | create ) |
Open a header cache.
| adata | Imap Account data |
| mdata | Imap Mailbox data |
| create | Create a new header cache if missing? |
Definition at line 310 of file util.c.
| void imap_hcache_close | ( | struct ImapMboxData * | mdata | ) |
Close the header cache.
| mdata | Imap Mailbox data |
Definition at line 351 of file util.c.
| struct Email * imap_hcache_get | ( | struct ImapMboxData * | mdata, |
| unsigned int | uid ) |
Get a header cache entry by its UID.
| mdata | Imap Mailbox data |
| uid | UID to find |
| ptr | |
| NULL | Failure |
Definition at line 366 of file util.c.
| int imap_hcache_put | ( | struct ImapMboxData * | mdata, |
| struct Email * | e ) |
Add an entry to the header cache.
| 0 | Success |
| -1 | Failure |
Definition at line 391 of file util.c.
| int imap_hcache_del | ( | struct ImapMboxData * | mdata, |
| unsigned int | uid ) |
Delete an item from the header cache.
| mdata | Imap Mailbox data |
| uid | UID of entry to delete |
| 0 | Success |
| -1 | Failure |
Definition at line 409 of file util.c.
| int imap_hcache_store_uid_seqset | ( | struct ImapMboxData * | mdata | ) |
Store a UID Sequence Set in the header cache.
| mdata | Imap Mailbox data |
| 0 | Success |
| -1 | Error |
Definition at line 426 of file util.c.
| int imap_hcache_clear_uid_seqset | ( | struct ImapMboxData * | mdata | ) |
Delete a UID Sequence Set from the header cache.
| mdata | Imap Mailbox data |
| 0 | Success |
| -1 | Error |
Definition at line 447 of file util.c.
| char * imap_hcache_get_uid_seqset | ( | struct ImapMboxData * | mdata | ) |
Get a UID Sequence Set from the header cache.
| mdata | Imap Mailbox data |
| ptr | UID Sequence Set |
| NULL | Error |
Definition at line 461 of file util.c.
| int imap_parse_path | ( | const char * | path, |
| struct ConnAccount * | cac, | ||
| char * | mailbox, | ||
| size_t | mailboxlen ) |
Parse an IMAP mailbox name into ConnAccount, name.
| path | Mailbox path to parse |
| cac | Account credentials |
| mailbox | Buffer for mailbox name |
| mailboxlen | Length of buffer |
| 0 | Success |
| -1 | Failure |
Given an IMAP mailbox name, return host, port and a path IMAP servers will recognize.
Definition at line 485 of file util.c.
| int imap_mxcmp | ( | const char * | mx1, |
| const char * | mx2 ) |
Compare mailbox names, giving priority to INBOX.
| mx1 | First mailbox name |
| mx2 | Second mailbox name |
| <0 | First mailbox precedes Second mailbox |
| 0 | Mailboxes are the same |
| >0 | Second mailbox precedes First mailbox |
Like a normal sort function except that "INBOX" will be sorted to the beginning of the list.
Definition at line 556 of file util.c.
| void imap_pretty_mailbox | ( | char * | path, |
| size_t | pathlen, | ||
| const char * | folder ) |
Prettify an IMAP mailbox name.
| path | Mailbox name to be tidied |
| pathlen | Length of path |
| folder | Path to use for '+' abbreviations |
Called by mutt_pretty_mailbox() to make IMAP paths look nice.
Definition at line 592 of file util.c.
| enum QuadOption imap_continue | ( | const char * | msg, |
| const char * | resp ) |
Display a message and ask the user if they want to go on.
| msg | Location of the error |
| resp | Message for user |
| QuadOption | Result, e.g. MUTT_NO |
Definition at line 657 of file util.c.
| void imap_error | ( | const char * | where, |
| const char * | msg ) |
| char * imap_fix_path | ( | const char * | mailbox, |
| char * | path, | ||
| size_t | plen ) |
Fix up the imap path.
| ptr | Fixed-up path |
This is necessary because the rest of neomutt assumes a hierarchy delimiter of '/', which is not necessarily true in IMAP. Additionally, the filesystem converts multiple hierarchy delimiters into a single one, ie "///" is equal to "/". IMAP servers are not required to do this. Moreover, IMAP servers may dislike the path ending with the delimiter.
Definition at line 689 of file util.c.
| char * imap_fix_path_with_delim | ( | const char | delim, |
| const char * | mailbox, | ||
| char * | path, | ||
| size_t | plen ) |
Fix up the imap path.
| delim | Delimiter specified by the server |
| mailbox | Mailbox path |
| path | Buffer for the result |
| plen | Length of buffer |
| ptr | Fixed-up path |
Definition at line 720 of file util.c.
| void imap_cachepath | ( | char | delim, |
| const char * | mailbox, | ||
| struct Buffer * | dest ) |
Generate a cache path for a mailbox.
Definition at line 756 of file util.c.
| int imap_get_literal_count | ( | char * | buf, |
| unsigned int * | bytes ) |
Write number of bytes in an IMAP literal into bytes.
| [in] | buf | Number as a string |
| [out] | bytes | Resulting number |
| 0 | Success |
| -1 | Failure |
Definition at line 787 of file util.c.
| char * imap_get_qualifier | ( | char * | buf | ) |
Get the qualifier from a tagged response.
| buf | Command string to process |
| ptr | Start of the qualifier |
In a tagged response, skip tag and status for the qualifier message. Used by imap_copy_message for TRYCREATE
Definition at line 814 of file util.c.
| char * imap_next_word | ( | char * | s | ) |
Find where the next IMAP word begins.
| s | Command string to process |
| ptr | Next IMAP word |
Definition at line 831 of file util.c.
| void imap_qualify_path | ( | char * | buf, |
| size_t | buflen, | ||
| struct ConnAccount * | cac, | ||
| char * | path ) |
Make an absolute IMAP folder target.
| buf | Buffer for the result |
| buflen | Length of buffer |
| cac | ConnAccount of the account |
| path | Path relative to the mailbox |
Definition at line 862 of file util.c.
| void imap_buf_qualify_path | ( | struct Buffer * | buf, |
| struct ConnAccount * | cac, | ||
| char * | path ) |
Make an absolute IMAP folder target to a buffer.
| buf | Buffer for the result |
| cac | ConnAccount of the account |
| path | Path relative to the mailbox |
Definition at line 876 of file util.c.
| void imap_quote_string | ( | char * | dest, |
| size_t | dlen, | ||
| const char * | src, | ||
| bool | quote_backtick ) |
Quote string according to IMAP rules.
| dest | Buffer for the result |
| dlen | Length of the buffer |
| src | String to be quoted |
| quote_backtick | If true, quote backticks too |
Surround string with quotes, escape " and \ with backslash
Definition at line 893 of file util.c.
| void imap_unquote_string | ( | char * | s | ) |
Equally stupid unquoting routine.
| s | String to be unquoted |
Definition at line 936 of file util.c.
| void imap_munge_mbox_name | ( | bool | unicode, |
| char * | dest, | ||
| size_t | dlen, | ||
| const char * | src ) |
Quote awkward characters in a mailbox name.
| unicode | true if Unicode is allowed |
| dest | Buffer to store safe mailbox name |
| dlen | Length of buffer |
| src | Mailbox name |
Definition at line 973 of file util.c.
| void imap_unmunge_mbox_name | ( | bool | unicode, |
| char * | s ) |
Remove quoting from a mailbox name.
| unicode | true if Unicode is allowed |
| s | Mailbox name |
The string will be altered in-place.
Definition at line 990 of file util.c.
| void imap_keep_alive | ( | void | ) |
Poll the current folder to keep the connection alive.
Definition at line 1007 of file util.c.
| int imap_wait_keep_alive | ( | pid_t | pid | ) |
Wait for a process to change state.
| pid | Process ID to listen to |
| num | 'wstatus' from waitpid() |
Definition at line 1033 of file util.c.
| void imap_allow_reopen | ( | struct Mailbox * | m | ) |
Allow re-opening a folder upon expunge.
| m | Mailbox |
Definition at line 1080 of file util.c.
| void imap_disallow_reopen | ( | struct Mailbox * | m | ) |
| bool imap_account_match | ( | const struct ConnAccount * | a1, |
| const struct ConnAccount * | a2 ) |
Compare two Accounts.
| a1 | First ConnAccount |
| a2 | Second ConnAccount |
| true | Accounts match |
Definition at line 1108 of file util.c.
| struct SeqsetIterator * mutt_seqset_iterator_new | ( | const char * | seqset | ) |
Create a new Sequence Set Iterator.
| seqset | Source Sequence Set |
| ptr | Newly allocated Sequence Set Iterator |
Definition at line 1140 of file util.c.
| int mutt_seqset_iterator_next | ( | struct SeqsetIterator * | iter, |
| unsigned int * | next ) |
Get the next UID from a Sequence Set.
| [in] | iter | Sequence Set Iterator |
| [out] | next | Next UID in set |
| 0 | Next sequence is generated |
| 1 | Iterator is finished |
| -1 | error |
Definition at line 1161 of file util.c.
| void mutt_seqset_iterator_free | ( | struct SeqsetIterator ** | ptr | ) |