NeoMutt  2019-12-07-60-g0cfa53
Teaching an old dog new tricks
DOXYGEN
imap.h File Reference

IMAP network mailbox. More...

#include <stddef.h>
#include <stdbool.h>
#include <sys/types.h>
#include "core/lib.h"
#include "mx.h"
+ Include dependency graph for imap.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int imap_access (const char *path)
 Check permissions on an IMAP mailbox with a new connection. More...
 
int imap_check_mailbox (struct Mailbox *m, bool force)
 use the NOOP or IDLE command to poll for new mail More...
 
int imap_delete_mailbox (struct Mailbox *m, char *path)
 Delete a mailbox. More...
 
int imap_sync_mailbox (struct Mailbox *m, bool expunge, bool close)
 Sync all the changes to the server. More...
 
int imap_path_status (const char *path, bool queue)
 Refresh the number of total and new messages. More...
 
int imap_mailbox_status (struct Mailbox *m, bool queue)
 Refresh the number of total and new messages. More...
 
int imap_search (struct Mailbox *m, const struct PatternList *pat)
 Find a matching mailbox. More...
 
int imap_subscribe (char *path, bool subscribe)
 Subscribe to a mailbox. More...
 
int imap_complete (char *buf, size_t buflen, const char *path)
 Try to complete an IMAP folder path. More...
 
int imap_fast_trash (struct Mailbox *m, char *dest)
 Use server COPY command to copy deleted messages to trash. More...
 
enum MailboxType imap_path_probe (const char *path, const struct stat *st)
 Is this an IMAP Mailbox? - Implements MxOps::path_probe() More...
 
int imap_path_canon (char *buf, size_t buflen)
 Canonicalise a Mailbox path - Implements MxOps::path_canon() More...
 
int imap_browse (const char *path, struct BrowserState *state)
 IMAP hook into the folder browser. More...
 
int imap_mailbox_create (const char *folder)
 Create a new IMAP mailbox. More...
 
int imap_mailbox_rename (const char *path)
 Rename a mailbox. More...
 
int imap_copy_messages (struct Mailbox *m, struct EmailList *el, const char *dest, bool delete_original)
 Server COPY messages to another folder. More...
 
void imap_logout_all (void)
 close all open connections More...
 
int imap_expand_path (struct Buffer *buf)
 Buffer wrapper around imap_path_canon() More...
 
int imap_parse_path (const char *path, struct ConnAccount *account, char *mailbox, size_t mailboxlen)
 Parse an IMAP mailbox name into ConnAccount, name. More...
 
void imap_pretty_mailbox (char *path, size_t pathlen, const char *folder)
 Prettify an IMAP mailbox name. More...
 
int imap_wait_keepalive (pid_t pid)
 Wait for a process to change state. More...
 
void imap_keepalive (void)
 poll the current folder to keep the connection alive More...
 
void imap_get_parent_path (const char *path, char *buf, size_t buflen)
 Get the path of the parent folder. More...
 
void imap_clean_path (char *path, size_t plen)
 Cleans an IMAP path using imap_fix_path. More...
 

Variables

struct SlistC_ImapAuthenticators
 Config: (imap) List of allowed IMAP authentication methods. More...
 
bool C_ImapIdle
 Config: (imap) Use the IMAP IDLE extension to check for new mail. More...
 
bool C_ImapRfc5161
 Config: (imap) Use the IMAP ENABLE extension to select capabilities. More...
 
char * C_ImapHeaders
 Config: (imap) Additional email headers to download when getting index. More...
 
long C_ImapFetchChunkSize
 Config: (imap) Download headers in blocks of this size. More...
 
bool C_ImapServernoise
 Config: (imap) Display server warnings as error messages. More...
 
char * C_ImapDelimChars
 Config: (imap) Characters that denote separators in IMAP folders. More...
 
short C_ImapPipelineDepth
 Config: (imap) Number of IMAP commands that may be queued up. More...
 
struct MxOps MxImapOps
 IMAP Mailbox - Implements MxOps. More...
 

Detailed Description

IMAP network mailbox.

Authors
  • Michael R. Elkins
  • Brendan Cully
  • Richard Russon

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 imap.h.

Function Documentation

◆ imap_access()

int imap_access ( const char *  path)

Check permissions on an IMAP mailbox with a new connection.

Parameters
pathMailbox path
Return values
0Success
<0Failure

TODO: ACL checks. Right now we assume if it exists we can mess with it. TODO: This method should take a Mailbox as parameter to be able to reuse the existing connection.

Definition at line 601 of file imap.c.

