sizeof(buf));
}
- if ((mx_get_magic(buf) <= 0)
+ enum MailboxType magic = mx_get_magic(buf);
+ if ((magic == MUTT_MAILBOX_ERROR) || (magic == MUTT_UNKNOWN)
#ifdef USE_IMAP
|| state.entry[menu->current].inferiors
#endif
unlock_realpath(ctx);
ctx->magic = mx_get_magic(ctx->path);
- if (ctx->magic == 0)
+ if (ctx->magic == MUTT_UNKNOWN)
{
mutt_error(_("Can't identify the contents of the compressed file"));
goto or_fail;
extern const char *magic_values[];
/**
- * enum MailboxTypes - Supported mailbox formats
+ * enum MailboxType - Supported mailbox formats
*/
-enum MailboxTypes
+enum MailboxType
{
- MUTT_MBOX = 1,
+ MUTT_MAILBOX_ERROR = -1,
+ MUTT_UNKNOWN = 0,
+ MUTT_MBOX,
MUTT_MMDF,
MUTT_MH,
MUTT_MAILDIR,
struct Menu *menu; /**< needed for pattern compilation */
- short magic; /**< mailbox type */
+ enum MailboxType magic; /**< mailbox type */
unsigned char rights[(RIGHTSMAX + 7) / 8]; /**< ACL bits */
else
#endif
mutt_expand_path(buf, buflen);
- if (mx_get_magic(buf) <= 0)
+
+ enum MailboxType magic = mx_get_magic(buf);
+ if ((magic == MUTT_MAILBOX_ERROR) || (magic == MUTT_UNKNOWN))
{
mutt_error(_("%s is not a mailbox."), buf);
return -1;
{
FILE *f = NULL;
bool rc = false;
- int typ;
- typ = mx_get_magic(path);
+ enum MailboxType magic = mx_get_magic(path);
- if (typ != MUTT_MBOX && typ != MUTT_MMDF)
+ if ((magic != MUTT_MBOX) && (magic != MUTT_MMDF))
return false;
f = fopen(path, "rb");
mutt_str_strfcpy(mailbox->path, path, sizeof(mailbox->path));
char *r = realpath(path, rp);
mutt_str_strfcpy(mailbox->realpath, r ? rp : path, sizeof(mailbox->realpath));
- mailbox->magic = 0;
+ mailbox->magic = MUTT_UNKNOWN;
return mailbox;
}
dirp = opendir(path);
if (!dirp)
{
- mailbox->magic = 0;
+ mailbox->magic = MUTT_UNKNOWN;
return 0;
}
else
#endif
if (stat(tmp->path, &sb) != 0 || (S_ISREG(sb.st_mode) && sb.st_size == 0) ||
- (!tmp->magic && (tmp->magic = mx_get_magic(tmp->path)) <= 0))
+ ((tmp->magic == MUTT_UNKNOWN) && (tmp->magic = mx_get_magic(tmp->path)) <= 0))
{
/* if the mailbox still doesn't exist, set the newly created flag to be
* ready for when it does. */
tmp->newly_created = true;
- tmp->magic = 0;
+ tmp->magic = MUTT_UNKNOWN;
tmp->size = 0;
return;
}
}
break;
#endif
+ default:; /* do nothing */
}
}
else if (CheckMboxSize && Context && Context->path)
int msg_flagged; /**< number of flagged messages */
bool notified; /**< user has been notified */
- short magic; /**< mailbox type */
+ enum MailboxType magic; /**< mailbox type */
bool newly_created; /**< mbox or mmdf just popped into existence */
time_t last_visited; /**< time of last exit from this mailbox */
time_t stats_last_checked; /**< mtime of mailbox the last time stats where checked. */
void maildir_flags(char *dest, size_t destlen, struct Header *hdr);
FILE * maildir_open_find_message(const char *folder, const char *msg, char **newname);
void maildir_parse_flags(struct Header *h, const char *path);
-struct Header *maildir_parse_message(int magic, const char *fname, bool is_old, struct Header *h);
-struct Header *maildir_parse_stream(int magic, FILE *f, const char *fname, bool is_old, struct Header *h);
+struct Header *maildir_parse_message(enum MailboxType magic, const char *fname, bool is_old, struct Header *h);
+struct Header *maildir_parse_stream(enum MailboxType magic, FILE *f, const char *fname, bool is_old, struct Header *h);
bool maildir_update_flags(struct Context *ctx, struct Header *o, struct Header *n);
bool mh_mailbox(struct Mailbox *mailbox, bool check_stats);
* Actually parse a maildir message. This may also be used to fill
* out a fake header structure generated by lazy maildir parsing.
*/
-struct Header *maildir_parse_stream(int magic, FILE *f, const char *fname,
+struct Header *maildir_parse_stream(enum MailboxType magic, FILE *f, const char *fname,
bool is_old, struct Header *h)
{
struct stat st;
* This may also be used to fill out a fake header structure generated by lazy
* maildir parsing.
*/
-struct Header *maildir_parse_message(int magic, const char *fname, bool is_old,
+struct Header *maildir_parse_message(enum MailboxType magic, const char *fname, bool is_old,
struct Header *h)
{
FILE *f = fopen(fname, "r");
char tmp[PATH_MAX];
int ret = 0;
int rc;
- int magic = 0;
- magic = mx_get_magic(s);
+ enum MailboxType magic = mx_get_magic(s);
#ifdef USE_POP
if (magic == MUTT_POP)
}
#endif
- if (magic > 0 && !mx_access(s, W_OK))
+ if ((magic != MUTT_MAILBOX_ERROR) && (magic != MUTT_UNKNOWN) && !mx_access(s, W_OK))
{
if (Confirmappend)
{
if (stat(s, st) != -1)
{
- if (magic == -1)
+ if (magic == MUTT_MAILBOX_ERROR)
{
mutt_error(_("%s is not a mailbox!"), s);
return 1;
* @retval ptr Mailbox function
* @retval NULL Error
*/
-struct MxOps *mx_get_ops(int magic)
+struct MxOps *mx_get_ops(enum MailboxType magic)
{
switch (magic)
{
* @retval -1 Error, can't identify mailbox
* @retval >0 Success, e.g. #MUTT_IMAP
*/
-int mx_get_magic(const char *path)
+enum MailboxType mx_get_magic(const char *path)
{
- struct stat st;
- int magic = 0;
- FILE *f = NULL;
+ if (!path)
+ return MUTT_UNKNOWN;
#ifdef USE_IMAP
if (mx_is_imap(path))
return MUTT_NOTMUCH;
#endif
+ struct stat st;
+ enum MailboxType magic = MUTT_UNKNOWN;
+ FILE *f = NULL;
+
if (stat(path, &st) == -1)
{
mutt_debug(1, "unable to stat %s: %s (errno %d).\n", path, strerror(errno), errno);
else
{
mutt_debug(1, "unable to open file %s for reading.\n", path);
- return -1;
+ return MUTT_MAILBOX_ERROR;
}
#ifdef USE_COMPRESSED
/* If there are no other matches, see if there are any
* compress hooks that match */
- if ((magic == 0) && mutt_comp_can_read(path))
+ if ((magic == MUTT_UNKNOWN) && mutt_comp_can_read(path))
return MUTT_COMPRESSED;
#endif
return magic;
ctx->append = true;
ctx->magic = mx_get_magic(ctx->path);
- if (ctx->magic == 0)
+ if (ctx->magic == MUTT_UNKNOWN)
{
mutt_error(_("%s is not a mailbox."), ctx->path);
return -1;
}
- if (ctx->magic < 0)
+ if (ctx->magic == MUTT_MAILBOX_ERROR)
{
if (stat(ctx->path, &sb) == -1)
{
ctx->magic = mx_get_magic(path);
ctx->mx_ops = mx_get_ops(ctx->magic);
- if (ctx->magic <= 0 || !ctx->mx_ops)
+ if ((ctx->magic == MUTT_UNKNOWN) || (ctx->magic == MUTT_MAILBOX_ERROR) || !ctx->mx_ops)
{
- if (ctx->magic == -1)
+ if (ctx->magic == MUTT_MAILBOX_ERROR)
mutt_perror(path);
- else if (ctx->magic == 0 || !ctx->mx_ops)
+ else if (ctx->magic == MUTT_UNKNOWN || !ctx->mx_ops)
mutt_error(_("%s is not a mailbox."), path);
mx_fastclose_mailbox(ctx);
void mx_update_context(struct Context *ctx, int new_messages);
void mx_update_tables(struct Context *ctx, bool committing);
-struct MxOps *mx_get_ops(int magic);
+struct MxOps *mx_get_ops(enum MailboxType magic);
/* This variable is backing for a config item */
WHERE short MboxType; ///< Config: Default type for creating new mailboxes
void mx_fastclose_mailbox(struct Context *ctx);
-int mx_get_magic(const char *path);
+enum MailboxType mx_get_magic(const char *path);
int mx_check_mailbox(struct Context *ctx, int *index_hint);
#ifdef USE_IMAP
bool mx_is_imap(const char *p);
{
char *folder; /**< Location of the email */
char *oldpath;
- char *virtual_id; /**< Unique Notmuch Id */
- int magic; /**< Type of mailbox the email is in */
+ char *virtual_id; /**< Unique Notmuch Id */
+ enum MailboxType magic; /**< Type of mailbox the email is in */
};
/**