* mu-msg-flags: overhaul; cleaned up things, and should be a bit faster

This commit is contained in:
Dirk-Jan C. Binnema
2010-11-14 16:40:43 +02:00
parent fdc67a021b
commit ece60f2e82
2 changed files with 138 additions and 90 deletions

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -24,32 +24,51 @@
G_BEGIN_DECLS
enum _MuMsgFlags {
MU_MSG_FLAG_UNKNOWN = 0,
MU_MSG_FLAG_NONE = 1 << 0,
/* the MU_MSG_FLAG_-flags are retrieved from the filename of
* the message, as per the maildir spec:
* http://cr.yp.to/proto/maildir.html not all (possibly not any) mail
* clients respect this fully -- therefore, we map these flags to
* MU_MSG_FLAG values.
*
* the other flags are determined from the contents of the
* message. Note that these flags are far from orthogonal,
* unfortunately.
*
*/
enum _MuMsgFlags {
MU_MSG_FLAG_NONE = 0,
/* these we get from the file */
MU_MSG_FLAG_NEW = 1 << 1,
MU_MSG_FLAG_SEEN = 1 << 2,
MU_MSG_FLAG_UNREAD = 1 << 3,
MU_MSG_FLAG_REPLIED = 1 << 4,
MU_MSG_FLAG_FLAGGED = 1 << 5,
MU_MSG_FLAG_TRASHED = 1 << 6,
MU_MSG_FLAG_DRAFT = 1 << 7,
MU_MSG_FLAG_PASSED = 1 << 8,
/* unlike the other MAILDIR flags, the NEW flag is not
* determined by the file name but by the dir: if the message
* is in the 'new' directory, it's considered... new */
MU_MSG_FLAG_NEW = 1 << 0,
/* "P"->resent,forwarded,bounced message */
MU_MSG_FLAG_PASSED = 1 << 1,
/* "R"->replied message */
MU_MSG_FLAG_REPLIED = 1 << 2,
/* "S"->seen message */
MU_MSG_FLAG_SEEN = 1 << 3,
/* "T"->trashed message */
MU_MSG_FLAG_TRASHED = 1 << 4,
/* "D"->draft message */
MU_MSG_FLAG_DRAFT = 1 << 5,
/* "F"->flagged message */
MU_MSG_FLAG_FLAGGED = 1 << 6,
/* these we get from the contents */
MU_MSG_FLAG_SIGNED = 1 << 10,
MU_MSG_FLAG_ENCRYPTED = 1 << 11,
MU_MSG_FLAG_HAS_ATTACH = 1 << 12
/* any new fields go here */
/* so the existing numbers stay valid note that we're also */
/* using these numbers in the database, so they should not change */
/* "Z"->signed message */
MU_MSG_FLAG_SIGNED = 1 << 7,
/* "X"->encrypted message */
MU_MSG_FLAG_ENCRYPTED = 1 << 8,
/* "A"->message has attachment */
MU_MSG_FLAG_HAS_ATTACH = 1 << 9
};
typedef enum _MuMsgFlags MuMsgFlags;
/**
/**
* convert the char-per-flag description into a MuMsgFlags value; the characters
* D=draft,F=flagged,N=new,P=passed,R=replied,S=seen,T=trashed
* a=has-attachment,s=signed, x=encrypted
@ -61,7 +80,7 @@ typedef enum _MuMsgFlags MuMsgFlags;
*/
MuMsgFlags mu_msg_flags_from_str (const char* str) G_GNUC_PURE;
/**
/**
* convert the char-per-flag description into a MuMsgFlags value
*
* @param c a character
@ -70,7 +89,7 @@ MuMsgFlags mu_msg_flags_from_str (const char* str) G_GNUC_PURE;
*/
MuMsgFlags mu_msg_flags_from_char (char c) G_GNUC_CONST;
/**
/**
* get a string for a given set of flags, OR'ed in
* @param flags; one character per flag:
* D=draft,F=flagged,N=new,P=passed,R=replied,S=seen,T=trashed
@ -85,7 +104,17 @@ MuMsgFlags mu_msg_flags_from_char (char c) G_GNUC_CONST;
*/
const char* mu_msg_flags_to_str_s (MuMsgFlags flags) G_GNUC_CONST;
/**
/**
* get the character for some msg flag, or 0 in case it's not found
*
* @param flags on specific flag (not OR'ed)
*
* @return the char for this flag, or 0 if not found
*/
char mu_msg_flags_char (MuMsgFlags flag);
/**
* get the Maildir flags from a mailfile. The flags are as specified
* in http://cr.yp.to/proto/maildir.html, plus MU_MSG_FLAG_NEW for
* new messages, ie the ones that live in new/. The flags are
@ -99,7 +128,7 @@ const char* mu_msg_flags_to_str_s (MuMsgFlags flags) G_GNUC_CONST;
*/
MuMsgFlags mu_msg_flags_from_file (const char* pathname) G_GNUC_PURE;
/**
/**
* is the message flag a file flag? ie. encoded in the filename
*
* @param flag the flag to check; note, this should be a single flag