602 {
603  if (imap_path_status(path, false) >= 0)
604  return 0;
605  return -1;
606 }
int imap_path_status(const char *path, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1310
char * path
Path.
Definition: url.h:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_check_mailbox()

int imap_check_mailbox ( struct Mailbox m,
bool  force 
)

use the NOOP or IDLE command to poll for new mail

Parameters
mMailbox
forceDon't wait
Return values
MUTT_REOPENEDmailbox has been externally modified
MUTT_NEW_MAILnew mail has arrived
0no change
-1error

Definition at line 1190 of file imap.c.

1191 {
1192  if (!m || !m->account)
1193  return -1;
1194 
1195  struct ImapAccountData *adata = imap_adata_get(m);
1196  struct ImapMboxData *mdata = imap_mdata_get(m);
1197 
1198  /* overload keyboard timeout to avoid many mailbox checks in a row.
1199  * Most users don't like having to wait exactly when they press a key. */
1200  int rc = 0;
1201 
1202  /* try IDLE first, unless force is set */
1203  if (!force && C_ImapIdle && (adata->capabilities & IMAP_CAP_IDLE) &&
1204  ((adata->state != IMAP_IDLE) || (mutt_date_epoch() >= adata->lastread + C_ImapKeepalive)))
1205  {
1206  if (imap_cmd_idle(adata) < 0)
1207  return -1;
1208  }
1209  if (adata->state == IMAP_IDLE)
1210  {
1211  while ((rc = mutt_socket_poll(adata->conn, 0)) > 0)
1212  {
1213  if (imap_cmd_step(adata) != IMAP_RES_CONTINUE)
1214  {
1215  mutt_debug(LL_DEBUG1, "Error reading IDLE response\n");
1216  return -1;
1217  }
1218  }
1219  if (rc < 0)
1220  {
1221  mutt_debug(LL_DEBUG1, "Poll failed, disabling IDLE\n");
1222  adata->capabilities &= ~IMAP_CAP_IDLE; // Clear the flag
1223  }
1224  }
1225 
1226  if ((force || ((adata->state != IMAP_IDLE) &&
1227  (mutt_date_epoch() >= adata->lastread + C_Timeout))) &&
1228  (imap_exec(adata, "NOOP", IMAP_CMD_POLL) != IMAP_EXEC_SUCCESS))
1229  {
1230  return -1;
1231  }
1232 
1233  /* We call this even when we haven't run NOOP in case we have pending
1234  * changes to process, since we can reopen here. */
1235  imap_cmd_finish(adata);
1236 
1237  if (mdata->check_status & IMAP_EXPUNGE_PENDING)
1238  rc = MUTT_REOPENED;
1239  else if (mdata->check_status & IMAP_NEWMAIL_PENDING)
1240  rc = MUTT_NEW_MAIL;
1241  else if (mdata->check_status & IMAP_FLAGS_PENDING)
1242  rc = MUTT_FLAGS;
1243 
1245 
1246  return rc;
1247 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:411
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1071
#define IMAP_EXPUNGE_PENDING
Messages on the server have been expunged.
Definition: imap_private.h:66
unsigned char state
ImapState, e.g. IMAP_AUTHENTICATED.
Definition: imap_private.h:172
#define IMAP_FLAGS_PENDING
Flags have changed on the server.
Definition: imap_private.h:68
#define IMAP_CMD_POLL
Poll the tcp connection before running the imap command.
Definition: imap_private.h:74
Imap command executed or queued successfully.
Definition: imap_private.h:81
Connection is idle.
Definition: imap_private.h:110
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: util.c:246
int mutt_socket_poll(struct Connection *conn, time_t wait_secs)
Checks whether reads would block.
Definition: socket.c:190
int imap_cmd_idle(struct ImapAccountData *adata)
Enter the IDLE state.
Definition: command.c:1358
ImapOpenFlags check_status
Flags, e.g. IMAP_NEWMAIL_PENDING.
Definition: imap_private.h:220
void * mdata
Driver specific data.
Definition: mailbox.h:135
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1241
WHERE short C_ImapKeepalive
Config: (imap) Time to wait before polling an open IMAP connection.
Definition: globals.h:155
Nondestructive flags change (IMAP)
Definition: mx.h:75
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
WHERE short C_Timeout
Config: Time to wait for user input in menus.
Definition: globals.h:151
#define IMAP_OPEN_NO_FLAGS
No flags are set.
Definition: imap_private.h:63
void imap_cmd_finish(struct ImapAccountData *adata)
Attempt to perform cleanup.
Definition: command.c:1295
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: util.c:115
ImapCapFlags capabilities
Definition: imap_private.h:183
time_t lastread
last time we read a command for the server
Definition: imap_private.h:186
bool C_ImapIdle
Config: (imap) Use the IMAP IDLE extension to check for new mail.
Definition: imap.c:64
#define IMAP_RES_CONTINUE
* ...
Definition: imap_private.h:55
IMAP-specific Account data -.
Definition: imap_private.h:166
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:130
Log at debug level 1.
Definition: logging.h:40
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
#define IMAP_CAP_IDLE
RFC2177: IDLE.
Definition: imap_private.h:131
#define IMAP_NEWMAIL_PENDING
New mail is waiting on the server.
Definition: imap_private.h:67
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
New mail received in Mailbox.
Definition: mx.h:72
Mailbox was reopened.
Definition: mx.h:74
struct Connection * conn
Definition: imap_private.h:168
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_delete_mailbox()

int imap_delete_mailbox ( struct Mailbox m,
char *  path 
)

Delete a mailbox.

Parameters
mMailbox
pathname of the mailbox to delete
Return values
0Success
-1Failure

Definition at line 643 of file imap.c.

644 {
645  char buf[PATH_MAX + 7];
646  char mbox[PATH_MAX];
647  struct Url *url = url_parse(path);
648 
649  struct ImapAccountData *adata = imap_adata_get(m);
650  imap_munge_mbox_name(adata->unicode, mbox, sizeof(mbox), url->path);
651  url_free(&url);
652  snprintf(buf, sizeof(buf), "DELETE %s", mbox);
654  return -1;
655 
656  return 0;
657 }
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src)
Quote awkward characters in a mailbox name.
Definition: util.c:1033
Imap command executed or queued successfully.
Definition: imap_private.h:81
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1241
#define PATH_MAX
Definition: mutt.h:50
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: util.c:115
char * path
Path.
Definition: url.h:73
IMAP-specific Account data -.
Definition: imap_private.h:166
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:130
void url_free(struct Url **u)
Free the contents of a URL.
Definition: url.c:288
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition: imap_private.h:71
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:161
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_sync_mailbox()

int imap_sync_mailbox ( struct Mailbox m,
bool  expunge,
bool  close 
)

Sync all the changes to the server.

Parameters
mMailbox
expungeif true do expunge
closeif true we move imap state to CLOSE
Return values
0Success
-1Error

Definition at line 1634 of file imap.c.

1635 {
1636  if (!m)
1637  return -1;
1638 
1639  struct Email **emails = NULL;
1640  int oldsort;
1641  int rc;
1642 
1643  struct ImapAccountData *adata = imap_adata_get(m);
1644  struct ImapMboxData *mdata = imap_mdata_get(m);
1645 
1646  if (adata->state < IMAP_SELECTED)
1647  {
1648  mutt_debug(LL_DEBUG2, "no mailbox selected\n");
1649  return -1;
1650  }
1651 
1652  /* This function is only called when the calling code expects the context
1653  * to be changed. */
1654  imap_allow_reopen(m);
1655 
1656  rc = imap_check_mailbox(m, false);
1657  if (rc < 0)
1658  return rc;
1659 
1660  /* if we are expunging anyway, we can do deleted messages very quickly... */
1661  if (expunge && (m->rights & MUTT_ACL_DELETE))
1662  {
1663  rc = imap_exec_msgset(m, "UID STORE", "+FLAGS.SILENT (\\Deleted)",
1664  MUTT_DELETED, true, false);
1665  if (rc < 0)
1666  {
1667  mutt_error(_("Expunge failed"));
1668  return rc;
1669  }
1670 
1671  if (rc > 0)
1672  {
1673  /* mark these messages as unchanged so second pass ignores them. Done
1674  * here so BOGUS UW-IMAP 4.7 SILENT FLAGS updates are ignored. */
1675  for (int i = 0; i < m->msg_count; i++)
1676  {
1677  struct Email *e = m->emails[i];
1678  if (!e)
1679  break;
1680  if (e->deleted && e->changed)
1681  e->active = false;
1682  }
1683  mutt_message(ngettext("Marking %d message deleted...",
1684  "Marking %d messages deleted...", rc),
1685  rc);
1686  }
1687  }
1688 
1689 #ifdef USE_HCACHE
1690  mdata->hcache = imap_hcache_open(adata, mdata);
1691 #endif
1692 
1693  /* save messages with real (non-flag) changes */
1694  for (int i = 0; i < m->msg_count; i++)
1695  {
1696  struct Email *e = m->emails[i];
1697  if (!e)
1698  break;
1699 
1700  if (e->deleted)
1701  {
1702  imap_cache_del(m, e);
1703 #ifdef USE_HCACHE
1704  imap_hcache_del(mdata, imap_edata_get(e)->uid);
1705 #endif
1706  }
1707 
1708  if (e->active && e->changed)
1709  {
1710 #ifdef USE_HCACHE
1711  imap_hcache_put(mdata, e);
1712 #endif
1713  /* if the message has been rethreaded or attachments have been deleted
1714  * we delete the message and reupload it.
1715  * This works better if we're expunging, of course. */
1716  /* TODO: why the e->env check? */
1717  if ((e->env && e->env->changed) || e->attach_del)
1718  {
1719  /* L10N: The plural is chosen by the last %d, i.e. the total number */
1720  mutt_message(ngettext("Saving changed message... [%d/%d]",
1721  "Saving changed messages... [%d/%d]", m->msg_count),
1722  i + 1, m->msg_count);
1723  bool save_append = m->append;
1724  m->append = true;
1725  mutt_save_message_ctx(e, true, false, false, m);
1726  m->append = save_append;
1727  /* TODO: why the check for h->env? Is this possible? */
1728  if (e->env)
1729  e->env->changed = 0;
1730  }
1731  }
1732  }
1733 
1734 #ifdef USE_HCACHE
1735  imap_hcache_close(mdata);
1736 #endif
1737 
1738  /* presort here to avoid doing 10 resorts in imap_exec_msgset */
1739  oldsort = C_Sort;
1740  if (C_Sort != SORT_ORDER)
1741  {
1742  emails = m->emails;
1743  m->emails = mutt_mem_malloc(m->msg_count * sizeof(struct Email *));
1744  memcpy(m->emails, emails, m->msg_count * sizeof(struct Email *));
1745 
1746  C_Sort = SORT_ORDER;
1747  qsort(m->emails, m->msg_count, sizeof(struct Email *), mutt_get_sort_func(SORT_ORDER));
1748  }
1749 
1750  rc = sync_helper(m, MUTT_ACL_DELETE, MUTT_DELETED, "\\Deleted");
1751  if (rc >= 0)
1752  rc |= sync_helper(m, MUTT_ACL_WRITE, MUTT_FLAG, "\\Flagged");
1753  if (rc >= 0)
1754  rc |= sync_helper(m, MUTT_ACL_WRITE, MUTT_OLD, "Old");
1755  if (rc >= 0)
1756  rc |= sync_helper(m, MUTT_ACL_SEEN, MUTT_READ, "\\Seen");
1757  if (rc >= 0)
1758  rc |= sync_helper(m, MUTT_ACL_WRITE, MUTT_REPLIED, "\\Answered");
1759 
1760  if (oldsort != C_Sort)
1761  {
1762  C_Sort = oldsort;
1763  FREE(&m->emails);
1764  m->emails = emails;
1765  }
1766 
1767  /* Flush the queued flags if any were changed in sync_helper. */
1768  if (rc > 0)
1769  if (imap_exec(adata, NULL, IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS)
1770  rc = -1;
1771 
1772  if (rc < 0)
1773  {
1774  if (close)
1775  {
1776  if (mutt_yesorno(_("Error saving flags. Close anyway?"), MUTT_NO) == MUTT_YES)
1777  {
1778  adata->state = IMAP_AUTHENTICATED;
1779  return 0;
1780  }
1781  }
1782  else
1783  mutt_error(_("Error saving flags"));
1784  return -1;
1785  }
1786 
1787  /* Update local record of server state to reflect the synchronization just
1788  * completed. imap_read_headers always overwrites hcache-origin flags, so
1789  * there is no need to mutate the hcache after flag-only changes. */
1790  for (int i = 0; i < m->msg_count; i++)
1791  {
1792  struct Email *e = m->emails[i];
1793  if (!e)
1794  break;
1795  struct ImapEmailData *edata = imap_edata_get(e);
1796  edata->deleted = e->deleted;
1797  edata->flagged = e->flagged;
1798  edata->old = e->old;
1799  edata->read = e->read;
1800  edata->replied = e->replied;
1801  e->changed = false;
1802  }
1803  m->changed = false;
1804 
1805  /* We must send an EXPUNGE command if we're not closing. */
1806  if (expunge && !close && (m->rights & MUTT_ACL_DELETE))
1807  {
1808  mutt_message(_("Expunging messages from server..."));
1809  /* Set expunge bit so we don't get spurious reopened messages */
1810  mdata->reopen |= IMAP_EXPUNGE_EXPECTED;
1811  if (imap_exec(adata, "EXPUNGE", IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS)
1812  {
1813  mdata->reopen &= ~IMAP_EXPUNGE_EXPECTED;
1814  imap_error(_("imap_sync_mailbox: EXPUNGE failed"), adata->buf);
1815  return -1;
1816  }
1817  mdata->reopen &= ~IMAP_EXPUNGE_EXPECTED;
1818  }
1819 
1820  if (expunge && close)
1821  {
1822  adata->closing = true;
1823  imap_exec(adata, "CLOSE", IMAP_CMD_QUEUE);
1824  adata->state = IMAP_AUTHENTICATED;
1825  }
1826 
1827  if (C_MessageCacheClean)
1828  imap_cache_clean(m);
1829 
1830  return 0;
1831 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:98
int mutt_save_message_ctx(struct Email *e, bool delete_original, bool decode, bool decrypt, struct Mailbox *m)
Save a message to a given mailbox.
Definition: commands.c:987
Deleted messages.
Definition: mutt.h:105
WHERE bool C_MessageCacheClean
Config: (imap/pop) Clean out obsolete entries from the message cache.
Definition: globals.h:243
header_cache_t * imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata)
Open a header cache.
Definition: util.c:419
int msg_count
Total number of messages.
Definition: mailbox.h:90
The envelope/body of an email.
Definition: email.h:37
int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e)
Add an entry to the header cache.
Definition: util.c:502
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition: message.c:100
Mailbox is selected.
Definition: imap_private.h:107
#define mutt_message(...)
Definition: logging.h:83
static int sync_helper(struct Mailbox *m, AclFlags right, int flag, const char *name)
Sync flag changes to the server.
Definition: imap.c:304
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
bool attach_del
Has an attachment marked for deletion.
Definition: email.h:49
unsigned char state
ImapState, e.g. IMAP_AUTHENTICATED.
Definition: imap_private.h:172
ImapOpenFlags reopen
Flags, e.g. IMAP_REOPEN_ALLOW.
Definition: imap_private.h:219
Flagged messages.
Definition: mutt.h:106
#define _(a)
Definition: message.h:28
bool changed
Email has been edited.
Definition: email.h:48
int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid)
Delete an item from the header cache.
Definition: util.c:520
#define MUTT_ACL_DELETE
Delete a message.
Definition: mailbox.h:65
Messages that have been replied to.
Definition: mutt.h:99
bool flagged
Definition: message.h:39
unsigned char changed
Changed fields, e.g. MUTT_ENV_CHANGED_SUBJECT.
Definition: envelope.h:88
Imap command executed or queued successfully.
Definition: imap_private.h:81
bool deleted
Definition: message.h:38
header_cache_t * hcache
Definition: imap_private.h:239
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: util.c:246
bool read
Email is read.
Definition: email.h:51
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: curs_lib.c:376
Log at debug level 2.
Definition: logging.h:41
bool old
Email is seen, but unread.
Definition: email.h:50
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:55
struct Envelope * env
Envelope information.
Definition: email.h:89
int imap_exec_msgset(struct Mailbox *m, const char *pre, const char *post, int flag, bool changed, bool invert)
Prepare commands for all messages matching conditions.
Definition: imap.c:1010
void imap_hcache_close(struct ImapMboxData *mdata)
Close the header cache.
Definition: util.c:456
WHERE short C_Sort
Config: Sort method for the index.
Definition: sort.h:58
void * mdata
Driver specific data.
Definition: mailbox.h:135
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition: mailbox.h:73
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1241
Old messages.
Definition: mutt.h:98
bool active
Message is not to be removed.
Definition: email.h:59
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:39
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
void imap_error(const char *where, const char *msg)
show an error and abort
Definition: util.c:778
Messages that have been read.
Definition: mutt.h:100
Connection is authenticated.
Definition: imap_private.h:106
bool replied
Definition: message.h:40
bool old
Definition: message.h:37
bool append
Mailbox is opened in append mode.
Definition: mailbox.h:112
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: util.c:115
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:120
int imap_check_mailbox(struct Mailbox *m, bool force)
use the NOOP or IDLE command to poll for new mail
Definition: imap.c:1190
IMAP-specific Account data -.
Definition: imap_private.h:166
#define IMAP_EXPUNGE_EXPECTED
Messages will be expunged from the server.
Definition: imap_private.h:65
bool flagged
Marked important?
Definition: email.h:43
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
bool deleted
Email is deleted.
Definition: email.h:45
void * edata
Driver-specific data.
Definition: email.h:106
#define IMAP_CMD_QUEUE
Queue a command, do not execute.
Definition: imap_private.h:73
#define mutt_error(...)
Definition: logging.h:84
bool replied
Email has been replied to.
Definition: email.h:54
void imap_allow_reopen(struct Mailbox *m)
Allow re-opening a folder upon expunge.
Definition: util.c:1138
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition: imap_private.h:71
#define FREE(x)
Definition: memory.h:40
bool read
Definition: message.h:36
#define MUTT_ACL_SEEN
Change the &#39;seen&#39; status of a message.
Definition: mailbox.h:72
bool changed
Mailbox has been modified.
Definition: mailbox.h:113
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
IMAP-specific Email data -.
Definition: message.h:33
sort_t mutt_get_sort_func(enum SortType method)
Get the sort function for a given sort id.
Definition: sort.c:322
int imap_cache_del(struct Mailbox *m, struct Email *e)
Delete an email from the body cache.
Definition: message.c:1759
int imap_cache_clean(struct Mailbox *m)
Delete all the entries in the message cache.
Definition: message.c:1778
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_path_status()

int imap_path_status ( const char *  path,
bool  queue 
)

Refresh the number of total and new messages.

Parameters
pathMailbox path
queueQueue the STATUS command
Return values
numTotal number of messages

Definition at line 1310 of file imap.c.

1311 {
1312  struct Mailbox *m = mx_mbox_find2(path);
1313  if (m)
1314  return imap_mailbox_status(m, queue);
1315 
1316  // FIXME(sileht): Is that case possible ?
1317  struct ImapAccountData *adata = NULL;
1318  struct ImapMboxData *mdata = NULL;
1319 
1320  if (imap_adata_find(path, &adata, &mdata) < 0)
1321  return -1;
1322  int rc = imap_status(adata, mdata, queue);
1323  imap_mdata_free((void *) &mdata);
1324  return rc;
1325 }
void imap_mdata_free(void **ptr)
Release and clear storage in an ImapMboxData structure.
Definition: util.c:227
static int imap_status(struct ImapAccountData *adata, struct ImapMboxData *mdata, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1256
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1576
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:130
void * mdata
Driver specific data.
Definition: mailbox.h:135
A mailbox.
Definition: mailbox.h:80
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
int imap_mailbox_status(struct Mailbox *m, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1336
IMAP-specific Account data -.
Definition: imap_private.h:166
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_mailbox_status()

int imap_mailbox_status ( struct Mailbox m,
bool  queue 
)

Refresh the number of total and new messages.

Parameters
mMailbox
queueQueue the STATUS command
Return values
numTotal number of messages
-1Error
Note
Prepare the mailbox if we are not connected

Definition at line 1336 of file imap.c.

1337 {
1338  struct ImapAccountData *adata = imap_adata_get(m);
1339  struct ImapMboxData *mdata = imap_mdata_get(m);
1340  if (!adata || !mdata)
1341  return -1;
1342  return imap_status(adata, mdata, queue);
1343 }
static int imap_status(struct ImapAccountData *adata, struct ImapMboxData *mdata, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1256
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: util.c:246
void * mdata
Driver specific data.
Definition: mailbox.h:135
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: util.c:115
IMAP-specific Account data -.
Definition: imap_private.h:166
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_search()

int imap_search ( struct Mailbox m,
const struct PatternList *  pat 
)

Find a matching mailbox.

Parameters
mMailbox
patPattern to match
Return values
0Success
-1Failure

Definition at line 1352 of file imap.c.

1353 {
1354  struct Buffer buf;
1355  struct ImapAccountData *adata = imap_adata_get(m);
1356  for (int i = 0; i < m->msg_count; i++)
1357  {
1358  struct Email *e = m->emails[i];
1359  if (!e)
1360  break;
1361  e->matched = false;
1362  }
1363 
1364  if (do_search(pat, true) == 0)
1365  return 0;
1366 
1367  mutt_buffer_init(&buf);
1368  mutt_buffer_addstr(&buf, "UID SEARCH ");
1369  if (compile_search(m, pat, &buf) < 0)
1370  {
1371  FREE(&buf.data);
1372  return -1;
1373  }
1374  if (imap_exec(adata, buf.data, IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS)
1375  {
1376  FREE(&buf.data);
1377  return -1;
1378  }
1379 
1380  FREE(&buf.data);
1381  return 0;
1382 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:98
int msg_count
Total number of messages.
Definition: mailbox.h:90
The envelope/body of an email.
Definition: email.h:37
String manipulation buffer.
Definition: buffer.h:33
Imap command executed or queued successfully.
Definition: imap_private.h:81
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1241
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
static int compile_search(struct Mailbox *m, const struct PatternList *pat, struct Buffer *buf)
Convert NeoMutt pattern to IMAP search.
Definition: imap.c:384
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: util.c:115
IMAP-specific Account data -.
Definition: imap_private.h:166
static int do_search(const struct PatternList *search, bool allpats)
Perform a search of messages.
Definition: imap.c:342
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition: imap_private.h:71
#define FREE(x)
Definition: memory.h:40
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
bool matched
Search matches this Email.
Definition: email.h:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_subscribe()

int imap_subscribe ( char *  path,
bool  subscribe 
)

Subscribe to a mailbox.

Parameters
pathMailbox path
subscribeTrue: subscribe, false: unsubscribe
Return values
0Success
-1Failure

Definition at line 1391 of file imap.c.

1392 {
1393  struct ImapAccountData *adata = NULL;
1394  struct ImapMboxData *mdata = NULL;
1395  char buf[2048];
1396  char errstr[256];
1397  struct Buffer err, token;
1398 
1399  if (imap_adata_find(path, &adata, &mdata) < 0)
1400  return -1;
1401 
1403  {
1404  char mbox[1024];
1405  mutt_buffer_init(&token);
1406  mutt_buffer_init(&err);
1407  err.data = errstr;
1408  err.dsize = sizeof(errstr);
1409  size_t len = snprintf(mbox, sizeof(mbox), "%smailboxes ", subscribe ? "" : "un");
1410  imap_quote_string(mbox + len, sizeof(mbox) - len, path, true);
1411  if (mutt_parse_rc_line(mbox, &token, &err))
1412  mutt_debug(LL_DEBUG1, "Error adding subscribed mailbox: %s\n", errstr);
1413  FREE(&token.data);
1414  }
1415 
1416  if (subscribe)
1417  mutt_message(_("Subscribing to %s..."), mdata->name);
1418  else
1419  mutt_message(_("Unsubscribing from %s..."), mdata->name);
1420 
1421  snprintf(buf, sizeof(buf), "%sSUBSCRIBE %s", subscribe ? "" : "UN", mdata->munge_name);
1422 
1423  if (imap_exec(adata, buf, IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS)
1424  {
1425  imap_mdata_free((void *) &mdata);
1426  return -1;
1427  }
1428 
1429  if (subscribe)
1430  mutt_message(_("Subscribed to %s"), mdata->name);
1431  else
1432  mutt_message(_("Unsubscribed from %s"), mdata->name);
1433  imap_mdata_free((void *) &mdata);
1434  return 0;
1435 }
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
quote string according to IMAP rules
Definition: util.c:959
#define mutt_message(...)
Definition: logging.h:83
void imap_mdata_free(void **ptr)
Release and clear storage in an ImapMboxData structure.
Definition: util.c:227
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
Imap command executed or queued successfully.
Definition: imap_private.h:81
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:130
void * mdata
Driver specific data.
Definition: mailbox.h:135
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1241
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
char * name
Mailbox name.
Definition: imap_private.h:215
WHERE bool C_ImapCheckSubscribed
Config: (imap) When opening a mailbox, ask the server for a list of subscribed folders.
Definition: globals.h:222
IMAP-specific Account data -.
Definition: imap_private.h:166
Log at debug level 1.
Definition: logging.h:40
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition: imap_private.h:71
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
char * munge_name
Munged version of the mailbox name.
Definition: imap_private.h:216
enum CommandResult mutt_parse_rc_line(char *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: init.c:3252
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_complete()

int imap_complete ( char *  buf,
size_t  buflen,
const char *  path 
)

Try to complete an IMAP folder path.

Parameters
bufBuffer for result
buflenLength of buffer
pathPartial mailbox name to complete
Return values
0Success
-1Failure

Given a partial IMAP folder path, return a string which adds as much to the path as is unique

Definition at line 1448 of file imap.c.

1449 {
1450  struct ImapAccountData *adata = NULL;
1451  struct ImapMboxData *mdata = NULL;
1452  char tmp[2048];
1453  struct ImapList listresp;
1454  char completion[1024];
1455  int clen;
1456  size_t matchlen = 0;
1457  int completions = 0;
1458  int rc;
1459 
1460  if (imap_adata_find(path, &adata, &mdata) < 0)
1461  {
1462  mutt_str_strfcpy(buf, path, buflen);
1463  return complete_hosts(buf, buflen);
1464  }
1465 
1466  /* fire off command */
1467  snprintf(tmp, sizeof(tmp), "%s \"\" \"%s%%\"",
1468  C_ImapListSubscribed ? "LSUB" : "LIST", mdata->real_name);
1469 
1470  imap_cmd_start(adata, tmp);
1471 
1472  /* and see what the results are */
1473  mutt_str_strfcpy(completion, mdata->name, sizeof(completion));
1474  imap_mdata_free((void *) &mdata);
1475 
1476  adata->cmdresult = &listresp;
1477  do
1478  {
1479  listresp.name = NULL;
1480  rc = imap_cmd_step(adata);
1481 
1482  if ((rc == IMAP_RES_CONTINUE) && listresp.name)
1483  {
1484  /* if the folder isn't selectable, append delimiter to force browse
1485  * to enter it on second tab. */
1486  if (listresp.noselect)
1487  {
1488  clen = strlen(listresp.name);
1489  listresp.name[clen++] = listresp.delim;
1490  listresp.name[clen] = '\0';
1491  }
1492  /* copy in first word */
1493  if (!completions)
1494  {
1495  mutt_str_strfcpy(completion, listresp.name, sizeof(completion));
1496  matchlen = strlen(completion);
1497  completions++;
1498  continue;
1499  }
1500 
1501  matchlen = longest_common_prefix(completion, listresp.name, 0, matchlen);
1502  completions++;
1503  }
1504  } while (rc == IMAP_RES_CONTINUE);
1505  adata->cmdresult = NULL;
1506 
1507  if (completions)
1508  {
1509  /* reformat output */
1510  imap_qualify_path(buf, buflen, &adata->conn_account, completion);
1511  mutt_pretty_mailbox(buf, buflen);
1512  return 0;
1513  }
1514 
1515  return -1;
1516 }
WHERE bool C_ImapListSubscribed
Config: (imap) When browsing a mailbox, only display subscribed folders.
Definition: globals.h:224
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1071
void imap_mdata_free(void **ptr)
Release and clear storage in an ImapMboxData structure.
Definition: util.c:227
struct ConnAccount conn_account
Definition: imap_private.h:169
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path)
Make an absolute IMAP folder target.
Definition: util.c:942
Items in an IMAP browser.
Definition: imap_private.h:144
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition: command.c:1057
static int complete_hosts(char *buf, size_t buflen)
Look for completion matches for mailboxes.
Definition: imap.c:514
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:130
void * mdata
Driver specific data.
Definition: mailbox.h:135
char * name
Definition: imap_private.h:146
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
char * name
Mailbox name.
Definition: imap_private.h:215
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:627
char * real_name
Original Mailbox name, e.g.: INBOX can be just \0.
Definition: imap_private.h:217
#define IMAP_RES_CONTINUE
* ...
Definition: imap_private.h:55
IMAP-specific Account data -.
Definition: imap_private.h:166
static size_t longest_common_prefix(char *dest, const char *src, size_t start, size_t dlen)
Find longest prefix common to two strings.
Definition: imap.c:493
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
struct ImapList * cmdresult
Definition: imap_private.h:195
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_fast_trash()

int imap_fast_trash ( struct Mailbox m,
char *  dest 
)

Use server COPY command to copy deleted messages to trash.

Parameters
mMailbox
destMailbox to move to
Return values
-1Error
0Success
1Non-fatal error - try fetch/append

Definition at line 1526 of file imap.c.

1527 {
1528  char prompt[1024];
1529  int rc = -1;
1530  bool triedcreate = false;
1531  enum QuadOption err_continue = MUTT_NO;
1532 
1533  struct ImapAccountData *adata = imap_adata_get(m);
1534  struct ImapAccountData *dest_adata = NULL;
1535  struct ImapMboxData *dest_mdata = NULL;
1536 
1537  if (imap_adata_find(dest, &dest_adata, &dest_mdata) < 0)
1538  return -1;
1539 
1540  struct Buffer sync_cmd = mutt_buffer_make(0);
1541 
1542  /* check that the save-to folder is in the same account */
1543  if (!mutt_account_match(&(adata->conn->account), &(dest_adata->conn->account)))
1544  {
1545  mutt_debug(LL_DEBUG3, "%s not same server as %s\n", dest, mailbox_path(m));
1546  goto out;
1547  }
1548 
1549  for (int i = 0; i < m->msg_count; i++)
1550  {
1551  struct Email *e = m->emails[i];
1552  if (!e)
1553  break;
1554  if (e->active && e->changed && e->deleted && !e->purge)
1555  {
1556  rc = imap_sync_message_for_copy(m, e, &sync_cmd, &err_continue);
1557  if (rc < 0)
1558  {
1559  mutt_debug(LL_DEBUG1, "could not sync\n");
1560  goto out;
1561  }
1562  }
1563  }
1564 
1565  /* loop in case of TRYCREATE */
1566  do
1567  {
1568  rc = imap_exec_msgset(m, "UID COPY", dest_mdata->munge_name, MUTT_TRASH, false, false);
1569  if (rc == 0)
1570  {
1571  mutt_debug(LL_DEBUG1, "No messages to trash\n");
1572  rc = -1;
1573  goto out;
1574  }
1575  else if (rc < 0)
1576  {
1577  mutt_debug(LL_DEBUG1, "could not queue copy\n");
1578  goto out;
1579  }
1580  else
1581  {
1582  mutt_message(ngettext("Copying %d message to %s...", "Copying %d messages to %s...", rc),
1583  rc, dest_mdata->name);
1584  }
1585 
1586  /* let's get it on */
1587  rc = imap_exec(adata, NULL, IMAP_CMD_NO_FLAGS);
1588  if (rc == IMAP_EXEC_ERROR)
1589  {
1590  if (triedcreate)
1591  {
1592  mutt_debug(LL_DEBUG1, "Already tried to create mailbox %s\n", dest_mdata->name);
1593  break;
1594  }
1595  /* bail out if command failed for reasons other than nonexistent target */
1596  if (!mutt_str_startswith(imap_get_qualifier(adata->buf), "[TRYCREATE]", CASE_IGNORE))
1597  break;
1598  mutt_debug(LL_DEBUG3, "server suggests TRYCREATE\n");
1599  snprintf(prompt, sizeof(prompt), _("Create %s?"), dest_mdata->name);
1600  if (C_Confirmcreate && (mutt_yesorno(prompt, MUTT_YES) != MUTT_YES))
1601  {
1602  mutt_clear_error();
1603  goto out;
1604  }
1605  if (imap_create_mailbox(adata, dest_mdata->name) < 0)
1606  break;
1607  triedcreate = true;
1608  }
1609  } while (rc == IMAP_EXEC_ERROR);
1610 
1611  if (rc != IMAP_EXEC_SUCCESS)
1612  {
1613  imap_error("imap_fast_trash", adata->buf);
1614  goto out;
1615  }
1616 
1617  rc = IMAP_EXEC_SUCCESS;
1618 
1619 out:
1620  mutt_buffer_dealloc(&sync_cmd);
1621  imap_mdata_free((void *) &dest_mdata);
1622 
1623  return ((rc == IMAP_EXEC_SUCCESS) ? 0 : -1);
1624 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:98
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
int msg_count
Total number of messages.
Definition: mailbox.h:90
The envelope/body of an email.
Definition: email.h:37
struct ConnAccount account
Definition: connection.h:36
#define mutt_message(...)
Definition: logging.h:83
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
void imap_mdata_free(void **ptr)
Release and clear storage in an ImapMboxData structure.
Definition: util.c:227
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
bool changed
Email has been edited.
Definition: email.h:48
WHERE bool C_Confirmcreate
Config: Confirm before creating a new mailbox.
Definition: globals.h:208
Imap command executed or queued successfully.
Definition: imap_private.h:81
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: curs_lib.c:376
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:130
int imap_exec_msgset(struct Mailbox *m, const char *pre, const char *post, int flag, bool changed, bool invert)
Prepare commands for all messages matching conditions.
Definition: imap.c:1010
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1241
int imap_sync_message_for_copy(struct Mailbox *m, struct Email *e, struct Buffer *cmd, enum QuadOption *err_continue)
Update server to reflect the flags of a single message.
Definition: imap.c:1088
bool active
Message is not to be removed.
Definition: email.h:59
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:39
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
void imap_error(const char *where, const char *msg)
show an error and abort
Definition: util.c:778
char * name
Mailbox name.
Definition: imap_private.h:215
bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare account info (host/port/user)
Definition: mutt_account.c:61
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: util.c:115
Ignore case when comparing strings.
Definition: string2.h:68
bool purge
Skip trash folder when deleting.
Definition: email.h:46
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
Definition: util.c:894
int imap_create_mailbox(struct ImapAccountData *adata, char *mailbox)
Create a new mailbox.
Definition: imap.c:575
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
IMAP-specific Account data -.
Definition: imap_private.h:166
Log at debug level 1.
Definition: logging.h:40
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
bool deleted
Email is deleted.
Definition: email.h:45
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition: imap_private.h:71
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
char * munge_name
Munged version of the mailbox name.
Definition: imap_private.h:216
Trashed messages.
Definition: mutt.h:112
Log at debug level 3.
Definition: logging.h:42
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
struct Connection * conn
Definition: imap_private.h:168
Imap command failure.
Definition: imap_private.h:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_path_probe()

enum MailboxType imap_path_probe ( const char *  path,
const struct stat *  st 
)

Is this an IMAP Mailbox? - Implements MxOps::path_probe()

Definition at line 2474 of file imap.c.

2475 {
2476  if (!path)
2477  return MUTT_UNKNOWN;
2478 
2479  if (mutt_str_startswith(path, "imap://", CASE_IGNORE))
2480  return MUTT_IMAP;
2481 
2482  if (mutt_str_startswith(path, "imaps://", CASE_IGNORE))
2483  return MUTT_IMAP;
2484 
2485  return MUTT_UNKNOWN;
2486 }
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:46
Ignore case when comparing strings.
Definition: string2.h:68
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
char * path
Path of Email (for local Mailboxes)
Definition: email.h:91
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_path_canon()

int imap_path_canon ( char *  buf,
size_t  buflen 
)

Canonicalise a Mailbox path - Implements MxOps::path_canon()

Definition at line 2491 of file imap.c.

2492 {
2493  if (!buf)
2494  return -1;
2495 
2496  struct Url *url = url_parse(buf);
2497  if (!url)
2498  return 0;
2499 
2500  char tmp[PATH_MAX];
2501  char tmp2[PATH_MAX];
2502 
2503  imap_fix_path('\0', url->path, tmp, sizeof(tmp));
2504  url->path = tmp;
2505  url_tostring(url, tmp2, sizeof(tmp2), 0);
2506  mutt_str_strfcpy(buf, tmp2, buflen);
2507  url_free(&url);
2508 
2509  return 0;
2510 }
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
int url_tostring(struct Url *u, char *dest, size_t len, int flags)
Output the URL string for a given Url object.
Definition: url.c:399
#define PATH_MAX
Definition: mutt.h:50
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
char * imap_fix_path(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition: util.c:797
char * path
Path.
Definition: url.h:73
void url_free(struct Url **u)
Free the contents of a URL.
Definition: url.c:288
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:161
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_browse()

int imap_browse ( const char *  path,
struct BrowserState state 
)

IMAP hook into the folder browser.

Parameters
pathCurrent folder
stateBrowserState to populate
Return values
0Success
-1Failure

Fill out browser_state, given a current folder to browse

Definition at line 184 of file browse.c.

185 {
186  struct ImapAccountData *adata = NULL;
187  struct ImapList list;
188  struct ConnAccount conn_account;
189  char buf[PATH_MAX + 16];
190  char mbox[PATH_MAX];
191  char munged_mbox[PATH_MAX];
192  const char *list_cmd = NULL;
193  int len;
194  int n;
195  char ctmp;
196  bool showparents = false;
197  bool save_lsub;
198 
199  if (imap_parse_path(path, &conn_account, buf, sizeof(buf)))
200  {
201  mutt_error(_("%s is an invalid IMAP path"), path);
202  return -1;
203  }
204 
205  save_lsub = C_ImapCheckSubscribed;
206  C_ImapCheckSubscribed = false;
207 
208  // Pick first mailbox connected to the same server
209  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_IMAP);
210  struct MailboxNode *np = NULL;
211  STAILQ_FOREACH(np, &ml, entries)
212  {
213  adata = imap_adata_get(np->mailbox);
214  // Pick first mailbox connected on the same server
215  if (imap_account_match(&adata->conn_account, &conn_account))
216  break;
217  adata = NULL;
218  }
220  if (!adata)
221  goto fail;
222 
224  {
225  /* RFC3348 section 3 states LSUB is unreliable for hierarchy information.
226  * The newer LIST extensions are designed for this. */
228  list_cmd = "LIST (SUBSCRIBED RECURSIVEMATCH)";
229  else
230  list_cmd = "LSUB";
231  }
232  else
233  {
234  list_cmd = "LIST";
235  }
236 
237  mutt_message(_("Getting folder list..."));
238 
239  /* skip check for parents when at the root */
240  if (buf[0] == '\0')
241  {
242  mbox[0] = '\0';
243  n = 0;
244  }
245  else
246  {
247  imap_fix_path(adata->delim, buf, mbox, sizeof(mbox));
248  n = mutt_str_strlen(mbox);
249  }
250 
251  if (n)
252  {
253  int rc;
254  mutt_debug(LL_DEBUG3, "mbox: %s\n", mbox);
255 
256  /* if our target exists and has inferiors, enter it if we
257  * aren't already going to */
258  imap_munge_mbox_name(adata->unicode, munged_mbox, sizeof(munged_mbox), mbox);
259  len = snprintf(buf, sizeof(buf), "%s \"\" %s", list_cmd, munged_mbox);
261  snprintf(buf + len, sizeof(buf) - len, " RETURN (CHILDREN)");
262  imap_cmd_start(adata, buf);
263  adata->cmdresult = &list;
264  do
265  {
266  list.name = 0;
267  rc = imap_cmd_step(adata);
268  if ((rc == IMAP_RES_CONTINUE) && list.name)
269  {
270  if (!list.noinferiors && list.name[0] &&
271  (imap_mxcmp(list.name, mbox) == 0) && (n < sizeof(mbox) - 1))
272  {
273  mbox[n++] = list.delim;
274  mbox[n] = '\0';
275  }
276  }
277  } while (rc == IMAP_RES_CONTINUE);
278  adata->cmdresult = NULL;
279 
280  /* if we're descending a folder, mark it as current in browser_state */
281  if (mbox[n - 1] == list.delim)
282  {
283  showparents = true;
284  imap_qualify_path(buf, sizeof(buf), &conn_account, mbox);
285  state->folder = mutt_str_strdup(buf);
286  n--;
287  }
288 
289  /* Find superiors to list
290  * Note: UW-IMAP servers return folder + delimiter when asked to list
291  * folder + delimiter. Cyrus servers don't. So we ask for folder,
292  * and tack on delimiter ourselves.
293  * Further note: UW-IMAP servers return nothing when asked for
294  * NAMESPACES without delimiters at the end. Argh! */
295  for (n--; n >= 0 && mbox[n] != list.delim; n--)
296  ;
297  if (n > 0) /* "aaaa/bbbb/" -> "aaaa" */
298  {
299  /* forget the check, it is too delicate (see above). Have we ever
300  * had the parent not exist? */
301  ctmp = mbox[n];
302  mbox[n] = '\0';
303 
304  if (showparents)
305  {
306  mutt_debug(LL_DEBUG3, "adding parent %s\n", mbox);
307  add_folder(list.delim, mbox, true, false, state, true);
308  }
309 
310  /* if our target isn't a folder, we are in our superior */
311  if (!state->folder)
312  {
313  /* store folder with delimiter */
314  mbox[n++] = ctmp;
315  ctmp = mbox[n];
316  mbox[n] = '\0';
317  imap_qualify_path(buf, sizeof(buf), &conn_account, mbox);
318  state->folder = mutt_str_strdup(buf);
319  }
320  mbox[n] = ctmp;
321  }
322  /* "/bbbb/" -> add "/", "aaaa/" -> add "" */
323  else
324  {
325  char relpath[2];
326  /* folder may be "/" */
327  snprintf(relpath, sizeof(relpath), "%c", (n < 0) ? '\0' : adata->delim);
328  if (showparents)
329  add_folder(adata->delim, relpath, true, false, state, true);
330  if (!state->folder)
331  {
332  imap_qualify_path(buf, sizeof(buf), &conn_account, relpath);
333  state->folder = mutt_str_strdup(buf);
334  }
335  }
336  }
337 
338  /* no namespace, no folder: set folder to host only */
339  if (!state->folder)
340  {
341  imap_qualify_path(buf, sizeof(buf), &conn_account, NULL);
342  state->folder = mutt_str_strdup(buf);
343  }
344 
345  mutt_debug(LL_DEBUG3, "Quoting mailbox scan: %s -> ", mbox);
346  snprintf(buf, sizeof(buf), "%s%%", mbox);
347  imap_munge_mbox_name(adata->unicode, munged_mbox, sizeof(munged_mbox), buf);
348  mutt_debug(LL_DEBUG3, "%s\n", munged_mbox);
349  len = snprintf(buf, sizeof(buf), "%s \"\" %s", list_cmd, munged_mbox);
351  snprintf(buf + len, sizeof(buf) - len, " RETURN (CHILDREN)");
352  if (browse_add_list_result(adata, buf, state, false))
353  goto fail;
354 
355  if (state->entrylen == 0)
356  {
357  mutt_error(_("No such folder"));
358  goto fail;
359  }
360 
362 
363  if (save_lsub)
364  C_ImapCheckSubscribed = true;
365 
366  return 0;
367 
368 fail:
369  if (save_lsub)
370  C_ImapCheckSubscribed = true;
371  return -1;
372 }
WHERE bool C_ImapListSubscribed
Config: (imap) When browsing a mailbox, only display subscribed folders.
Definition: globals.h:224
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1071
#define mutt_message(...)
Definition: logging.h:83
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:135
struct ConnAccount conn_account
Definition: imap_private.h:169
void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src)
Quote awkward characters in a mailbox name.
Definition: util.c:1033
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path)
Make an absolute IMAP folder target.
Definition: util.c:942
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
Items in an IMAP browser.
Definition: imap_private.h:144
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition: command.c:1057
Container for Accounts, Notifications.
Definition: neomutt.h:35
char * folder
Definition: browser.h:102
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition: util.c:1166
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType magic)
Get a List of all Mailboxes.
Definition: neomutt.c:157
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
#define IMAP_CAP_LIST_EXTENDED
RFC5258: IMAP4 LIST Command Extensions.
Definition: imap_private.h:136
int imap_parse_path(const char *path, struct ConnAccount *account, char *mailbox, size_t mailboxlen)
Parse an IMAP mailbox name into ConnAccount, name.
Definition: util.c:599
#define PATH_MAX
Definition: mutt.h:50
char * name
Definition: imap_private.h:146
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: util.c:115
WHERE bool C_ImapCheckSubscribed
Config: (imap) When opening a mailbox, ask the server for a list of subscribed folders.
Definition: globals.h:222
char * imap_fix_path(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition: util.c:797
ImapCapFlags capabilities
Definition: imap_private.h:183
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
Login details for a remote server.
Definition: connaccount.h:31
size_t entrylen
number of real entries
Definition: browser.h:98
#define IMAP_RES_CONTINUE
* ...
Definition: imap_private.h:55
IMAP-specific Account data -.
Definition: imap_private.h:166
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define mutt_error(...)
Definition: logging.h:84
static int browse_add_list_result(struct ImapAccountData *adata, const char *cmd, struct BrowserState *state, bool isparent)
Add entries to the folder browser.
Definition: browse.c:144
int imap_mxcmp(const char *mx1, const char *mx2)
Compare mailbox names, giving priority to INBOX.
Definition: util.c:669
struct ImapList * cmdresult
Definition: imap_private.h:195
List of Mailboxes.
Definition: mailbox.h:144
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
static void add_folder(char delim, char *folder, bool noselect, bool noinferiors, struct BrowserState *state, bool isparent)
Format and add an IMAP folder to the browser.
Definition: browse.c:60
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:52
Log at debug level 3.
Definition: logging.h:42
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:146
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_mailbox_create()

int imap_mailbox_create ( const char *  path)

Create a new IMAP mailbox.

Parameters
pathMailbox to create
Return values
0Success
-1Failure

Prompt for a new mailbox name, and try to create it

Definition at line 382 of file browse.c.

383 {
384  struct ImapAccountData *adata = NULL;
385  struct ImapMboxData *mdata = NULL;
386  char name[1024];
387  short n;
388 
389  if (imap_adata_find(path, &adata, &mdata) < 0)
390  {
391  mutt_debug(LL_DEBUG1, "Couldn't find open connection to %s\n", path);
392  goto err;
393  }
394 
395  /* append a delimiter if necessary */
396  mutt_str_strfcpy(name, mdata->real_name, sizeof(name));
397  n = mutt_str_strlen(name);
398  if (n && (n < sizeof(name) - 1) && (name[n - 1] != adata->delim))
399  {
400  name[n++] = adata->delim;
401  name[n] = '\0';
402  }
403 
404  if (mutt_get_field(_("Create mailbox: "), name, sizeof(name), MUTT_FILE) < 0)
405  goto err;
406 
407  if (mutt_str_strlen(name) == 0)
408  {
409  mutt_error(_("Mailbox must have a name"));
410  goto err;
411  }
412 
413  if (imap_create_mailbox(adata, name) < 0)
414  goto err;
415 
416  imap_mdata_free((void *) &mdata);
417  mutt_message(_("Mailbox created"));
418  mutt_sleep(0);
419  return 0;
420 
421 err:
422  imap_mdata_free((void *) &mdata);
423  return -1;
424 }
#define mutt_message(...)
Definition: logging.h:83
void imap_mdata_free(void **ptr)
Release and clear storage in an ImapMboxData structure.
Definition: util.c:227
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:92
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1545
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:130
const char * name
Definition: pgpmicalg.c:46
void * mdata
Driver specific data.
Definition: mailbox.h:135
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
int imap_create_mailbox(struct ImapAccountData *adata, char *mailbox)
Create a new mailbox.
Definition: imap.c:575
#define MUTT_FILE
Do file completion.
Definition: mutt.h:64
char * real_name
Original Mailbox name, e.g.: INBOX can be just \0.
Definition: imap_private.h:217
IMAP-specific Account data -.
Definition: imap_private.h:166
Log at debug level 1.
Definition: logging.h:40
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
#define mutt_error(...)
Definition: logging.h:84
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_mailbox_rename()

int imap_mailbox_rename ( const char *  path)

Rename a mailbox.

Parameters
pathMailbox to rename
Return values
0Success
-1Failure

The user will be prompted for a new name.

Definition at line 434 of file browse.c.

435 {
436  struct ImapAccountData *adata = NULL;
437  struct ImapMboxData *mdata = NULL;
438  char buf[PATH_MAX];
439  char newname[PATH_MAX];
440 
441  if (imap_adata_find(path, &adata, &mdata) < 0)
442  {
443  mutt_debug(LL_DEBUG1, "Couldn't find open connection to %s\n", path);
444  return -1;
445  }
446 
447  if (mdata->real_name[0] == '\0')
448  {
449  mutt_error(_("Can't rename root folder"));
450  goto err;
451  }
452 
453  snprintf(buf, sizeof(buf), _("Rename mailbox %s to: "), mdata->name);
454  mutt_str_strfcpy(newname, mdata->name, sizeof(newname));
455 
456  if (mutt_get_field(buf, newname, sizeof(newname), MUTT_FILE) < 0)
457  goto err;
458 
459  if (mutt_str_strlen(newname) == 0)
460  {
461  mutt_error(_("Mailbox must have a name"));
462  goto err;
463  }
464 
465  imap_fix_path(adata->delim, newname, buf, sizeof(buf));
466 
467  if (imap_rename_mailbox(adata, mdata->name, buf) < 0)
468  {
469  mutt_error(_("Rename failed: %s"), imap_get_qualifier(adata->buf));
470  goto err;
471  }
472 
473  mutt_message(_("Mailbox renamed"));
474  mutt_sleep(0);
475  return 0;
476 
477 err:
478  imap_mdata_free((void *) &mdata);
479  return -1;
480 }
#define mutt_message(...)
Definition: logging.h:83
void imap_mdata_free(void **ptr)
Release and clear storage in an ImapMboxData structure.
Definition: util.c:227
int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char *newname)
Rename a mailbox.
Definition: imap.c:616
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:92
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1545
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:130
void * mdata
Driver specific data.
Definition: mailbox.h:135
#define PATH_MAX
Definition: mutt.h:50
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
char * name
Mailbox name.
Definition: imap_private.h:215
char * imap_fix_path(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition: util.c:797
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
Definition: util.c:894
#define MUTT_FILE
Do file completion.
Definition: mutt.h:64
char * real_name
Original Mailbox name, e.g.: INBOX can be just \0.
Definition: imap_private.h:217
IMAP-specific Account data -.
Definition: imap_private.h:166
Log at debug level 1.
Definition: logging.h:40
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
#define mutt_error(...)
Definition: logging.h:84
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_copy_messages()

int imap_copy_messages ( struct Mailbox m,
struct EmailList *  el,
const char *  dest,
bool  delete_original 
)

Server COPY messages to another folder.

Parameters
mMailbox
elList of Emails to copy
destDestination folder
delete_originalDelete the original?
Return values
-1Error
0Success
1Non-fatal error - try fetch/append

Definition at line 1587 of file message.c.

1588 {
1589  if (!m || !el || !dest)
1590  return -1;
1591 
1592  struct Buffer cmd, sync_cmd;
1593  char buf[PATH_MAX];
1594  char mbox[PATH_MAX];
1595  char mmbox[PATH_MAX];
1596  char prompt[PATH_MAX + 64];
1597  int rc;
1598  struct ConnAccount conn_account;
1599  enum QuadOption err_continue = MUTT_NO;
1600  int triedcreate = 0;
1601  struct EmailNode *en = STAILQ_FIRST(el);
1602  bool single = !STAILQ_NEXT(en, entries);
1603  struct ImapAccountData *adata = imap_adata_get(m);
1604 
1605  if (single && en->email->attach_del)
1606  {
1607  mutt_debug(LL_DEBUG3, "#1 Message contains attachments to be deleted\n");
1608  return 1;
1609  }
1610 
1611  if (imap_parse_path(dest, &conn_account, buf, sizeof(buf)))
1612  {
1613  mutt_debug(LL_DEBUG1, "bad destination %s\n", dest);
1614  return -1;
1615  }
1616 
1617  /* check that the save-to folder is in the same account */
1618  if (!mutt_account_match(&adata->conn->account, &conn_account))
1619  {
1620  mutt_debug(LL_DEBUG3, "%s not same server as %s\n", dest, mailbox_path(m));
1621  return 1;
1622  }
1623 
1624  imap_fix_path(adata->delim, buf, mbox, sizeof(mbox));
1625  if (!*mbox)
1626  mutt_str_strfcpy(mbox, "INBOX", sizeof(mbox));
1627  imap_munge_mbox_name(adata->unicode, mmbox, sizeof(mmbox), mbox);
1628 
1629  /* loop in case of TRYCREATE */
1630  do
1631  {
1632  mutt_buffer_init(&sync_cmd);
1633  mutt_buffer_init(&cmd);
1634 
1635  if (!single) /* copy tagged messages */
1636  {
1637  /* if any messages have attachments to delete, fall through to FETCH
1638  * and APPEND. TODO: Copy what we can with COPY, fall through for the
1639  * remainder. */
1640  STAILQ_FOREACH(en, el, entries)
1641  {
1642  if (en->email->attach_del)
1643  {
1645  "#2 Message contains attachments to be deleted\n");
1646  return 1;
1647  }
1648 
1649  if (en->email->active && en->email->changed)
1650  {
1651  rc = imap_sync_message_for_copy(m, en->email, &sync_cmd, &err_continue);
1652  if (rc < 0)
1653  {
1654  mutt_debug(LL_DEBUG1, "#1 could not sync\n");
1655  goto out;
1656  }
1657  }
1658  }
1659 
1660  rc = imap_exec_msgset(m, "UID COPY", mmbox, MUTT_TAG, false, false);
1661  if (rc == 0)
1662  {
1663  mutt_debug(LL_DEBUG1, "No messages tagged\n");
1664  rc = -1;
1665  goto out;
1666  }
1667  else if (rc < 0)
1668  {
1669  mutt_debug(LL_DEBUG1, "#1 could not queue copy\n");
1670  goto out;
1671  }
1672  else
1673  {
1674  mutt_message(ngettext("Copying %d message to %s...", "Copying %d messages to %s...", rc),
1675  rc, mbox);
1676  }
1677  }
1678  else
1679  {
1680  mutt_message(_("Copying message %d to %s..."), en->email->index + 1, mbox);
1681  mutt_buffer_add_printf(&cmd, "UID COPY %u %s", imap_edata_get(en->email)->uid, mmbox);
1682 
1683  if (en->email->active && en->email->changed)
1684  {
1685  rc = imap_sync_message_for_copy(m, en->email, &sync_cmd, &err_continue);
1686  if (rc < 0)
1687  {
1688  mutt_debug(LL_DEBUG1, "#2 could not sync\n");
1689  goto out;
1690  }
1691  }
1692  rc = imap_exec(adata, cmd.data, IMAP_CMD_QUEUE);
1693  if (rc != IMAP_EXEC_SUCCESS)
1694  {
1695  mutt_debug(LL_DEBUG1, "#2 could not queue copy\n");
1696  goto out;
1697  }
1698  }
1699 
1700  /* let's get it on */
1701  rc = imap_exec(adata, NULL, IMAP_CMD_NO_FLAGS);
1702  if (rc == IMAP_EXEC_ERROR)
1703  {
1704  if (triedcreate)
1705  {
1706  mutt_debug(LL_DEBUG1, "Already tried to create mailbox %s\n", mbox);
1707  break;
1708  }
1709  /* bail out if command failed for reasons other than nonexistent target */
1710  if (!mutt_str_startswith(imap_get_qualifier(adata->buf), "[TRYCREATE]", CASE_IGNORE))
1711  break;
1712  mutt_debug(LL_DEBUG3, "server suggests TRYCREATE\n");
1713  snprintf(prompt, sizeof(prompt), _("Create %s?"), mbox);
1714  if (C_Confirmcreate && (mutt_yesorno(prompt, MUTT_YES) != MUTT_YES))
1715  {
1716  mutt_clear_error();
1717  goto out;
1718  }
1719  if (imap_create_mailbox(adata, mbox) < 0)
1720  break;
1721  triedcreate = 1;
1722  }
1723  } while (rc == IMAP_EXEC_ERROR);
1724 
1725  if (rc != 0)
1726  {
1727  imap_error("imap_copy_messages", adata->buf);
1728  goto out;
1729  }
1730 
1731  /* cleanup */
1732  if (delete_original)
1733  {
1734  STAILQ_FOREACH(en, el, entries)
1735  {
1736  mutt_set_flag(m, en->email, MUTT_DELETE, true);
1737  mutt_set_flag(m, en->email, MUTT_PURGE, true);
1738  if (C_DeleteUntag)
1739  mutt_set_flag(m, en->email, MUTT_TAG, false);
1740  }
1741  }
1742 
1743  rc = 0;
1744 
1745 out:
1746  FREE(&cmd.data);
1747  FREE(&sync_cmd.data);
1748 
1749  return (rc < 0) ? -1 : rc;
1750 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition: message.c:100
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:70
struct ConnAccount account
Definition: connection.h:36
#define mutt_message(...)
Definition: logging.h:83
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
struct ConnAccount conn_account
Definition: imap_private.h:169
bool attach_del
Has an attachment marked for deletion.
Definition: email.h:49
void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src)
Quote awkward characters in a mailbox name.
Definition: util.c:1033
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
bool changed
Email has been edited.
Definition: email.h:48
Messages to be purged (bypass trash)
Definition: mutt.h:104
WHERE bool C_Confirmcreate
Config: Confirm before creating a new mailbox.
Definition: globals.h:208
Imap command executed or queued successfully.
Definition: imap_private.h:81
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: curs_lib.c:376
int imap_exec_msgset(struct Mailbox *m, const char *pre, const char *post, int flag, bool changed, bool invert)
Prepare commands for all messages matching conditions.
Definition: imap.c:1010
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:203
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1241
int imap_sync_message_for_copy(struct Mailbox *m, struct Email *e, struct Buffer *cmd, enum QuadOption *err_continue)
Update server to reflect the flags of a single message.
Definition: imap.c:1088
bool active
Message is not to be removed.
Definition: email.h:59
int imap_parse_path(const char *path, struct ConnAccount *account, char *mailbox, size_t mailboxlen)
Parse an IMAP mailbox name into ConnAccount, name.
Definition: util.c:599
unsigned int uid
32-bit Message UID
Definition: message.h:44
Messages to be deleted.
Definition: mutt.h:102
#define PATH_MAX
Definition: mutt.h:50
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:39
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
void imap_error(const char *where, const char *msg)
show an error and abort
Definition: util.c:778
Tagged messages.
Definition: mutt.h:107
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare account info (host/port/user)
Definition: mutt_account.c:61
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: util.c:115
Ignore case when comparing strings.
Definition: string2.h:68
char * imap_fix_path(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition: util.c:797
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
Definition: util.c:894
int imap_create_mailbox(struct ImapAccountData *adata, char *mailbox)
Create a new mailbox.
Definition: imap.c:575
Login details for a remote server.
Definition: connaccount.h:31
#define STAILQ_NEXT(elm, field)
Definition: queue.h:397
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
WHERE bool C_DeleteUntag
Config: Untag messages when they are marked for deletion.
Definition: globals.h:209
IMAP-specific Account data -.
Definition: imap_private.h:166
Log at debug level 1.
Definition: logging.h:40
struct Email * email
Email in the list.
Definition: email.h:116
#define IMAP_CMD_QUEUE
Queue a command, do not execute.
Definition: imap_private.h:73
int index
The absolute (unsorted) message number.
Definition: email.h:85
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition: imap_private.h:71
#define FREE(x)
Definition: memory.h:40
List of Emails.
Definition: email.h:114
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
#define STAILQ_FIRST(head)
Definition: queue.h:347
Log at debug level 3.
Definition: logging.h:42
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
struct Connection * conn
Definition: imap_private.h:168
Imap command failure.
Definition: imap_private.h:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_logout_all()

void imap_logout_all ( void  )

close all open connections

Quick and dirty until we can make sure we've got all the context we need.

Definition at line 688 of file imap.c.

689 {
690  struct Account *np = NULL;
691  TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
692  {
693  if (np->magic != MUTT_IMAP)
694  continue;
695 
696  struct ImapAccountData *adata = np->adata;
697  if (!adata)
698  continue;
699 
700  struct Connection *conn = adata->conn;
701  if (!conn || (conn->fd < 0))
702  continue;
703 
704  mutt_message(_("Closing connection to %s..."), conn->account.host);
705  imap_logout(np->adata);
707  }
708 }
struct ConnAccount account
Definition: connection.h:36
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
#define mutt_message(...)
Definition: logging.h:83
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:39
A group of associated Mailboxes.
Definition: account.h:36
An open network connection (socket)
Definition: connection.h:34
static void imap_logout(struct ImapAccountData *adata)
Gracefully log out of server.
Definition: imap.c:663
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:35
char host[128]
Definition: connaccount.h:36
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
enum MailboxType magic
Type of Mailboxes this Account contains.
Definition: account.h:38
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
IMAP-specific Account data -.
Definition: imap_private.h:166
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:52
struct Connection * conn
Definition: imap_private.h:168
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_expand_path()

int imap_expand_path ( struct Buffer buf)

Buffer wrapper around imap_path_canon()

Parameters
bufPath to expand
Return values
0Success
-1Failure
Note
The path is expanded in place

Definition at line 2520 of file imap.c.

2521 {
2523  return imap_path_canon(buf->data, PATH_MAX);
2524 }
#define PATH_MAX
Definition: mutt.h:50
char * data
Pointer to data.
Definition: buffer.h:35
int imap_path_canon(char *buf, size_t buflen)
Canonicalise a Mailbox path - Implements MxOps::path_canon()
Definition: imap.c:2491
void mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:265
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_parse_path()

int imap_parse_path ( const char *  path,
struct ConnAccount account,
char *  mailbox,
size_t  mailboxlen 
)

Parse an IMAP mailbox name into ConnAccount, name.

Parameters
pathMailbox path to parse
accountAccount credentials
mailboxBuffer for mailbox name
mailboxlenLength of buffer
Return values
0Success
-1Failure

Given an IMAP mailbox name, return host, port and a path IMAP servers will recognize. mx.mbox is malloc'd, caller must free it

Definition at line 599 of file util.c.

600 {
601  static unsigned short ImapPort = 0;
602  static unsigned short ImapsPort = 0;
603  struct servent *service = NULL;
604 
605  if (ImapPort == 0)
606  {
607  service = getservbyname("imap", "tcp");
608  if (service)
609  ImapPort = ntohs(service->s_port);
610  else
611  ImapPort = IMAP_PORT;
612  mutt_debug(LL_DEBUG3, "Using default IMAP port %d\n", ImapPort);
613  }
614  if (ImapsPort == 0)
615  {
616  service = getservbyname("imaps", "tcp");
617  if (service)
618  ImapsPort = ntohs(service->s_port);
619  else
620  ImapsPort = IMAP_SSL_PORT;
621  mutt_debug(LL_DEBUG3, "Using default IMAPS port %d\n", ImapsPort);
622  }
623 
624  /* Defaults */
625  memset(account, 0, sizeof(struct ConnAccount));
626  account->port = ImapPort;
627  account->type = MUTT_ACCT_TYPE_IMAP;
628 
629  struct Url *url = url_parse(path);
630  if (!url)
631  return -1;
632 
633  if ((url->scheme != U_IMAP) && (url->scheme != U_IMAPS))
634  {
635  url_free(&url);
636  return -1;
637  }
638 
639  if ((mutt_account_fromurl(account, url) < 0) || (account->host[0] == '\0'))
640  {
641  url_free(&url);
642  return -1;
643  }
644 
645  if (url->scheme == U_IMAPS)
646  account->flags |= MUTT_ACCT_SSL;
647 
648  mutt_str_strfcpy(mailbox, url->path, mailboxlen);
649 
650  url_free(&url);
651 
652  if ((account->flags & MUTT_ACCT_SSL) && !(account->flags & MUTT_ACCT_PORT))
653  account->port = ImapsPort;
654 
655  return 0;
656 }
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition: url.h:68
#define IMAP_SSL_PORT
Port for IMAP over SSL/TLS.
Definition: imap_private.h:44
Url is imaps://.
Definition: url.h:39
#define IMAP_PORT
Default port for IMAP.
Definition: imap_private.h:43
Url is imap://.
Definition: url.h:38
char host[128]
Definition: connaccount.h:36
unsigned short port
Definition: connaccount.h:37
#define MUTT_ACCT_PORT
Port field has been set.
Definition: mutt_account.h:60
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition: connaccount.h:38
Login details for a remote server.
Definition: connaccount.h:31
Imap Account.
Definition: mutt_account.h:52
char * path
Path.
Definition: url.h:73
void url_free(struct Url **u)
Free the contents of a URL.
Definition: url.c:288
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition: mutt_account.h:64
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
int mutt_account_fromurl(struct ConnAccount *account, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:109
Log at debug level 3.
Definition: logging.h:42
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:39
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:161
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_pretty_mailbox()

void imap_pretty_mailbox ( char *  path,
size_t  pathlen,
const char *  folder 
)

Prettify an IMAP mailbox name.

Parameters
pathMailbox name to be tidied
pathlenLength of path
folderPath to use for '+' abbreviations

Called by mutt_pretty_mailbox() to make IMAP paths look nice.

Definition at line 706 of file util.c.

707 {
708  struct ConnAccount target_conn_account, home_conn_account;
709  struct Url url;
710  char *delim = NULL;
711  int tlen;
712  int hlen = 0;
713  bool home_match = false;
714  char target_mailbox[1024];
715  char home_mailbox[1024];
716 
717  if (imap_parse_path(path, &target_conn_account, target_mailbox, sizeof(target_mailbox)) < 0)
718  return;
719 
720  if (imap_path_probe(folder, NULL) != MUTT_IMAP)
721  goto fallback;
722 
723  if (imap_parse_path(folder, &home_conn_account, home_mailbox, sizeof(home_mailbox)) < 0)
724  goto fallback;
725 
726  tlen = mutt_str_strlen(target_mailbox);
727  hlen = mutt_str_strlen(home_mailbox);
728 
729  /* check whether we can do '+' substitution */
730  if (tlen && mutt_account_match(&home_conn_account, &target_conn_account) &&
731  (mutt_str_strncmp(home_mailbox, target_mailbox, hlen) == 0))
732  {
733  if (hlen == 0)
734  home_match = true;
735  else if (C_ImapDelimChars)
736  {
737  for (delim = C_ImapDelimChars; *delim != '\0'; delim++)
738  if (target_mailbox[hlen] == *delim)
739  home_match = true;
740  }
741  }
742 
743  /* do the '+' substitution */
744  if (home_match)
745  {
746  *path++ = '+';
747  /* copy remaining path, skipping delimiter */
748  if (hlen == 0)
749  hlen = -1;
750  memcpy(path, target_mailbox + hlen + 1, tlen - hlen - 1);
751  path[tlen - hlen - 1] = '\0';
752  return;
753  }
754 
755 fallback:
756  mutt_account_tourl(&target_conn_account, &url);
757  url.path = target_mailbox;
758  url_tostring(&url, path, pathlen, 0);
759 }
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe()
Definition: imap.c:2474
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
char * C_ImapDelimChars
Config: (imap) Characters that denote separators in IMAP folders.
Definition: util.c:62
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
int url_tostring(struct Url *u, char *dest, size_t len, int flags)
Output the URL string for a given Url object.
Definition: url.c:399
bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare account info (host/port/user)
Definition: mutt_account.c:61
Login details for a remote server.
Definition: connaccount.h:31
char * path
Path.
Definition: url.h:73
int mutt_str_strncmp(const char *a, const char *b, size_t l)
Compare two strings (to a maximum), safely.
Definition: string.c:642
void mutt_account_tourl(struct ConnAccount *account, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:145
int imap_parse_path(const char *path, struct ConnAccount *account, char *mailbox, size_t mailboxlen)
Parse an IMAP mailbox name into ConnAccount, name.
Definition: util.c:599
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_wait_keepalive()

int imap_wait_keepalive ( pid_t  pid)

Wait for a process to change state.

Parameters
pidProcess ID to listen to
Return values
num'wstatus' from waitpid()

Definition at line 1090 of file util.c.

1091 {
1092  struct sigaction oldalrm;
1093  struct sigaction act;
1094  sigset_t oldmask;
1095  int rc;
1096 
1097  bool imap_passive = C_ImapPassive;
1098 
1099  C_ImapPassive = true;
1100  OptKeepQuiet = true;
1101 
1102  sigprocmask(SIG_SETMASK, NULL, &oldmask);
1103 
1104  sigemptyset(&act.sa_mask);
1105  act.sa_handler = mutt_sig_empty_handler;
1106 #ifdef SA_INTERRUPT
1107  act.sa_flags = SA_INTERRUPT;
1108 #else
1109  act.sa_flags = 0;
1110 #endif
1111 
1112  sigaction(SIGALRM, &act, &oldalrm);
1113 
1114  alarm(C_ImapKeepalive);
1115  while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
1116  {
1117  alarm(0); /* cancel a possibly pending alarm */
1118  imap_keepalive();
1119  alarm(C_ImapKeepalive);
1120  }
1121 
1122  alarm(0); /* cancel a possibly pending alarm */
1123 
1124  sigaction(SIGALRM, &oldalrm, NULL);
1125  sigprocmask(SIG_SETMASK, &oldmask, NULL);
1126 
1127  OptKeepQuiet = false;
1128  if (!imap_passive)
1129  C_ImapPassive = false;
1130 
1131  return rc;
1132 }
void mutt_sig_empty_handler(int sig)
Dummy signal handler.
Definition: signal.c:57
WHERE short C_ImapKeepalive
Config: (imap) Time to wait before polling an open IMAP connection.
Definition: globals.h:155
WHERE bool C_ImapPassive
Config: (imap) Reuse an existing IMAP connection to check for new mail.
Definition: globals.h:225
void imap_keepalive(void)
poll the current folder to keep the connection alive
Definition: util.c:1067
WHERE bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program ...
Definition: options.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_keepalive()

void imap_keepalive ( void  )

poll the current folder to keep the connection alive

Definition at line 1067 of file util.c.

1068 {
1069  time_t now = mutt_date_epoch();
1070  struct Account *np = NULL;
1071  TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
1072  {
1073  if (np->magic != MUTT_IMAP)
1074  continue;
1075 
1076  struct ImapAccountData *adata = np->adata;
1077  if (!adata || !adata->mailbox)
1078  continue;
1079 
1080  if ((adata->state >= IMAP_AUTHENTICATED) && (now >= (adata->lastread + C_ImapKeepalive)))
1081  imap_check_mailbox(adata->mailbox, true);
1082  }
1083 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:411
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:39
unsigned char state
ImapState, e.g. IMAP_AUTHENTICATED.
Definition: imap_private.h:172
A group of associated Mailboxes.
Definition: account.h:36
struct Mailbox * mailbox
Definition: imap_private.h:205
Container for Accounts, Notifications.
Definition: neomutt.h:35
WHERE short C_ImapKeepalive
Config: (imap) Time to wait before polling an open IMAP connection.
Definition: globals.h:155
enum MailboxType magic
Type of Mailboxes this Account contains.
Definition: account.h:38
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
Connection is authenticated.
Definition: imap_private.h:106
time_t lastread
last time we read a command for the server
Definition: imap_private.h:186
int imap_check_mailbox(struct Mailbox *m, bool force)
use the NOOP or IDLE command to poll for new mail
Definition: imap.c:1190
IMAP-specific Account data -.
Definition: imap_private.h:166
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_get_parent_path()

void imap_get_parent_path ( const char *  path,
char *  buf,
size_t  buflen 
)

Get the path of the parent folder.

Parameters
pathMailbox whose parent is to be determined
bufBuffer for the result
buflenLength of the buffer

Provided an imap path, returns in buf the parent directory if existent. Else returns the same path.

Definition at line 303 of file util.c.

304 {
305  struct ImapAccountData *adata = NULL;
306  struct ImapMboxData *mdata = NULL;
307  char mbox[1024];
308 
309  if (imap_adata_find(path, &adata, &mdata) < 0)
310  {
311  mutt_str_strfcpy(buf, path, buflen);
312  return;
313  }
314 
315  /* Gets the parent mbox in mbox */
316  imap_get_parent(mdata->name, adata->delim, mbox, sizeof(mbox));
317 
318  /* Returns a fully qualified IMAP url */
319  imap_qualify_path(buf, buflen, &adata->conn_account, mbox);
320  imap_mdata_free((void *) &mdata);
321 }
struct ConnAccount conn_account
Definition: imap_private.h:169
void imap_mdata_free(void **ptr)
Release and clear storage in an ImapMboxData structure.
Definition: util.c:227
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:130
void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen)
Get an IMAP folder&#39;s parent.
Definition: util.c:260
void * mdata
Driver specific data.
Definition: mailbox.h:135
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
char * name
Mailbox name.
Definition: imap_private.h:215
IMAP-specific Account data -.
Definition: imap_private.h:166
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path)
Make an absolute IMAP folder target.
Definition: util.c:942
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_clean_path()

void imap_clean_path ( char *  path,
size_t  plen 
)

Cleans an IMAP path using imap_fix_path.

Parameters
pathPath to be cleaned
plenLength of the buffer

Does it in place.

Definition at line 330 of file util.c.

331 {
332  struct ImapAccountData *adata = NULL;
333  struct ImapMboxData *mdata = NULL;
334 
335  if (imap_adata_find(path, &adata, &mdata) < 0)
336  return;
337 
338  /* Returns a fully qualified IMAP url */
339  imap_qualify_path(path, plen, &adata->conn_account, mdata->name);
340  imap_mdata_free((void *) &mdata);
341 }
struct ConnAccount conn_account
Definition: imap_private.h:169
static size_t plen
Length of cached packet.
Definition: pgppacket.c:39
void imap_mdata_free(void **ptr)
Release and clear storage in an ImapMboxData structure.
Definition: util.c:227
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:130
void * mdata
Driver specific data.
Definition: mailbox.h:135
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
char * name
Mailbox name.
Definition: imap_private.h:215
IMAP-specific Account data -.
Definition: imap_private.h:166
IMAP-specific Mailbox data -.
Definition: imap_private.h:213
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path)
Make an absolute IMAP folder target.
Definition: util.c:942
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_ImapAuthenticators

struct Slist* C_ImapAuthenticators

Config: (imap) List of allowed IMAP authentication methods.

Definition at line 38 of file auth.c.

◆ C_ImapIdle

bool C_ImapIdle

Config: (imap) Use the IMAP IDLE extension to check for new mail.

Definition at line 64 of file imap.c.

◆ C_ImapRfc5161

bool C_ImapRfc5161

Config: (imap) Use the IMAP ENABLE extension to select capabilities.

Definition at line 68 of file imap.c.

◆ C_ImapHeaders

char* C_ImapHeaders

Config: (imap) Additional email headers to download when getting index.

Definition at line 64 of file message.c.

◆ C_ImapFetchChunkSize

long C_ImapFetchChunkSize

Config: (imap) Download headers in blocks of this size.

Definition at line 68 of file message.c.

◆ C_ImapServernoise

bool C_ImapServernoise

Config: (imap) Display server warnings as error messages.

Definition at line 55 of file command.c.

◆ C_ImapDelimChars

char* C_ImapDelimChars

Config: (imap) Characters that denote separators in IMAP folders.

Definition at line 62 of file util.c.

◆ C_ImapPipelineDepth

short C_ImapPipelineDepth

Config: (imap) Number of IMAP commands that may be queued up.

Definition at line 63 of file util.c.

◆ MxImapOps

struct MxOps MxImapOps

IMAP Mailbox - Implements MxOps.

Definition at line 2554 of file imap.c.