mirror of https://github.com/djcb/mu.git
* mu_msg_flags_from_file => mu_msg_file_get_flags_from_path
This commit is contained in:
parent
2d0959ec63
commit
372e245fc7
|
@ -154,99 +154,3 @@ mu_msg_flags_foreach (MuMsgFlagsForeachFunc func, gpointer user_data)
|
||||||
func (ALL_FLAGS[i], user_data);
|
func (ALL_FLAGS[i], user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* is this a 'new' msg or a 'cur' msg?; if new, we return
|
|
||||||
* (in info) a ptr to the info part
|
|
||||||
*/
|
|
||||||
enum _MsgType {
|
|
||||||
MSG_TYPE_CUR,
|
|
||||||
MSG_TYPE_NEW,
|
|
||||||
MSG_TYPE_OTHER
|
|
||||||
};
|
|
||||||
typedef enum _MsgType MsgType;
|
|
||||||
|
|
||||||
|
|
||||||
static MsgType
|
|
||||||
check_msg_type (const char* path, char **info)
|
|
||||||
{
|
|
||||||
char *dir, *file;
|
|
||||||
MsgType mtype;
|
|
||||||
|
|
||||||
/* try to find the info part */
|
|
||||||
/* note that we can use either the ':' or '!' as separator;
|
|
||||||
* the former is the official, but as it does not work on e.g. VFAT
|
|
||||||
* file systems, some Maildir implementations use the latter instead
|
|
||||||
* (or both). For example, Tinymail/modest does this. The python
|
|
||||||
* documentation at http://docs.python.org/lib/mailbox-maildir.html
|
|
||||||
* mentions the '!' as well as a 'popular choice'
|
|
||||||
*/
|
|
||||||
|
|
||||||
*info = NULL;
|
|
||||||
dir = g_path_get_dirname (path);
|
|
||||||
file = g_path_get_basename (path);
|
|
||||||
|
|
||||||
if (!(*info = strrchr(file, ':')))
|
|
||||||
*info = strrchr (file, '!'); /* Tinymail */
|
|
||||||
if (*info)
|
|
||||||
++(*info); /* skip the ':' or '!' */
|
|
||||||
|
|
||||||
if (g_str_has_suffix (dir, G_DIR_SEPARATOR_S "cur")) {
|
|
||||||
if (!*info)
|
|
||||||
g_debug ("'cur' file, but no info part: %s", path);
|
|
||||||
mtype = MSG_TYPE_CUR;
|
|
||||||
} else if (g_str_has_suffix (dir, G_DIR_SEPARATOR_S "new")) {
|
|
||||||
if (*info)
|
|
||||||
g_debug ("'new' file, ignoring info part: %s", path);
|
|
||||||
mtype = MSG_TYPE_NEW;
|
|
||||||
} else
|
|
||||||
mtype = MSG_TYPE_OTHER; /* file has been added explicitly as
|
|
||||||
a single message */
|
|
||||||
if (*info)
|
|
||||||
*info = g_strdup (*info);
|
|
||||||
|
|
||||||
g_free (dir);
|
|
||||||
g_free (file);
|
|
||||||
|
|
||||||
return mtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
MuMsgFlags
|
|
||||||
mu_msg_flags_from_file (const char* path)
|
|
||||||
{
|
|
||||||
MuMsgFlags flags;
|
|
||||||
MsgType mtype;
|
|
||||||
char *info = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (path, MU_MSG_FLAG_NONE);
|
|
||||||
g_return_val_if_fail (!g_str_has_suffix(path,G_DIR_SEPARATOR_S),
|
|
||||||
MU_MSG_FLAG_NONE);
|
|
||||||
|
|
||||||
mtype = check_msg_type (path, &info);
|
|
||||||
if (mtype == MSG_TYPE_NEW) { /* we ignore any new-msg flags */
|
|
||||||
g_free (info);
|
|
||||||
return MU_MSG_FLAG_NEW;
|
|
||||||
}
|
|
||||||
|
|
||||||
flags = MU_MSG_FLAG_NONE;
|
|
||||||
if (mtype == MSG_TYPE_CUR || mtype == MSG_TYPE_OTHER) {
|
|
||||||
char *cursor = info;
|
|
||||||
/* only support the "2," format */
|
|
||||||
if (cursor && cursor[0]=='2' && cursor[1]==',') {
|
|
||||||
cursor += 2; /* jump past 2, */
|
|
||||||
for (; *cursor; ++cursor)
|
|
||||||
switch (*cursor) {
|
|
||||||
case 'P': flags|= MU_MSG_FLAG_PASSED; break;
|
|
||||||
case 'T': flags|= MU_MSG_FLAG_TRASHED; break;
|
|
||||||
case 'R': flags|= MU_MSG_FLAG_REPLIED; break;
|
|
||||||
case 'S': flags|= MU_MSG_FLAG_SEEN; break;
|
|
||||||
case 'D': flags|= MU_MSG_FLAG_DRAFT;break;
|
|
||||||
case 'F': flags|= MU_MSG_FLAG_FLAGGED; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_free (info);
|
|
||||||
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
|
@ -128,8 +128,6 @@ char mu_msg_flag_char (MuMsgFlags flag) G_GNUC_CONST;
|
||||||
const char* mu_msg_flag_name (MuMsgFlags flag) G_GNUC_CONST;
|
const char* mu_msg_flag_name (MuMsgFlags flag) G_GNUC_CONST;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef void (*MuMsgFlagsForeachFunc)
|
typedef void (*MuMsgFlagsForeachFunc)
|
||||||
(MuMsgFlags flag, gpointer user_data);
|
(MuMsgFlags flag, gpointer user_data);
|
||||||
|
|
||||||
|
@ -142,22 +140,6 @@ typedef void (*MuMsgFlagsForeachFunc)
|
||||||
void mu_msg_flags_foreach (MuMsgFlagsForeachFunc func, gpointer user_data);
|
void mu_msg_flags_foreach (MuMsgFlagsForeachFunc func, gpointer user_data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* logically OR'ed. Note that the file does not have to exist; the
|
|
||||||
* flags are based on the name only.
|
|
||||||
*
|
|
||||||
* @param pathname of a mailfile; it does not have to refer to an
|
|
||||||
* actual message
|
|
||||||
*
|
|
||||||
* @return the flags, or MU_MSG_FILE_FLAG_UNKNOWN in case of error
|
|
||||||
*/
|
|
||||||
MuMsgFlags mu_msg_flags_from_file (const char* pathname) G_GNUC_PURE;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* is the message flag a file flag? ie. encoded in the filename
|
* is the message flag a file flag? ie. encoded in the filename
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue