NeoMutt  2020-06-26-89-g172cd3
Teaching an old dog new tricks
DOXYGEN
mx.h File Reference

API for mailboxes. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include "config/lib.h"
#include "core/lib.h"
+ Include dependency graph for mx.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Message
 A local copy of an email. More...
 
struct  MxOps
 The Mailbox API. More...
 

Macros

#define MUTT_OPEN_NO_FLAGS   0
 No flags are set. More...
 
#define MUTT_NOSORT   (1 << 0)
 Do not sort the mailbox after opening it. More...
 
#define MUTT_APPEND   (1 << 1)
 Open mailbox for appending messages. More...
 
#define MUTT_READONLY   (1 << 2)
 Open in read-only mode. More...
 
#define MUTT_QUIET   (1 << 3)
 Do not print any messages. More...
 
#define MUTT_NEWFOLDER   (1 << 4)
 Create a new folder - same as MUTT_APPEND,. More...
 
#define MUTT_PEEK   (1 << 5)
 Revert atime back after taking a look (if applicable) More...
 
#define MUTT_APPENDNEW   (1 << 6)
 Set in mx_open_mailbox_append if the mailbox doesn't exist. More...
 
#define MUTT_MSG_NO_FLAGS   0
 No flags are set. More...
 
#define MUTT_ADD_FROM   (1 << 0)
 add a From_ line More...
 
#define MUTT_SET_DRAFT   (1 << 1)
 set the message draft flag More...
 

Typedefs

typedef uint8_t OpenMailboxFlags
 Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT. More...
 
typedef uint8_t MsgOpenFlags
 Flags for mx_msg_open_new(), e.g. MUTT_ADD_FROM. More...
 

Enumerations

enum  MxCheckReturns { MUTT_NEW_MAIL = 1, MUTT_LOCKED, MUTT_REOPENED, MUTT_FLAGS }
 Return values from mx_mbox_check() More...
 

Functions

int mx_mbox_check (struct Mailbox *m)
 Check for new mail - Wrapper for MxOps::mbox_check() More...
 
int mx_mbox_check_stats (struct Mailbox *m, int flags)
 Check the statistics for a mailbox - Wrapper for MxOps::mbox_check_stats() More...
 
int mx_mbox_close (struct Context **ptr)
 Save changes and close mailbox. More...
 
struct Contextmx_mbox_open (struct Mailbox *m, OpenMailboxFlags flags)
 Open a mailbox and parse it. More...
 
int mx_mbox_sync (struct Mailbox *m)
 Save changes to mailbox. More...
 
int mx_msg_close (struct Mailbox *m, struct Message **msg)
 Close a message. More...
 
int mx_msg_commit (struct Mailbox *m, struct Message *msg)
 Commit a message to a folder - Wrapper for MxOps::msg_commit() More...
 
struct Messagemx_msg_open_new (struct Mailbox *m, struct Email *e, MsgOpenFlags flags)
 Open a new message. More...
 
struct Messagemx_msg_open (struct Mailbox *m, int msgno)
 return a stream pointer for a message More...
 
int mx_msg_padding_size (struct Mailbox *m)
 Bytes of padding between messages - Wrapper for MxOps::msg_padding_size() More...
 
int mx_save_hcache (struct Mailbox *m, struct Email *e)
 Save message to the header cache - Wrapper for MxOps::msg_save_hcache() More...
 
int mx_path_canon (char *buf, size_t buflen, const char *folder, enum MailboxType *type)
 Canonicalise a mailbox path - Wrapper for MxOps::path_canon() More...
 
int mx_path_canon2 (struct Mailbox *m, const char *folder)
 Canonicalise the path to realpath. More...
 
int mx_path_parent (char *buf, size_t buflen)
 Find the parent of a mailbox path - Wrapper for MxOps::path_parent() More...
 
int mx_path_pretty (char *buf, size_t buflen, const char *folder)
 Abbreviate a mailbox path - Wrapper for MxOps::path_pretty() More...
 
enum MailboxType mx_path_probe (const char *path)
 Find a mailbox that understands a path. More...
 
struct Mailboxmx_path_resolve (const char *path)
 Get a Mailbox for a path. More...
 
struct Mailboxmx_resolve (const char *path_or_name)
 Get a Mailbox from either a path or name. More...
 
int mx_tags_commit (struct Mailbox *m, struct Email *e, char *tags)
 Save tags to the Mailbox - Wrapper for MxOps::tags_commit() More...
 
int mx_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen)
 start the tag editor of the mailbox More...
 
struct Accountmx_ac_find (struct Mailbox *m)
 Find the Account owning a Mailbox. More...
 
struct Mailboxmx_mbox_find (struct Account *a, const char *path)
 Find a Mailbox on an Account. More...
 
struct Mailboxmx_mbox_find2 (const char *path)
 Find a Mailbox on an Account. More...
 
int mx_ac_add (struct Account *a, struct Mailbox *m)
 Add a Mailbox to an Account - Wrapper for MxOps::ac_add() More...
 
int mx_ac_remove (struct Mailbox *m)
 Remove a Mailbox from an Account and delete Account if empty. More...
 
int mx_access (const char *path, int flags)
 Wrapper for access, checks permissions on a given mailbox. More...
 
void mx_alloc_memory (struct Mailbox *m)
 Create storage for the emails. More...
 
int mx_check_empty (const char *path)
 Is the mailbox empty. More...
 
void mx_fastclose_mailbox (struct Mailbox *m)
 free up memory associated with the Mailbox More...
 
const struct MxOpsmx_get_ops (enum MailboxType type)
 Get mailbox operations. More...
 
bool mx_tags_is_supported (struct Mailbox *m)
 return true if mailbox support tagging More...
 

Variables

const struct MxOpsmx_ops []
 All the Mailbox backends. More...
 
unsigned char C_CatchupNewsgroup
 Config: (nntp) Mark all articles as read when leaving a newsgroup. More...
 
bool C_KeepFlagged
 Config: Don't move flagged messages from C_Spoolfile to C_Mbox. More...
 
unsigned char C_MboxType
 Config: Default type for creating new mailboxes. More...
 
unsigned char C_Move
 Config: Move emails from C_Spoolfile to C_Mbox when read. More...
 
char * C_Trash
 Config: Folder to put deleted emails. More...
 
struct EnumDef MboxTypeDef
 

Detailed Description

API for mailboxes.

Authors
  • Michael R. Elkins
  • Thomas Roessler
  • 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 mx.h.

Macro Definition Documentation

◆ MUTT_OPEN_NO_FLAGS

#define MUTT_OPEN_NO_FLAGS   0

No flags are set.

Definition at line 52 of file mx.h.

◆ MUTT_NOSORT

#define MUTT_NOSORT   (1 << 0)

Do not sort the mailbox after opening it.

Definition at line 53 of file mx.h.

◆ MUTT_APPEND

#define MUTT_APPEND   (1 << 1)

Open mailbox for appending messages.

Definition at line 54 of file mx.h.

◆ MUTT_READONLY

#define MUTT_READONLY   (1 << 2)

Open in read-only mode.

Definition at line 55 of file mx.h.

◆ MUTT_QUIET

#define MUTT_QUIET   (1 << 3)

Do not print any messages.

Definition at line 56 of file mx.h.

◆ MUTT_NEWFOLDER

#define MUTT_NEWFOLDER   (1 << 4)

Create a new folder - same as MUTT_APPEND,.

but uses mutt_file_fopen() with mode "w" for mbox-style folders. This will truncate an existing file.

Definition at line 57 of file mx.h.

◆ MUTT_PEEK

#define MUTT_PEEK   (1 << 5)

Revert atime back after taking a look (if applicable)

Definition at line 60 of file mx.h.

◆ MUTT_APPENDNEW

#define MUTT_APPENDNEW   (1 << 6)

Set in mx_open_mailbox_append if the mailbox doesn't exist.

Used by maildir/mh to create the mailbox.

Definition at line 61 of file mx.h.

◆ MUTT_MSG_NO_FLAGS

#define MUTT_MSG_NO_FLAGS   0

No flags are set.

Definition at line 65 of file mx.h.

◆ MUTT_ADD_FROM

#define MUTT_ADD_FROM   (1 << 0)

add a From_ line

Definition at line 66 of file mx.h.

◆ MUTT_SET_DRAFT

#define MUTT_SET_DRAFT   (1 << 1)

set the message draft flag

Definition at line 67 of file mx.h.

Typedef Documentation

◆ OpenMailboxFlags

typedef uint8_t OpenMailboxFlags

Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.

Definition at line 51 of file mx.h.

◆ MsgOpenFlags

typedef uint8_t MsgOpenFlags

Flags for mx_msg_open_new(), e.g. MUTT_ADD_FROM.

Definition at line 64 of file mx.h.

Enumeration Type Documentation

◆ MxCheckReturns

Return values from mx_mbox_check()

Enumerator
MUTT_NEW_MAIL 

New mail received in Mailbox.

MUTT_LOCKED 

Couldn't lock the Mailbox.

MUTT_REOPENED 

Mailbox was reopened.

MUTT_FLAGS 

Nondestructive flags change (IMAP)

Definition at line 72 of file mx.h.

73 {
74  MUTT_NEW_MAIL = 1,
75  MUTT_LOCKED,
77  MUTT_FLAGS,
78 };
Nondestructive flags change (IMAP)
Definition: mx.h:77
Couldn&#39;t lock the Mailbox.
Definition: mx.h:75
New mail received in Mailbox.
Definition: mx.h:74
Mailbox was reopened.
Definition: mx.h:76

Function Documentation

◆ mx_mbox_check()

int mx_mbox_check ( struct Mailbox m)

Check for new mail - Wrapper for MxOps::mbox_check()

Parameters
mMailbox
Return values
>0Success, e.g. MUTT_NEW_MAIL
0Success, no change
-1Failure

Definition at line 1113 of file mx.c.

1114 {
1115  if (!m || !m->mx_ops)
1116  return -1;
1117 
1118  int rc = m->mx_ops->mbox_check(m);
1119  if ((rc == MUTT_NEW_MAIL) || (rc == MUTT_REOPENED))
1121 
1122  return rc;
1123 }
Email list was changed.
Definition: mailbox.h:166
int(* mbox_check)(struct Mailbox *m)
Check for new mail.
Definition: mx.h:153
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
New mail received in Mailbox.
Definition: mx.h:74
Mailbox was reopened.
Definition: mx.h:76
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:174
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_mbox_check_stats()

int mx_mbox_check_stats ( struct Mailbox m,
int  flags 
)

Check the statistics for a mailbox - Wrapper for MxOps::mbox_check_stats()

Definition at line 1791 of file mx.c.

1792 {
1793  if (!m)
1794  return -1;
1795 
1796  return m->mx_ops->mbox_check_stats(m, flags);
1797 }
int(* mbox_check_stats)(struct Mailbox *m, int flags)
Check the Mailbox statistics.
Definition: mx.h:163
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
+ Here is the caller graph for this function:

◆ mx_mbox_close()

int mx_mbox_close ( struct Context **  ptr)

Save changes and close mailbox.

Parameters
[out]ptrMailbox
Return values
MUTT_REOPENEDmailbox has been externally modified
MUTT_NEW_MAILnew mail has arrived
0Success
-1Failure
Note
The flag retvals come from a call to a backend sync function
Context will be freed after it's closed

Definition at line 604 of file mx.c.

605 {
606  if (!ptr || !*ptr)
607  return 0;
608 
609  struct Context *ctx = *ptr;
610  if (!ctx || !ctx->mailbox)
611  return -1;
612 
613  struct Mailbox *m = ctx->mailbox;
614 
615  if (C_MailCheckRecent && !m->peekonly)
616  m->has_new = false;
617 
618  if (m->readonly || m->dontwrite || m->append || m->peekonly)
619  {
621  ctx_free(ptr);
622  return 0;
623  }
624 
625  int i, read_msgs = 0;
626  int rc = -1;
627  enum QuadOption move_messages = MUTT_NO;
628  enum QuadOption purge = MUTT_YES;
629  struct Buffer *mbox = NULL;
630  struct Buffer *buf = mutt_buffer_pool_get();
631 
632 #ifdef USE_NNTP
633  if ((m->msg_unread != 0) && (m->type == MUTT_NNTP))
634  {
635  struct NntpMboxData *mdata = m->mdata;
636 
637  if (mdata && mdata->adata && mdata->group)
638  {
639  enum QuadOption ans =
640  query_quadoption(C_CatchupNewsgroup, _("Mark all articles read?"));
641  if (ans == MUTT_ABORT)
642  goto cleanup;
643  if (ans == MUTT_YES)
644  mutt_newsgroup_catchup(m, mdata->adata, mdata->group);
645  }
646  }
647 #endif
648 
649  for (i = 0; i < m->msg_count; i++)
650  {
651  struct Email *e = m->emails[i];
652  if (!e)
653  break;
654 
655  if (!e->deleted && e->read && !(e->flagged && C_KeepFlagged))
656  read_msgs++;
657  }
658 
659 #ifdef USE_NNTP
660  /* don't need to move articles from newsgroup */
661  if (m->type == MUTT_NNTP)
662  read_msgs = 0;
663 #endif
664 
665  if ((read_msgs != 0) && (C_Move != MUTT_NO))
666  {
667  bool is_spool;
668  mbox = mutt_buffer_pool_get();
669 
671  if (p)
672  {
673  is_spool = true;
674  mutt_buffer_strcpy(mbox, p);
675  }
676  else
677  {
678  mutt_buffer_strcpy(mbox, C_Mbox);
679  is_spool = mutt_is_spool(mailbox_path(m)) && !mutt_is_spool(mutt_b2s(mbox));
680  }
681 
682  if (is_spool && !mutt_buffer_is_empty(mbox))
683  {
685  mutt_buffer_printf(buf,
686  /* L10N: The first argument is the number of read messages to be
687  moved, the second argument is the target mailbox. */
688  ngettext("Move %d read message to %s?",
689  "Move %d read messages to %s?", read_msgs),
690  read_msgs, mutt_b2s(mbox));
691  move_messages = query_quadoption(C_Move, mutt_b2s(buf));
692  if (move_messages == MUTT_ABORT)
693  goto cleanup;
694  }
695  }
696 
697  /* There is no point in asking whether or not to purge if we are
698  * just marking messages as "trash". */
699  if ((m->msg_deleted != 0) && !((m->type == MUTT_MAILDIR) && C_MaildirTrash))
700  {
701  mutt_buffer_printf(buf,
702  ngettext("Purge %d deleted message?",
703  "Purge %d deleted messages?", m->msg_deleted),
704  m->msg_deleted);
705  purge = query_quadoption(C_Delete, mutt_b2s(buf));
706  if (purge == MUTT_ABORT)
707  goto cleanup;
708  }
709 
710  if (C_MarkOld && !m->peekonly)
711  {
712  for (i = 0; i < m->msg_count; i++)
713  {
714  struct Email *e = m->emails[i];
715  if (!e)
716  break;
717  if (!e->deleted && !e->old && !e->read)
718  mutt_set_flag(m, e, MUTT_OLD, true);
719  }
720  }
721 
722  if (move_messages)
723  {
724  if (m->verbose)
725  mutt_message(_("Moving read messages to %s..."), mutt_b2s(mbox));
726 
727 #ifdef USE_IMAP
728  /* try to use server-side copy first */
729  i = 1;
730 
731  if ((m->type == MUTT_IMAP) && (imap_path_probe(mutt_b2s(mbox), NULL) == MUTT_IMAP))
732  {
733  /* add messages for moving, and clear old tags, if any */
734  struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
735  for (i = 0; i < m->msg_count; i++)
736  {
737  struct Email *e = m->emails[i];
738  if (!e)
739  break;
740 
741  if (e->read && !e->deleted && !(e->flagged && C_KeepFlagged))
742  {
743  e->tagged = true;
744  emaillist_add_email(&el, e);
745  }
746  else
747  e->tagged = false;
748  }
749 
750  i = imap_copy_messages(ctx->mailbox, &el, mutt_b2s(mbox), true);
751  emaillist_clear(&el);
752  }
753 
754  if (i == 0) /* success */
756  else if (i == -1) /* horrible error, bail */
757  goto cleanup;
758  else /* use regular append-copy mode */
759 #endif
760  {
761  struct Mailbox *m_read = mx_path_resolve(mutt_b2s(mbox));
762  struct Context *ctx_read = mx_mbox_open(m_read, MUTT_APPEND);
763  if (!ctx_read)
764  {
765  mailbox_free(&m_read);
766  goto cleanup;
767  }
768 
769  for (i = 0; i < m->msg_count; i++)
770  {
771  struct Email *e = m->emails[i];
772  if (!e)
773  break;
774  if (e->read && !e->deleted && !(e->flagged && C_KeepFlagged))
775  {
776  if (mutt_append_message(ctx_read->mailbox, ctx->mailbox, e,
778  {
779  mutt_set_flag(m, e, MUTT_DELETE, true);
780  mutt_set_flag(m, e, MUTT_PURGE, true);
781  }
782  else
783  {
784  mx_mbox_close(&ctx_read);
785  goto cleanup;
786  }
787  }
788  }
789 
790  mx_mbox_close(&ctx_read);
791  }
792  }
793  else if (!m->changed && (m->msg_deleted == 0))
794  {
795  if (m->verbose)
796  mutt_message(_("Mailbox is unchanged"));
797  if ((m->type == MUTT_MBOX) || (m->type == MUTT_MMDF))
798  mbox_reset_atime(m, NULL);
800  ctx_free(ptr);
801  rc = 0;
802  goto cleanup;
803  }
804 
805  /* copy mails to the trash before expunging */
806  const struct Mailbox *m_trash = mx_mbox_find(m->account, C_Trash);
807  if (purge && (m->msg_deleted != 0) && (m != m_trash))
808  {
809  if (trash_append(ctx->mailbox) != 0)
810  goto cleanup;
811  }
812 
813 #ifdef USE_IMAP
814  /* allow IMAP to preserve the deleted flag across sessions */
815  if (m->type == MUTT_IMAP)
816  {
817  int check = imap_sync_mailbox(ctx->mailbox, (purge != MUTT_NO), true);
818  if (check < 0)
819  {
820  rc = check;
821  goto cleanup;
822  }
823  }
824  else
825 #endif
826  {
827  if (purge == MUTT_NO)
828  {
829  for (i = 0; i < m->msg_count; i++)
830  {
831  struct Email *e = m->emails[i];
832  if (!e)
833  break;
834 
835  e->deleted = false;
836  e->purge = false;
837  }
838  m->msg_deleted = 0;
839  }
840 
841  if (m->changed || (m->msg_deleted != 0))
842  {
843  int check = sync_mailbox(ctx->mailbox);
844  if (check != 0)
845  {
846  rc = check;
847  goto cleanup;
848  }
849  }
850  }
851 
852  if (m->verbose)
853  {
854  if (move_messages)
855  {
856  mutt_message(_("%d kept, %d moved, %d deleted"),
857  m->msg_count - m->msg_deleted, read_msgs, m->msg_deleted);
858  }
859  else
860  mutt_message(_("%d kept, %d deleted"), m->msg_count - m->msg_deleted, m->msg_deleted);
861  }
862 
863  if ((m->msg_count == m->msg_deleted) &&
864  ((m->type == MUTT_MMDF) || (m->type == MUTT_MBOX)) &&
866  {
868  }
869 
870 #ifdef USE_SIDEBAR
871  if ((purge == MUTT_YES) && (m->msg_deleted != 0))
872  {
873  for (i = 0; i < m->msg_count; i++)
874  {
875  struct Email *e = m->emails[i];
876  if (!e)
877  break;
878  if (e->deleted && !e->read)
879  {
880  m->msg_unread--;
881  if (!e->old)
882  m->msg_new--;
883  }
884  if (e->deleted && e->flagged)
885  m->msg_flagged--;
886  }
887  }
888 #endif
889 
891  ctx_free(ptr);
892 
893  rc = 0;
894 
895 cleanup:
898  return rc;
899 }
#define MUTT_APPEND
Open mailbox for appending messages.
Definition: mx.h:54
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
The "current" mailbox.
Definition: context.h:37
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:196
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
int msg_count
Total number of messages.
Definition: mailbox.h:91
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:68
bool C_MarkOld
Config: Mark new emails as old when leaving the mailbox.
Definition: globals.c:36
The envelope/body of an email.
Definition: email.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
WHERE bool C_SaveEmpty
Config: (mbox,mmdf) Preserve empty mailboxes.
Definition: mutt_globals.h:160
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe()
Definition: imap.c:2344
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:96
int msg_unread
Number of unread messages.
Definition: mailbox.h:92
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: mailbox.h:52
int mx_mbox_close(struct Context **ptr)
Save changes and close mailbox.
Definition: mx.c:604
void mbox_reset_atime(struct Mailbox *m, struct stat *st)
Reset the access time on the mailbox file.
Definition: mbox.c:840
User aborted the question (with Ctrl-G)
Definition: quad.h:38
#define mutt_message(...)
Definition: logging.h:83
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:93
static int sync_mailbox(struct Mailbox *m)
save changes to disk
Definition: mx.c:464
int emaillist_add_email(struct EmailList *el, struct Email *e)
Add an Email to a list.
Definition: email.c:144
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
static int trash_append(struct Mailbox *m)
move deleted mails to the trash folder
Definition: mx.c:495
bool peekonly
Just taking a glance, revert atime.
Definition: mailbox.h:117
struct NntpAccountData * adata
Definition: lib.h:153
unsigned char C_Move
Config: Move emails from C_Spoolfile to C_Mbox when read.
Definition: mx.c:85
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1581
struct Context * mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:267
Messages to be purged (bypass trash)
Definition: mutt.h:100
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MUTT_CM_NO_FLAGS
No flags are set.
Definition: copy.h:34
int imap_sync_mailbox(struct Mailbox *m, bool expunge, bool close)
Sync all the changes to the server.
Definition: imap.c:1468
bool has_new
Mailbox has new mail.
Definition: mailbox.h:88
char * C_Trash
Config: Folder to put deleted emails.
Definition: mx.c:86
unsigned char C_CatchupNewsgroup
Config: (nntp) Mark all articles as read when leaving a newsgroup.
Definition: config.c:37
bool tagged
Email is tagged.
Definition: email.h:44
bool read
Email is read.
Definition: email.h:51
struct Mailbox * mailbox
Definition: context.h:50
bool old
Email is seen, but unread.
Definition: email.h:50
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:60
void mutt_file_unlink_empty(const char *path)
Delete a file if it&#39;s empty.
Definition: file.c:1304
bool readonly
Don&#39;t allow changes to the mailbox.
Definition: mailbox.h:119
void mx_fastclose_mailbox(struct Mailbox *m)
free up memory associated with the Mailbox
Definition: mx.c:426
char * group
Definition: lib.h:140
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
void * mdata
Driver specific data.
Definition: mailbox.h:136
#define MUTT_MBOX_HOOK
mbox-hook: move messages after reading them
Definition: hook.h:46
&#39;Maildir&#39; Mailbox type
Definition: mailbox.h:51
Old messages.
Definition: mutt.h:94
#define mutt_b2s(buf)
Definition: buffer.h:41
int imap_copy_messages(struct Mailbox *m, struct EmailList *el, const char *dest, bool delete_original)
Server COPY messages to another folder.
Definition: message.c:1600
Messages to be deleted.
Definition: mutt.h:98
A mailbox.
Definition: mailbox.h:81
char * mutt_find_hook(HookFlags type, const char *pat)
Find a matching hook.
Definition: hook.c:552
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:39
bool dontwrite
Don&#39;t write the mailbox on close.
Definition: mailbox.h:115
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:49
bool append
Mailbox is opened in append mode.
Definition: mailbox.h:113
bool verbose
Display status messages?
Definition: mailbox.h:118
bool purge
Skip trash folder when deleting.
Definition: email.h:46
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
Definition: copy.h:61
WHERE bool C_MailCheckRecent
Config: Notify the user about new mail since the last time the mailbox was opened.
Definition: mutt_globals.h:154
NNTP-specific Mailbox data -.
Definition: lib.h:138
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:48
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: curs_lib.c:515
WHERE unsigned char C_Delete
Config: Really delete messages, when the mailbox is closed.
Definition: mutt_globals.h:129
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:323
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
bool flagged
Marked important?
Definition: email.h:43
void emaillist_clear(struct EmailList *el)
Drop a private list of Emails.
Definition: email.c:123
int msg_new
Number of new messages.
Definition: mailbox.h:95
bool deleted
Email is deleted.
Definition: email.h:45
bool C_MaildirTrash
Config: Use the maildir &#39;trashed&#39; flag, rather than deleting.
Definition: config.c:38
int mutt_append_message(struct Mailbox *dest, struct Mailbox *src, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags)
Append a message.
Definition: copy.c:891
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1670
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
bool changed
Mailbox has been modified.
Definition: mailbox.h:114
void ctx_free(struct Context **ptr)
Free a Context.
Definition: context.c:49
bool C_KeepFlagged
Config: Don&#39;t move flagged messages from C_Spoolfile to C_Mbox.
Definition: mx.c:83
struct NntpMboxData * mutt_newsgroup_catchup(struct Mailbox *m, struct NntpAccountData *adata, char *group)
Catchup newsgroup.
Definition: newsrc.c:1293
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
WHERE char * C_Mbox
Config: Folder that receives read emails (see Move)
Definition: mutt_globals.h:97
static bool mutt_is_spool(const char *str)
Is this the spoolfile?
Definition: mx.c:155
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_mbox_open()

struct Context* mx_mbox_open ( struct Mailbox m,
OpenMailboxFlags  flags 
)

Open a mailbox and parse it.

Parameters
mMailbox to open
flagsFlags, see OpenMailboxFlags
Return values
ptrMailbox context
NULLError

Definition at line 267 of file mx.c.

268 {
269  if (!m)
270  return NULL;
271 
272  struct Context *ctx = ctx_new();
273  ctx->mailbox = m;
274 
275  struct EventContext ev_ctx = { ctx };
276  notify_send(ctx->notify, NT_CONTEXT, NT_CONTEXT_OPEN, &ev_ctx);
277 
278  // If the Mailbox is closed, Context->mailbox must be set to NULL
280 
281  if ((m->type == MUTT_UNKNOWN) && (flags & (MUTT_NEWFOLDER | MUTT_APPEND)))
282  {
283  m->type = C_MboxType;
284  m->mx_ops = mx_get_ops(m->type);
285  }
286 
287  const bool newly_linked_account = !m->account;
288  if (newly_linked_account)
289  {
290  struct Account *a = mx_ac_find(m);
291  bool new_account = false;
292  if (!a)
293  {
294  a = account_new(NULL, NeoMutt->sub);
295  a->type = m->type;
296  new_account = true;
297  }
298  if (mx_ac_add(a, m) < 0)
299  {
300  ctx_free(&ctx);
301  if (new_account)
302  {
303  FREE(&a);
304  }
305  return NULL;
306  }
307  if (new_account)
308  {
310  }
311  }
312 
313  ctx->msg_not_read_yet = -1;
314  ctx->collapsed = false;
315 
316  m->verbose = !(flags & MUTT_QUIET);
317  if (flags & MUTT_READONLY)
318  m->readonly = true;
319  m->peekonly = (flags & MUTT_PEEK);
320 
321  if (flags & (MUTT_APPEND | MUTT_NEWFOLDER))
322  {
323  if (mx_open_mailbox_append(ctx->mailbox, flags) != 0)
324  {
325  goto error;
326  }
327  return ctx;
328  }
329 
330  if (m->opened > 0)
331  {
332  m->opened++;
333  return ctx;
334  }
335 
336  m->size = 0;
337  m->msg_unread = 0;
338  m->msg_flagged = 0;
339  m->rights = MUTT_ACL_ALL;
340 
341  if (m->type == MUTT_UNKNOWN)
342  {
344  m->mx_ops = mx_get_ops(m->type);
345  }
346 
347  if ((m->type == MUTT_UNKNOWN) || (m->type == MUTT_MAILBOX_ERROR) || !m->mx_ops)
348  {
349  if (m->type == MUTT_MAILBOX_ERROR)
351  else if ((m->type == MUTT_UNKNOWN) || !m->mx_ops)
352  mutt_error(_("%s is not a mailbox"), mailbox_path(m));
353  goto error;
354  }
355 
357 
358  /* if the user has a 'push' command in their .neomuttrc, or in a folder-hook,
359  * it will cause the progress messages not to be displayed because
360  * mutt_refresh() will think we are in the middle of a macro. so set a
361  * flag to indicate that we should really refresh the screen. */
362  OptForceRefresh = true;
363 
364  if (m->verbose)
365  mutt_message(_("Reading %s..."), mailbox_path(m));
366 
367  // Clear out any existing emails
368  for (int i = 0; i < m->email_max; i++)
369  {
370  email_free(&m->emails[i]);
371  }
372 
373  m->msg_count = 0;
374  m->msg_unread = 0;
375  m->msg_flagged = 0;
376  m->msg_new = 0;
377  m->msg_deleted = 0;
378  m->msg_tagged = 0;
379  m->vcount = 0;
380 
381  int rc = m->mx_ops->mbox_open(ctx->mailbox);
382  m->opened++;
383  if (rc == 0)
384  ctx_update(ctx);
385 
386  if ((rc == 0) || (rc == -2))
387  {
388  if ((flags & MUTT_NOSORT) == 0)
389  {
390  /* avoid unnecessary work since the mailbox is completely unthreaded
391  * to begin with */
392  OptSortSubthreads = false;
393  OptNeedRescore = false;
394  }
395  if (m->verbose)
397  if (rc == -2)
398  {
399  mutt_error(_("Reading from %s interrupted..."), mailbox_path(m));
400  mutt_sort_headers(ctx, true);
401  }
402  }
403  else
404  {
405  goto error;
406  }
407 
408  if (!m->peekonly)
409  m->has_new = false;
410  OptForceRefresh = false;
411 
412  return ctx;
413 
414 error:
416  if (newly_linked_account)
418  ctx_free(&ctx);
419  return NULL;
420 }
#define MUTT_APPEND
Open mailbox for appending messages.
Definition: mx.h:54
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
The "current" mailbox.
Definition: context.h:37
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:196
int ctx_mailbox_observer(struct NotifyCallback *nc)
Watch for changes affecting the Context - Implements observer_t.
Definition: context.c:291
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:141
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
#define MUTT_ACL_ALL
Definition: mailbox.h:76
int msg_count
Total number of messages.
Definition: mailbox.h:91
off_t size
Size of the Mailbox.
Definition: mailbox.h:87
#define mutt_perror(...)
Definition: logging.h:85
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:96
int msg_unread
Number of unread messages.
Definition: mailbox.h:92
int mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1757
#define mutt_message(...)
Definition: logging.h:83
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:93
bool peekonly
Just taking a glance, revert atime.
Definition: mailbox.h:117
A group of associated Mailboxes.
Definition: account.h:36
#define _(a)
Definition: message.h:28
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
Error occurred examining Mailbox.
Definition: mailbox.h:46
#define MUTT_READONLY
Open in read-only mode.
Definition: mx.h:55
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
WHERE bool OptNeedRescore
(pseudo) set when the &#39;score&#39; command is used
Definition: options.h:42
struct Account * mx_ac_find(struct Mailbox *m)
Find the Account owning a Mailbox.
Definition: mx.c:1557
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Context * ctx_new(void)
Create a new Context.
Definition: context.c:72
int vcount
The number of virtual messages.
Definition: mailbox.h:102
int(* mbox_open)(struct Mailbox *m)
Open a Mailbox.
Definition: mx.h:136
bool has_new
Mailbox has new mail.
Definition: mailbox.h:88
struct Mailbox * mailbox
Definition: context.h:50
#define MUTT_PEEK
Revert atime back after taking a look (if applicable)
Definition: mx.h:60
bool readonly
Don&#39;t allow changes to the mailbox.
Definition: mailbox.h:119
The Context has been opened.
Definition: context.h:61
struct Notify * notify
Notifications handler.
Definition: context.h:51
void mx_fastclose_mailbox(struct Mailbox *m)
free up memory associated with the Mailbox
Definition: mx.c:426
int opened
Number of times mailbox is opened.
Definition: mailbox.h:132
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
struct Account * account_new(const char *name, struct ConfigSubset *sub)
Create a new Account.
Definition: account.c:43
int msg_not_read_yet
Which msg "new" in pager, -1 if none.
Definition: context.h:44
WHERE bool OptForceRefresh
(pseudo) refresh even during macros
Definition: options.h:37
void mutt_sort_headers(struct Context *ctx, bool init)
Sort emails by their headers.
Definition: sort.c:364
int email_max
Number of pointers in emails.
Definition: mailbox.h:100
void ctx_update(struct Context *ctx)
Update the Context&#39;s message counts.
Definition: context.c:106
#define MUTT_NOSORT
Do not sort the mailbox after opening it.
Definition: mx.h:53
bool verbose
Display status messages?
Definition: mailbox.h:118
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
unsigned char C_MboxType
Config: Default type for creating new mailboxes.
Definition: mx.c:84
int msg_tagged
How many messages are tagged?
Definition: mailbox.h:97
#define MUTT_QUIET
Do not print any messages.
Definition: mx.h:56
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:121
bool notify_observer_add(struct Notify *notify, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:153
void mutt_make_label_hash(struct Mailbox *m)
Create a Hash Table to store the labels.
Definition: mutt_header.c:360
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1327
Context has changed, NotifyContext, EventContext.
Definition: notify_type.h:37
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
static int mx_open_mailbox_append(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox for appending.
Definition: mx.c:200
int msg_new
Number of new messages.
Definition: mailbox.h:95
bool collapsed
Are all threads collapsed?
Definition: context.h:48
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:94
#define mutt_error(...)
Definition: logging.h:84
#define FREE(x)
Definition: memory.h:40
WHERE bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: options.h:54
void ctx_free(struct Context **ptr)
Free a Context.
Definition: context.c:49
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct Notify * notify
Notifications handler.
Definition: mailbox.h:139
An Event that happened to an Context.
Definition: context.h:68
#define MUTT_NEWFOLDER
Create a new folder - same as MUTT_APPEND,.
Definition: mx.h:57
bool neomutt_account_add(struct NeoMutt *n, struct Account *a)
Add an Account to the global list.
Definition: neomutt.c:84
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:41
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_mbox_sync()

int mx_mbox_sync ( struct Mailbox m)

Save changes to mailbox.

Parameters
[in]mMailbox
Return values
MUTT_REOPENEDmailbox has been externally modified
MUTT_NEW_MAILnew mail has arrived
0Success
-1Error
Note
The flag retvals come from a call to a backend sync function

Definition at line 911 of file mx.c.

912 {
913  if (!m)
914  return -1;
915 
916  int rc;
917  int purge = 1;
918  int msgcount, deleted;
919 
920  if (m->dontwrite)
921  {
922  char buf[256], tmp[256];
923  if (km_expand_key(buf, sizeof(buf), km_find_func(MENU_MAIN, OP_TOGGLE_WRITE)))
924  snprintf(tmp, sizeof(tmp), _(" Press '%s' to toggle write"), buf);
925  else
926  mutt_str_copy(tmp, _("Use 'toggle-write' to re-enable write"), sizeof(tmp));
927 
928  mutt_error(_("Mailbox is marked unwritable. %s"), tmp);
929  return -1;
930  }
931  else if (m->readonly)
932  {
933  mutt_error(_("Mailbox is read-only"));
934  return -1;
935  }
936 
937  if (!m->changed && (m->msg_deleted == 0))
938  {
939  if (m->verbose)
940  mutt_message(_("Mailbox is unchanged"));
941  return 0;
942  }
943 
944  if (m->msg_deleted != 0)
945  {
946  char buf[128];
947 
948  snprintf(buf, sizeof(buf),
949  ngettext("Purge %d deleted message?", "Purge %d deleted messages?", m->msg_deleted),
950  m->msg_deleted);
951  purge = query_quadoption(C_Delete, buf);
952  if (purge == MUTT_ABORT)
953  return -1;
954  if (purge == MUTT_NO)
955  {
956  if (!m->changed)
957  return 0; /* nothing to do! */
958  /* let IMAP servers hold on to D flags */
959  if (m->type != MUTT_IMAP)
960  {
961  for (int i = 0; i < m->msg_count; i++)
962  {
963  struct Email *e = m->emails[i];
964  if (!e)
965  break;
966  e->deleted = false;
967  e->purge = false;
968  }
969  m->msg_deleted = 0;
970  }
971  }
973  }
974 
975  /* really only for IMAP - imap_sync_mailbox results in a call to
976  * ctx_update_tables, so m->msg_deleted is 0 when it comes back */
977  msgcount = m->msg_count;
978  deleted = m->msg_deleted;
979 
980  const struct Mailbox *m_trash = mx_mbox_find(m->account, C_Trash);
981  if (purge && (m->msg_deleted != 0) && (m != m_trash))
982  {
983  if (trash_append(m) != 0)
984  return -1;
985  }
986 
987 #ifdef USE_IMAP
988  if (m->type == MUTT_IMAP)
989  rc = imap_sync_mailbox(m, purge, false);
990  else
991 #endif
992  rc = sync_mailbox(m);
993  if (rc >= 0)
994  {
995 #ifdef USE_IMAP
996  if ((m->type == MUTT_IMAP) && !purge)
997  {
998  if (m->verbose)
999  mutt_message(_("Mailbox checkpointed"));
1000  }
1001  else
1002 #endif
1003  {
1004  if (m->verbose)
1005  mutt_message(_("%d kept, %d deleted"), msgcount - deleted, deleted);
1006  }
1007 
1008  mutt_sleep(0);
1009 
1010  if ((m->msg_count == m->msg_deleted) &&
1011  ((m->type == MUTT_MBOX) || (m->type == MUTT_MMDF)) &&
1013  {
1014  unlink(mailbox_path(m));
1016  return 0;
1017  }
1018 
1019  /* if we haven't deleted any messages, we don't need to resort */
1020  /* ... except for certain folder formats which need "unsorted"
1021  * sort order in order to synchronize folders.
1022  *
1023  * MH and maildir are safe. mbox-style seems to need re-sorting,
1024  * at least with the new threading code. */
1025  if (purge || ((m->type != MUTT_MAILDIR) && (m->type != MUTT_MH)))
1026  {
1027  /* IMAP does this automatically after handling EXPUNGE */
1028  if (m->type != MUTT_IMAP)
1029  {
1032  }
1033  }
1034  }
1035 
1036  return rc;
1037 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:196
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
int msg_count
Total number of messages.
Definition: mailbox.h:91
The envelope/body of an email.
Definition: email.h:37
Clear the &#39;last-tagged&#39; pointer.
Definition: mailbox.h:170
WHERE bool C_SaveEmpty
Config: (mbox,mmdf) Preserve empty mailboxes.
Definition: mutt_globals.h:160
Update internal tables.
Definition: mailbox.h:169
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:96
User aborted the question (with Ctrl-G)
Definition: quad.h:38
#define mutt_message(...)
Definition: logging.h:83
static int sync_mailbox(struct Mailbox *m)
save changes to disk
Definition: mx.c:464
static int trash_append(struct Mailbox *m)
move deleted mails to the trash folder
Definition: mx.c:495
#define _(a)
Definition: message.h:28
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1581
Index panel (list of emails)
Definition: keymap.h:78
int imap_sync_mailbox(struct Mailbox *m, bool expunge, bool close)
Sync all the changes to the server.
Definition: imap.c:1468
char * C_Trash
Config: Folder to put deleted emails.
Definition: mx.c:86
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1446
bool readonly
Don&#39;t allow changes to the mailbox.
Definition: mailbox.h:119
void mx_fastclose_mailbox(struct Mailbox *m)
free up memory associated with the Mailbox
Definition: mx.c:426
&#39;Maildir&#39; Mailbox type
Definition: mailbox.h:51
struct Keymap * km_find_func(enum MenuType menu, int func)
Find a function&#39;s mapping in a Menu.
Definition: keymap.c:899
Email list needs resorting.
Definition: mailbox.h:167
A mailbox.
Definition: mailbox.h:81
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:39
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:871
bool dontwrite
Don&#39;t write the mailbox on close.
Definition: mailbox.h:115
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:49
&#39;MH&#39; Mailbox type
Definition: mailbox.h:50
bool verbose
Display status messages?
Definition: mailbox.h:118
bool purge
Skip trash folder when deleting.
Definition: email.h:46
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:48
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: curs_lib.c:515
WHERE unsigned char C_Delete
Config: Really delete messages, when the mailbox is closed.
Definition: mutt_globals.h:129
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:721
bool deleted
Email is deleted.
Definition: email.h:45
#define mutt_error(...)
Definition: logging.h:84
bool changed
Mailbox has been modified.
Definition: mailbox.h:114
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:174
static bool mutt_is_spool(const char *str)
Is this the spoolfile?
Definition: mx.c:155
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_msg_close()

int mx_msg_close ( struct Mailbox m,
struct Message **  msg 
)

Close a message.

Parameters
[in]mMailbox
[out]msgMessage to close
Return values
0Success
-1Failure

Definition at line 1180 of file mx.c.

1181 {
1182  if (!m || !msg || !*msg)
1183  return 0;
1184 
1185  int rc = 0;
1186 
1187  if (m->mx_ops && m->mx_ops->msg_close)
1188  rc = m->mx_ops->msg_close(m, *msg);
1189 
1190  if ((*msg)->path)
1191  {
1192  mutt_debug(LL_DEBUG1, "unlinking %s\n", (*msg)->path);
1193  unlink((*msg)->path);
1194  FREE(&(*msg)->path);
1195  }
1196 
1197  FREE(&(*msg)->committed_path);
1198  FREE(msg);
1199  return rc;
1200 }
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
Log at debug level 1.
Definition: logging.h:40
#define FREE(x)
Definition: memory.h:40
int(* msg_close)(struct Mailbox *m, struct Message *msg)
Close an email.
Definition: mx.h:217
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the caller graph for this function:

◆ mx_msg_commit()

int mx_msg_commit ( struct Mailbox m,
struct Message msg 
)

Commit a message to a folder - Wrapper for MxOps::msg_commit()

Parameters
mMailbox
msgMessage to commit
Return values
0Success
-1Failure

Definition at line 1159 of file mx.c.

1160 {
1161  if (!m || !m->mx_ops || !m->mx_ops->msg_commit)
1162  return -1;
1163 
1164  if (!(msg->write && m->append))
1165  {
1166  mutt_debug(LL_DEBUG1, "msg->write = %d, m->append = %d\n", msg->write, m->append);
1167  return -1;
1168  }
1169 
1170  return m->mx_ops->msg_commit(m, msg);
1171 }
int(* msg_commit)(struct Mailbox *m, struct Message *msg)
Save changes to an email.
Definition: mx.h:208
bool append
Mailbox is opened in append mode.
Definition: mailbox.h:113
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
bool write
nonzero if message is open for writing
Definition: mx.h:88
Log at debug level 1.
Definition: logging.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the caller graph for this function:

◆ mx_msg_open_new()

struct Message* mx_msg_open_new ( struct Mailbox m,
struct Email e,
MsgOpenFlags  flags 
)

Open a new message.

Parameters
mDestination mailbox
eMessage being copied (required for maildir support, because the filename depends on the message flags)
flagsFlags, see MsgOpenFlags
Return values
ptrNew Message

Definition at line 1046 of file mx.c.

1047 {
1048  if (!m)
1049  return NULL;
1050 
1051  struct Address *p = NULL;
1052  struct Message *msg = NULL;
1053 
1054  if (!m->mx_ops || !m->mx_ops->msg_open_new)
1055  {
1056  mutt_debug(LL_DEBUG1, "function unimplemented for mailbox type %d\n", m->type);
1057  return NULL;
1058  }
1059 
1060  msg = mutt_mem_calloc(1, sizeof(struct Message));
1061  msg->write = true;
1062 
1063  if (e)
1064  {
1065  msg->flags.flagged = e->flagged;
1066  msg->flags.replied = e->replied;
1067  msg->flags.read = e->read;
1068  msg->flags.draft = (flags & MUTT_SET_DRAFT);
1069  msg->received = e->received;
1070  }
1071 
1072  if (msg->received == 0)
1073  msg->received = mutt_date_epoch();
1074 
1075  if (m->mx_ops->msg_open_new(m, msg, e) == 0)
1076  {
1077  if (m->type == MUTT_MMDF)
1078  fputs(MMDF_SEP, msg->fp);
1079 
1080  if (((m->type == MUTT_MBOX) || (m->type == MUTT_MMDF)) && (flags & MUTT_ADD_FROM))
1081  {
1082  if (e)
1083  {
1084  p = TAILQ_FIRST(&e->env->return_path);
1085  if (!p)
1086  p = TAILQ_FIRST(&e->env->sender);
1087  if (!p)
1088  p = TAILQ_FIRST(&e->env->from);
1089  }
1090 
1091  // Force a 'C' locale for the date, so that day/month names are in English
1092  locale_t loc = newlocale(LC_TIME_MASK, "C", 0);
1093  char buf[64] = { 0 };
1094  struct tm tm = mutt_date_localtime(msg->received);
1095  strftime_l(buf, sizeof(buf), "%a %b %e %H:%M:%S %Y", &tm, loc);
1096  freelocale(loc);
1097  fprintf(msg->fp, "From %s %s\n", p ? p->mailbox : NONULL(Username), buf);
1098  }
1099  }
1100  else
1101  FREE(&msg);
1102 
1103  return msg;
1104 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:414
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
#define NONULL(x)
Definition: string2.h:37
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define TAILQ_FIRST(head)
Definition: queue.h:716
struct tm mutt_date_localtime(time_t t)
Converts calendar time to a broken-down time structure expressed in user timezone.
Definition: date.c:641
bool replied
Definition: mx.h:93
An email address.
Definition: address.h:34
char * mailbox
Mailbox and host address.
Definition: address.h:37
#define MUTT_SET_DRAFT
set the message draft flag
Definition: mx.h:67
int(* msg_open_new)(struct Mailbox *m, struct Message *msg, struct Email *e)
Open a new message in a Mailbox.
Definition: mx.h:199
WHERE char * Username
User&#39;s login name.
Definition: mutt_globals.h:53
bool read
Email is read.
Definition: email.h:51
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
struct Envelope * env
Envelope information.
Definition: email.h:89
bool flagged
Definition: mx.h:92
A local copy of an email.
Definition: mx.h:83
struct Message::@0 flags
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:49
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
bool draft
Definition: mx.h:94
#define MMDF_SEP
Definition: lib.h:64
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:48
bool write
nonzero if message is open for writing
Definition: mx.h:88
struct AddressList return_path
Return path for the Email.
Definition: envelope.h:56
Log at debug level 1.
Definition: logging.h:40
bool flagged
Marked important?
Definition: email.h:43
bool replied
Email has been replied to.
Definition: email.h:54
FILE * fp
pointer to the message data
Definition: mx.h:85
#define FREE(x)
Definition: memory.h:40
time_t received
the time at which this message was received
Definition: mx.h:96
struct AddressList sender
Email&#39;s sender.
Definition: envelope.h:61
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
bool read
Definition: mx.h:91
#define MUTT_ADD_FROM
add a From_ line
Definition: mx.h:66
time_t received
Time when the message was placed in the mailbox.
Definition: email.h:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_msg_open()

struct Message* mx_msg_open ( struct Mailbox m,
int  msgno 
)

return a stream pointer for a message

Parameters
mMailbox
msgnoMessage number
Return values
ptrMessage
NULLError

Definition at line 1132 of file mx.c.

1133 {
1134  if (!m)
1135  return NULL;
1136 
1137  struct Message *msg = NULL;
1138 
1139  if (!m->mx_ops || !m->mx_ops->msg_open)
1140  {
1141  mutt_debug(LL_DEBUG1, "function not implemented for mailbox type %d\n", m->type);
1142  return NULL;
1143  }
1144 
1145  msg = mutt_mem_calloc(1, sizeof(struct Message));
1146  if (m->mx_ops->msg_open(m, msg, msgno) < 0)
1147  FREE(&msg);
1148 
1149  return msg;
1150 }
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
A local copy of an email.
Definition: mx.h:83
int(* msg_open)(struct Mailbox *m, struct Message *msg, int msgno)
Open an email message in a Mailbox.
Definition: mx.h:189
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
Log at debug level 1.
Definition: logging.h:40
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_msg_padding_size()

int mx_msg_padding_size ( struct Mailbox m)

Bytes of padding between messages - Wrapper for MxOps::msg_padding_size()

Parameters
mMailbox
Return values
numNumber of bytes of padding

mmdf and mbox add separators, which leads a small discrepancy when computing vsize for a limited view.

Definition at line 1543 of file mx.c.

1544 {
1545  if (!m || !m->mx_ops || !m->mx_ops->msg_padding_size)
1546  return 0;
1547 
1548  return m->mx_ops->msg_padding_size(m);
1549 }
int(* msg_padding_size)(struct Mailbox *m)
Bytes of padding between messages.
Definition: mx.h:224
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
+ Here is the caller graph for this function:

◆ mx_save_hcache()

int mx_save_hcache ( struct Mailbox m,
struct Email e 
)

Save message to the header cache - Wrapper for MxOps::msg_save_hcache()

Parameters
mMailbox
eEmail
Return values
0Success
-1Failure

Write a single header out to the header cache.

Definition at line 1808 of file mx.c.

1809 {
1810  if (!m->mx_ops || !m->mx_ops->msg_save_hcache)
1811  return 0;
1812 
1813  return m->mx_ops->msg_save_hcache(m, e);
1814 }
int(* msg_save_hcache)(struct Mailbox *m, struct Email *e)
Save message to the header cache.
Definition: mx.h:233
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
+ Here is the caller graph for this function:

◆ mx_path_canon()

int mx_path_canon ( char *  buf,
size_t  buflen,
const char *  folder,
enum MailboxType type 
)

Canonicalise a mailbox path - Wrapper for MxOps::path_canon()

Definition at line 1373 of file mx.c.

1374 {
1375  if (!buf)
1376  return -1;
1377 
1378  for (size_t i = 0; i < 3; i++)
1379  {
1380  /* Look for !! ! - < > or ^ followed by / or NUL */
1381  if ((buf[0] == '!') && (buf[1] == '!'))
1382  {
1383  if (((buf[2] == '/') || (buf[2] == '\0')))
1384  {
1385  mutt_str_inline_replace(buf, buflen, 2, LastFolder);
1386  }
1387  }
1388  else if ((buf[0] == '+') || (buf[0] == '='))
1389  {
1390  size_t folder_len = mutt_str_len(folder);
1391  if ((folder_len > 0) && (folder[folder_len - 1] != '/'))
1392  {
1393  buf[0] = '/';
1394  mutt_str_inline_replace(buf, buflen, 0, folder);
1395  }
1396  else
1397  {
1398  mutt_str_inline_replace(buf, buflen, 1, folder);
1399  }
1400  }
1401  else if ((buf[1] == '/') || (buf[1] == '\0'))
1402  {
1403  if (buf[0] == '!')
1404  {
1405  mutt_str_inline_replace(buf, buflen, 1, C_Spoolfile);
1406  }
1407  else if (buf[0] == '-')
1408  {
1409  mutt_str_inline_replace(buf, buflen, 1, LastFolder);
1410  }
1411  else if (buf[0] == '<')
1412  {
1413  mutt_str_inline_replace(buf, buflen, 1, C_Record);
1414  }
1415  else if (buf[0] == '>')
1416  {
1417  mutt_str_inline_replace(buf, buflen, 1, C_Mbox);
1418  }
1419  else if (buf[0] == '^')
1420  {
1421  mutt_str_inline_replace(buf, buflen, 1, CurrentFolder);
1422  }
1423  else if (buf[0] == '~')
1424  {
1425  mutt_str_inline_replace(buf, buflen, 1, HomeDir);
1426  }
1427  }
1428  else if (buf[0] == '@')
1429  {
1430  /* elm compatibility, @ expands alias to user name */
1431  struct AddressList *al = alias_lookup(buf + 1);
1432  if (!al || TAILQ_EMPTY(al))
1433  break;
1434 
1435  struct Email *e = email_new();
1436  e->env = mutt_env_new();
1437  mutt_addrlist_copy(&e->env->from, al, false);
1438  mutt_addrlist_copy(&e->env->to, al, false);
1439  mutt_default_save(buf, buflen, e);
1440  email_free(&e);
1441  break;
1442  }
1443  else
1444  {
1445  break;
1446  }
1447  }
1448 
1449  // if (!folder) //XXX - use inherited version, or pass NULL to backend?
1450  // return -1;
1451 
1452  enum MailboxType type2 = mx_path_probe(buf);
1453  if (type)
1454  *type = type2;
1455  const struct MxOps *ops = mx_get_ops(type2);
1456  if (!ops || !ops->path_canon)
1457  return -1;
1458 
1459  if (ops->path_canon(buf, buflen) < 0)
1460  {
1461  mutt_path_canon(buf, buflen, HomeDir, true);
1462  }
1463 
1464  return 0;
1465 }
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:141
The envelope/body of an email.
Definition: email.h:37
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:737
void mutt_default_save(char *path, size_t pathlen, struct Email *e)
Find the default save path for an email.
Definition: hook.c:653
char * HomeDir
User&#39;s home directory.
Definition: mutt_globals.h:50
int(* path_canon)(char *buf, size_t buflen)
Canonicalise a Mailbox path.
Definition: mx.h:272
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
struct AddressList * alias_lookup(const char *name)
Find an Alias.
Definition: alias.c:277
struct Envelope * env
Envelope information.
Definition: email.h:89
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:42
WHERE char * LastFolder
Previously selected mailbox.
Definition: mutt_globals.h:56
WHERE char * C_Record
Config: Folder to save &#39;sent&#39; messages.
Definition: mutt_globals.h:101
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:636
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1327
bool mutt_path_canon(char *buf, size_t buflen, const char *homedir, bool is_dir)
Create the canonical version of a path.
Definition: path.c:285
MailboxType
Supported mailbox formats.
Definition: mailbox.h:43
WHERE char * C_Spoolfile
Config: Inbox.
Definition: mutt_globals.h:111
WHERE char * CurrentFolder
Currently selected mailbox.
Definition: mutt_globals.h:55
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
struct Email * email_new(void)
Create a new Email.
Definition: email.c:68
bool mutt_str_inline_replace(char *buf, size_t buflen, size_t xlen, const char *rstr)
Replace the beginning of a string.
Definition: string.c:1018
#define TAILQ_EMPTY(head)
Definition: queue.h:714
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:41
WHERE char * C_Mbox
Config: Folder that receives read emails (see Move)
Definition: mutt_globals.h:97
The Mailbox API.
Definition: mx.h:105
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_path_canon2()

int mx_path_canon2 ( struct Mailbox m,
const char *  folder 
)

Canonicalise the path to realpath.

Parameters
mMailbox
folderPath to canonicalise
Return values
0Success
-1Failure

Definition at line 1474 of file mx.c.

1475 {
1476  if (!m)
1477  return -1;
1478 
1479  char buf[PATH_MAX];
1480 
1481  if (m->realpath)
1482  mutt_str_copy(buf, m->realpath, sizeof(buf));
1483  else
1484  mutt_str_copy(buf, mailbox_path(m), sizeof(buf));
1485 
1486  int rc = mx_path_canon(buf, sizeof(buf), folder, &m->type);
1487 
1488  mutt_str_replace(&m->realpath, buf);
1489 
1490  if (rc >= 0)
1491  {
1492  m->mx_ops = mx_get_ops(m->type);
1494  }
1495 
1496  return rc;
1497 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:196
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:141
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define PATH_MAX
Definition: mutt.h:44
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:721
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:451
struct Buffer pathbuf
Definition: mailbox.h:83
int mx_path_canon(char *buf, size_t buflen, const char *folder, enum MailboxType *type)
Canonicalise a mailbox path - Wrapper for MxOps::path_canon()
Definition: mx.c:1373
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_path_parent()

int mx_path_parent ( char *  buf,
size_t  buflen 
)

Find the parent of a mailbox path - Wrapper for MxOps::path_parent()

Definition at line 1527 of file mx.c.

1528 {
1529  if (!buf)
1530  return -1;
1531 
1532  return 0;
1533 }

◆ mx_path_pretty()

int mx_path_pretty ( char *  buf,
size_t  buflen,
const char *  folder 
)

Abbreviate a mailbox path - Wrapper for MxOps::path_pretty()

Definition at line 1502 of file mx.c.

1503 {
1504  enum MailboxType type = mx_path_probe(buf);
1505  const struct MxOps *ops = mx_get_ops(type);
1506  if (!ops)
1507  return -1;
1508 
1509  if (!ops->path_canon)
1510  return -1;
1511 
1512  if (ops->path_canon(buf, buflen) < 0)
1513  return -1;
1514 
1515  if (!ops->path_pretty)
1516  return -1;
1517 
1518  if (ops->path_pretty(buf, buflen, folder) < 0)
1519  return -1;
1520 
1521  return 0;
1522 }
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:141
int(* path_canon)(char *buf, size_t buflen)
Canonicalise a Mailbox path.
Definition: mx.h:272
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
Definition: mx.h:107
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1327
MailboxType
Supported mailbox formats.
Definition: mailbox.h:43
int(* path_pretty)(char *buf, size_t buflen, const char *folder)
Abbreviate a Mailbox path.
Definition: mx.h:282
The Mailbox API.
Definition: mx.h:105
+ Here is the call graph for this function:

◆ mx_path_probe()

enum MailboxType mx_path_probe ( const char *  path)

Find a mailbox that understands a path.

Parameters
pathPath to examine
Return values
numType, e.g. MUTT_IMAP

Definition at line 1327 of file mx.c.

1328 {
1329  if (!path)
1330  return MUTT_UNKNOWN;
1331 
1332  enum MailboxType rc;
1333 
1334  // First, search the non-local Mailbox types (is_local == false)
1335  for (const struct MxOps **ops = mx_ops; *ops; ops++)
1336  {
1337  if ((*ops)->is_local)
1338  continue;
1339  rc = (*ops)->path_probe(path, NULL);
1340  if (rc != MUTT_UNKNOWN)
1341  return rc;
1342  }
1343 
1344  struct stat st = { 0 };
1345  if (stat(path, &st) != 0)
1346  {
1347  mutt_debug(LL_DEBUG1, "unable to stat %s: %s (errno %d)\n", path, strerror(errno), errno);
1348  return MUTT_UNKNOWN;
1349  }
1350 
1351  if (S_ISFIFO(st.st_mode))
1352  {
1353  mutt_error(_("Can't open %s: it is a pipe"), path);
1354  return MUTT_UNKNOWN;
1355  }
1356 
1357  // Next, search the local Mailbox types (is_local == true)
1358  for (const struct MxOps **ops = mx_ops; *ops; ops++)
1359  {
1360  if (!(*ops)->is_local)
1361  continue;
1362  rc = (*ops)->path_probe(path, &st);
1363  if (rc != MUTT_UNKNOWN)
1364  return rc;
1365  }
1366 
1367  return rc;
1368 }
#define _(a)
Definition: message.h:28
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
const struct MxOps * mx_ops[]
All the Mailbox backends.
Definition: mx.c:107
MailboxType
Supported mailbox formats.
Definition: mailbox.h:43
Log at debug level 1.
Definition: logging.h:40
#define mutt_error(...)
Definition: logging.h:84
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
The Mailbox API.
Definition: mx.h:105
+ Here is the caller graph for this function:

◆ mx_path_resolve()

struct Mailbox* mx_path_resolve ( const char *  path)

Get a Mailbox for a path.

Parameters
pathMailbox path
Return values
ptrMailbox

If there isn't a Mailbox for the path, one will be created.

Definition at line 1670 of file mx.c.

1671 {
1672  if (!path)
1673  return NULL;
1674 
1675  struct Mailbox *m = mx_mbox_find2(path);
1676  if (m)
1677  return m;
1678 
1679  m = mailbox_new();
1680  m->flags = MB_HIDDEN;
1681  mutt_buffer_strcpy(&m->pathbuf, path);
1683 
1684  return m;
1685 }
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1474
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1643
int flags
e.g. MB_NORMAL
Definition: mailbox.h:134
#define MB_HIDDEN
Definition: mailbox.h:38
A mailbox.
Definition: mailbox.h:81
WHERE char * C_Folder
Config: Base folder for a set of mailboxes.
Definition: mutt_globals.h:99
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
struct Mailbox * mailbox_new(void)
Create a new Mailbox.
Definition: mailbox.c:42
struct Buffer pathbuf
Definition: mailbox.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_resolve()

struct Mailbox* mx_resolve ( const char *  path_or_name)

Get a Mailbox from either a path or name.

Parameters
path_or_nameMailbox path or name
Return values
ptrMailbox

Order of resolving:

  1. Name
  2. Path

Definition at line 1739 of file mx.c.

1740 {
1741  if (!path_or_name)
1742  return NULL;
1743 
1744  // Order is name first because you can create a Mailbox from
1745  // a path, but can't from a name. So fallback behavior creates
1746  // a new Mailbox for us.
1747  struct Mailbox *m = mx_mbox_find_by_name(path_or_name);
1748  if (!m)
1749  m = mx_path_resolve(path_or_name);
1750 
1751  return m;
1752 }
static struct Mailbox * mx_mbox_find_by_name(const char *name)
Find a Mailbox with given name.
Definition: mx.c:1714
A mailbox.
Definition: mailbox.h:81
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1670
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_tags_commit()

int mx_tags_commit ( struct Mailbox m,
struct Email e,
char *  tags 
)

Save tags to the Mailbox - Wrapper for MxOps::tags_commit()

Parameters
mMailbox
eEmail
tagsTags to save
Return values
0Success
-1Failure

Definition at line 1300 of file mx.c.

1301 {
1302  if (!m)
1303  return -1;
1304 
1305  if (m->mx_ops->tags_commit)
1306  return m->mx_ops->tags_commit(m, e, tags);
1307 
1308  mutt_message(_("Folder doesn't support tagging, aborting"));
1309  return -1;
1310 }
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
int(* tags_commit)(struct Mailbox *m, struct Email *e, char *buf)
Save the tags to a message.
Definition: mx.h:255
+ Here is the caller graph for this function:

◆ mx_tags_edit()

int mx_tags_edit ( struct Mailbox m,
const char *  tags,
char *  buf,
size_t  buflen 
)

start the tag editor of the mailbox

Parameters
mMailbox
tagsExisting tags
bufBuffer for the results
buflenLength of the buffer
Return values
-1Error
0No valid user input
1Buffer set

Definition at line 1280 of file mx.c.

1281 {
1282  if (!m)
1283  return -1;
1284 
1285  if (m->mx_ops->tags_edit)
1286  return m->mx_ops->tags_edit(m, tags, buf, buflen);
1287 
1288  mutt_message(_("Folder doesn't support tagging, aborting"));
1289  return -1;
1290 }
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
int(* tags_edit)(struct Mailbox *m, const char *tags, char *buf, size_t buflen)
Prompt and validate new messages tags.
Definition: mx.h:245
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
+ Here is the caller graph for this function:

◆ mx_ac_find()

struct Account* mx_ac_find ( struct Mailbox m)

Find the Account owning a Mailbox.

Parameters
mMailbox
Return values
ptrAccount
NULLNone found

Definition at line 1557 of file mx.c.

1558 {
1559  if (!m || !m->mx_ops)
1560  return NULL;
1561 
1562  struct Account *np = NULL;
1563  TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
1564  {
1565  if (np->type != m->type)
1566  continue;
1567 
1568  if (m->mx_ops->ac_find(np, m->realpath))
1569  return np;
1570  }
1571 
1572  return NULL;
1573 }
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
A group of associated Mailboxes.
Definition: account.h:36
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
Container for Accounts, Notifications.
Definition: neomutt.h:36
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
struct Account *(* ac_find)(struct Account *a, const char *path)
Find an Account that matches a Mailbox path.
Definition: mx.h:118
+ Here is the caller graph for this function:

◆ mx_mbox_find()

struct Mailbox* mx_mbox_find ( struct Account a,
const char *  path 
)

Find a Mailbox on an Account.

Parameters
aAccount to search
pathPath to find
Return values
ptrMailbox

Definition at line 1581 of file mx.c.

1582 {
1583  if (!a || !path)
1584  return NULL;
1585 
1586  struct MailboxNode *np = NULL;
1587  struct Url *url_p = NULL;
1588  struct Url *url_a = NULL;
1589 
1590  const bool use_url = (a->type == MUTT_IMAP);
1591  if (use_url)
1592  {
1593  url_p = url_parse(path);
1594  if (!url_p)
1595  goto done;
1596  }
1597 
1598  STAILQ_FOREACH(np, &a->mailboxes, entries)
1599  {
1600  if (!use_url)
1601  {
1602  if (mutt_str_equal(np->mailbox->realpath, path))
1603  return np->mailbox;
1604  continue;
1605  }
1606 
1607  url_free(&url_a);
1608  url_a = url_parse(np->mailbox->realpath);
1609  if (!url_a)
1610  continue;
1611 
1612  if (!mutt_istr_equal(url_a->host, url_p->host))
1613  continue;
1614  if (url_p->user && !mutt_istr_equal(url_a->user, url_p->user))
1615  continue;
1616  if (a->type == MUTT_IMAP)
1617  {
1618  if (imap_mxcmp(url_a->path, url_p->path) == 0)
1619  break;
1620  }
1621  else
1622  {
1623  if (mutt_str_equal(url_a->path, url_p->path))
1624  break;
1625  }
1626  }
1627 
1628 done:
1629  url_free(&url_p);
1630  url_free(&url_a);
1631 
1632  if (!np)
1633  return NULL;
1634  return np->mailbox;
1635 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:876
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
int imap_mxcmp(const char *mx1, const char *mx2)
Compare mailbox names, giving priority to INBOX.
Definition: util.c:691
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:888
char * user
Username.
Definition: url.h:69
char * host
Host.
Definition: url.h:71
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
char * path
Path.
Definition: url.h:73
List of Mailboxes.
Definition: mailbox.h:145
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:147
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:234
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_mbox_find2()

struct Mailbox* mx_mbox_find2 ( const char *  path)

Find a Mailbox on an Account.

Parameters
pathPath to find
Return values
ptrMailbox
NULLNo match

Definition at line 1643 of file mx.c.

1644 {
1645  if (!path)
1646  return NULL;
1647 
1648  char buf[PATH_MAX];
1649  mutt_str_copy(buf, path, sizeof(buf));
1650  mx_path_canon(buf, sizeof(buf), C_Folder, NULL);
1651 
1652  struct Account *np = NULL;
1653  TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
1654  {
1655  struct Mailbox *m = mx_mbox_find(np, buf);
1656  if (m)
1657  return m;
1658  }
1659 
1660  return NULL;
1661 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
A group of associated Mailboxes.
Definition: account.h:36
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1581
Container for Accounts, Notifications.
Definition: neomutt.h:36
A mailbox.
Definition: mailbox.h:81
#define PATH_MAX
Definition: mutt.h:44
WHERE char * C_Folder
Config: Base folder for a set of mailboxes.
Definition: mutt_globals.h:99
char * path
Path.
Definition: url.h:73
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:721
int mx_path_canon(char *buf, size_t buflen, const char *folder, enum MailboxType *type)
Canonicalise a mailbox path - Wrapper for MxOps::path_canon()
Definition: mx.c:1373
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_ac_add()

int mx_ac_add ( struct Account a,
struct Mailbox m 
)

Add a Mailbox to an Account - Wrapper for MxOps::ac_add()

Definition at line 1757 of file mx.c.

1758 {
1759  if (!a || !m || !m->mx_ops || !m->mx_ops->ac_add)
1760  return -1;
1761 
1762  if (m->mx_ops->ac_add(a, m) < 0)
1763  return -1;
1764 
1765  account_mailbox_add(a, m);
1766  return 0;
1767 }
int(* ac_add)(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account.
Definition: mx.h:127
bool account_mailbox_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account.
Definition: account.c:66
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_ac_remove()

int mx_ac_remove ( struct Mailbox m)

Remove a Mailbox from an Account and delete Account if empty.

Parameters
mMailbox to remove

Definition at line 1773 of file mx.c.

1774 {
1775  if (!m || !m->account)
1776  return -1;
1777 
1778  struct Account *a = m->account;
1780  mailbox_free(&m);
1781  if (STAILQ_EMPTY(&a->mailboxes))
1782  {
1784  }
1785  return 0;
1786 }
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
A group of associated Mailboxes.
Definition: account.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:36
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:60
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:94
#define STAILQ_EMPTY(head)
Definition: queue.h:345
bool neomutt_account_remove(struct NeoMutt *n, struct Account *a)
Remove an Account from the global list.
Definition: neomutt.c:105
+ Here is the call graph for this function:

◆ mx_access()

int mx_access ( const char *  path,
int  flags 
)

Wrapper for access, checks permissions on a given mailbox.

Parameters
pathPath of mailbox
flagsFlags, e.g. W_OK
Return values
0Success, allowed
<0Failure, not allowed

We may be interested in using ACL-style flags at some point, currently we use the normal access() flags.

Definition at line 183 of file mx.c.

184 {
185 #ifdef USE_IMAP
186  if (imap_path_probe(path, NULL) == MUTT_IMAP)
187  return imap_access(path);
188 #endif
189 
190  return access(path, flags);
191 }
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe()
Definition: imap.c:2344
int imap_access(const char *path)
Check permissions on an IMAP mailbox with a new connection.
Definition: imap.c:450
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_alloc_memory()

void mx_alloc_memory ( struct Mailbox m)

Create storage for the emails.

Parameters
mMailbox

Definition at line 1206 of file mx.c.

1207 {
1208  size_t s = MAX(sizeof(struct Email *), sizeof(int));
1209 
1210  if ((m->email_max + 25) * s < m->email_max * s)
1211  {
1212  mutt_error(_("Out of memory"));
1213  mutt_exit(1);
1214  }
1215 
1216  m->email_max += 25;
1217  if (m->emails)
1218  {
1219  mutt_mem_realloc(&m->emails, sizeof(struct Email *) * m->email_max);
1220  mutt_mem_realloc(&m->v2r, sizeof(int) * m->email_max);
1221  }
1222  else
1223  {
1224  m->emails = mutt_mem_calloc(m->email_max, sizeof(struct Email *));
1225  m->v2r = mutt_mem_calloc(m->email_max, sizeof(int));
1226  }
1227  for (int i = m->email_max - 25; i < m->email_max; i++)
1228  {
1229  m->emails[i] = NULL;
1230  m->v2r[i] = -1;
1231  }
1232 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
The envelope/body of an email.
Definition: email.h:37
#define _(a)
Definition: message.h:28
#define MAX(a, b)
Definition: memory.h:30
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
int email_max
Number of pointers in emails.
Definition: mailbox.h:100
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:137
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:101
#define mutt_error(...)
Definition: logging.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_check_empty()

int mx_check_empty ( const char *  path)

Is the mailbox empty.

Parameters
pathMailbox to check
Return values
1Mailbox is empty
0Mailbox contains mail
-1Error

Definition at line 1241 of file mx.c.

1242 {
1243  switch (mx_path_probe(path))
1244  {
1245  case MUTT_MBOX:
1246  case MUTT_MMDF:
1247  return mutt_file_check_empty(path);
1248  case MUTT_MH:
1249  return mh_check_empty(path);
1250  case MUTT_MAILDIR:
1251  return maildir_check_empty(path);
1252 #ifdef USE_IMAP
1253  case MUTT_IMAP:
1254  {
1255  int rc = imap_path_status(path, false);
1256  if (rc < 0)
1257  return -1;
1258  if (rc == 0)
1259  return 1;
1260  return 0;
1261  }
1262 #endif
1263  default:
1264  errno = EINVAL;
1265  return -1;
1266  }
1267  /* not reached */
1268 }
int imap_path_status(const char *path, bool queue)
Refresh the number of total and new messages.
Definition: imap.c:1181
&#39;Maildir&#39; Mailbox type
Definition: mailbox.h:51
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:49
&#39;MH&#39; Mailbox type
Definition: mailbox.h:50
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:48
int maildir_check_empty(const char *path)
Is the mailbox empty.
Definition: shared.c:1553
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1327
int mutt_file_check_empty(const char *path)
Is the mailbox empty.
Definition: file.c:1405
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
int mh_check_empty(const char *path)
Is mailbox empty.
Definition: shared.c:1593
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_fastclose_mailbox()

void mx_fastclose_mailbox ( struct Mailbox m)

free up memory associated with the Mailbox

Parameters
mMailbox

Definition at line 426 of file mx.c.

427 {
428  if (!m)
429  return;
430 
431  m->opened--;
432  if (m->opened != 0)
433  return;
434 
435  /* never announce that a mailbox we've just left has new mail.
436  * TODO: really belongs in mx_mbox_close, but this is a nice hook point */
437  if (!m->peekonly)
439 
440  if (m->mx_ops)
441  m->mx_ops->mbox_close(m);
442 
444  mutt_hash_free(&m->id_hash);
446 
447  if (m->emails)
448  {
449  for (int i = 0; i < m->msg_count; i++)
450  {
451  if (!m->emails[i])
452  break;
453  email_free(&m->emails[i]);
454  }
455  }
456 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int msg_count
Total number of messages.
Definition: mailbox.h:91
struct HashTable * label_hash
Hash Table for x-labels.
Definition: mailbox.h:129
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:447
bool peekonly
Just taking a glance, revert atime.
Definition: mailbox.h:117
struct HashTable * id_hash
Hash Table by msg id.
Definition: mailbox.h:127
int opened
Number of times mailbox is opened.
Definition: mailbox.h:132
struct HashTable * subj_hash
Hash Table by subject.
Definition: mailbox.h:128
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
int(* mbox_close)(struct Mailbox *m)
Close a Mailbox.
Definition: mx.h:179
void mutt_mailbox_set_notified(struct Mailbox *m)
Note when the user was last notified of new mail.
Definition: mutt_mailbox.c:300
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mx_get_ops()

const struct MxOps* mx_get_ops ( enum MailboxType  type)

Get mailbox operations.

Parameters
typeMailbox type
Return values
ptrMailbox function
NULLError

Definition at line 141 of file mx.c.

142 {
143  for (const struct MxOps **ops = mx_ops; *ops; ops++)
144  if ((*ops)->type == type)
145  return *ops;
146 
147  return NULL;
148 }
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
const struct MxOps * mx_ops[]
All the Mailbox backends.
Definition: mx.c:107
The Mailbox API.
Definition: mx.h:105
+ Here is the caller graph for this function:

◆ mx_tags_is_supported()

bool mx_tags_is_supported ( struct Mailbox m)

return true if mailbox support tagging

Parameters
mMailbox
Return values
trueTagging is supported

Definition at line 1317 of file mx.c.

1318 {
1319  return m && m->mx_ops->tags_commit && m->mx_ops->tags_edit;
1320 }
int(* tags_edit)(struct Mailbox *m, const char *tags, char *buf, size_t buflen)
Prompt and validate new messages tags.
Definition: mx.h:245
const struct MxOps * mx_ops
MXAPI callback functions.
Definition: mailbox.h:111
int(* tags_commit)(struct Mailbox *m, struct Email *e, char *buf)
Save the tags to a message.
Definition: mx.h:255
+ Here is the caller graph for this function:

Variable Documentation

◆ mx_ops

const struct MxOps* mx_ops[]

All the Mailbox backends.

Definition at line 107 of file mx.c.

◆ C_CatchupNewsgroup

unsigned char C_CatchupNewsgroup

Config: (nntp) Mark all articles as read when leaving a newsgroup.

Definition at line 37 of file config.c.

◆ C_KeepFlagged

bool C_KeepFlagged

Config: Don't move flagged messages from C_Spoolfile to C_Mbox.

Definition at line 83 of file mx.c.

◆ C_MboxType

unsigned char C_MboxType

Config: Default type for creating new mailboxes.

Definition at line 84 of file mx.c.

◆ C_Move

unsigned char C_Move

Config: Move emails from C_Spoolfile to C_Mbox when read.

Definition at line 85 of file mx.c.

◆ C_Trash

char* C_Trash

Config: Folder to put deleted emails.

Definition at line 86 of file mx.c.

◆ MboxTypeDef

struct EnumDef MboxTypeDef

Definition at line 98 of file mx.c.