mirror of https://github.com/djcb/mu.git
* MuMsgFlags => MuFlags
This commit is contained in:
parent
bf66680595
commit
a571a3f877
|
@ -89,7 +89,7 @@ SCM_DEFINE (msg_move, "mu:msg:move-to-maildir", 2, 0, 0,
|
||||||
GError *err;
|
GError *err;
|
||||||
MuMsgWrapper *msgwrap;
|
MuMsgWrapper *msgwrap;
|
||||||
gboolean rv;
|
gboolean rv;
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
|
|
||||||
SCM_ASSERT (mu_guile_scm_is_msg(MSG), MSG, SCM_ARG1, FUNC_NAME);
|
SCM_ASSERT (mu_guile_scm_is_msg(MSG), MSG, SCM_ARG1, FUNC_NAME);
|
||||||
SCM_ASSERT (scm_is_string (TARGETMDIR), TARGETMDIR, SCM_ARG2, FUNC_NAME);
|
SCM_ASSERT (scm_is_string (TARGETMDIR), TARGETMDIR, SCM_ARG2, FUNC_NAME);
|
||||||
|
@ -194,20 +194,20 @@ SCM_DEFINE (msg_prio, "mu:msg:priority", 1, 0, 0,
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
struct _FlagData {
|
struct _FlagData {
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
SCM lst;
|
SCM lst;
|
||||||
};
|
};
|
||||||
typedef struct _FlagData FlagData;
|
typedef struct _FlagData FlagData;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_flag (MuMsgFlags flag, FlagData *fdata)
|
check_flag (MuFlags flag, FlagData *fdata)
|
||||||
{
|
{
|
||||||
if (fdata->flags & flag) {
|
if (fdata->flags & flag) {
|
||||||
SCM item;
|
SCM item;
|
||||||
char *flagsym;
|
char *flagsym;
|
||||||
|
|
||||||
flagsym = g_strconcat ("mu:", mu_msg_flag_name(flag), NULL);
|
flagsym = g_strconcat ("mu:", mu_flag_name(flag), NULL);
|
||||||
item = scm_list_1 (scm_from_locale_symbol(flagsym));
|
item = scm_list_1 (scm_from_locale_symbol(flagsym));
|
||||||
g_free (flagsym);
|
g_free (flagsym);
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ SCM_DEFINE (msg_flags, "mu:msg:flags", 1, 0, 0,
|
||||||
|
|
||||||
fdata.flags = mu_msg_get_flags (msgwrap->_msg);
|
fdata.flags = mu_msg_get_flags (msgwrap->_msg);
|
||||||
fdata.lst = SCM_EOL;
|
fdata.lst = SCM_EOL;
|
||||||
mu_msg_flags_foreach ((MuMsgFlagsForeachFunc)check_flag,
|
mu_flags_foreach ((MuFlagsForeachFunc)check_flag,
|
||||||
&fdata);
|
&fdata);
|
||||||
|
|
||||||
return fdata.lst;
|
return fdata.lst;
|
||||||
|
@ -517,17 +517,17 @@ define_symbols (void)
|
||||||
scm_c_define ("mu:normal", scm_from_int(MU_MSG_PRIO_NORMAL));
|
scm_c_define ("mu:normal", scm_from_int(MU_MSG_PRIO_NORMAL));
|
||||||
|
|
||||||
/* message flags */
|
/* message flags */
|
||||||
scm_c_define ("mu:new", scm_from_int(MU_MSG_FLAG_NEW));
|
scm_c_define ("mu:new", scm_from_int(MU_FLAG_NEW));
|
||||||
scm_c_define ("mu:passed", scm_from_int(MU_MSG_FLAG_PASSED));
|
scm_c_define ("mu:passed", scm_from_int(MU_FLAG_PASSED));
|
||||||
scm_c_define ("mu:replied", scm_from_int(MU_MSG_FLAG_REPLIED));
|
scm_c_define ("mu:replied", scm_from_int(MU_FLAG_REPLIED));
|
||||||
scm_c_define ("mu:seen", scm_from_int(MU_MSG_FLAG_SEEN));
|
scm_c_define ("mu:seen", scm_from_int(MU_FLAG_SEEN));
|
||||||
scm_c_define ("mu:trashed", scm_from_int(MU_MSG_FLAG_TRASHED));
|
scm_c_define ("mu:trashed", scm_from_int(MU_FLAG_TRASHED));
|
||||||
scm_c_define ("mu:draft", scm_from_int(MU_MSG_FLAG_DRAFT));
|
scm_c_define ("mu:draft", scm_from_int(MU_FLAG_DRAFT));
|
||||||
scm_c_define ("mu:flagged", scm_from_int(MU_MSG_FLAG_FLAGGED));
|
scm_c_define ("mu:flagged", scm_from_int(MU_FLAG_FLAGGED));
|
||||||
scm_c_define ("mu:unread", scm_from_int(MU_MSG_FLAG_UNREAD));
|
scm_c_define ("mu:unread", scm_from_int(MU_FLAG_UNREAD));
|
||||||
scm_c_define ("mu:signed", scm_from_int(MU_MSG_FLAG_SIGNED));
|
scm_c_define ("mu:signed", scm_from_int(MU_FLAG_SIGNED));
|
||||||
scm_c_define ("mu:encrypted", scm_from_int(MU_MSG_FLAG_ENCRYPTED));
|
scm_c_define ("mu:encrypted", scm_from_int(MU_FLAG_ENCRYPTED));
|
||||||
scm_c_define ("mu:has-attach", scm_from_int(MU_MSG_FLAG_HAS_ATTACH));
|
scm_c_define ("mu:has-attach", scm_from_int(MU_FLAG_HAS_ATTACH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,8 @@ libmu_la_SOURCES= \
|
||||||
mu-container.h \
|
mu-container.h \
|
||||||
mu-date.c \
|
mu-date.c \
|
||||||
mu-date.h \
|
mu-date.h \
|
||||||
|
mu-flags.h \
|
||||||
|
mu-flags.c \
|
||||||
mu-index.c \
|
mu-index.c \
|
||||||
mu-index.h \
|
mu-index.h \
|
||||||
mu-log.c \
|
mu-log.c \
|
||||||
|
@ -76,8 +78,6 @@ libmu_la_SOURCES= \
|
||||||
mu-msg-fields.h \
|
mu-msg-fields.h \
|
||||||
mu-msg-file.c \
|
mu-msg-file.c \
|
||||||
mu-msg-file.h \
|
mu-msg-file.h \
|
||||||
mu-msg-flags.c \
|
|
||||||
mu-msg-flags.h \
|
|
||||||
mu-msg-iter.cc \
|
mu-msg-iter.cc \
|
||||||
mu-msg-iter.h \
|
mu-msg-iter.h \
|
||||||
mu-msg-part.c \
|
mu-msg-part.c \
|
||||||
|
|
|
@ -550,7 +550,7 @@ display_field (MuMsg *msg, MuMsgFieldId mfid)
|
||||||
return mu_msg_prio_name ((MuMsgPrio)val);
|
return mu_msg_prio_name ((MuMsgPrio)val);
|
||||||
} else if (mfid == MU_MSG_FIELD_ID_FLAGS) {
|
} else if (mfid == MU_MSG_FIELD_ID_FLAGS) {
|
||||||
val = mu_msg_get_field_numeric (msg, mfid);
|
val = mu_msg_get_field_numeric (msg, mfid);
|
||||||
return mu_str_flags_s ((MuMsgFlags)val);
|
return mu_str_flags_s ((MuFlags)val);
|
||||||
} else /* as string */
|
} else /* as string */
|
||||||
return mu_msg_get_field_string (msg, mfid);
|
return mu_msg_get_field_string (msg, mfid);
|
||||||
|
|
||||||
|
|
10
src/mu-cmd.c
10
src/mu-cmd.c
|
@ -37,7 +37,7 @@
|
||||||
#include "mu-maildir.h"
|
#include "mu-maildir.h"
|
||||||
#include "mu-contacts.h"
|
#include "mu-contacts.h"
|
||||||
#include "mu-runtime.h"
|
#include "mu-runtime.h"
|
||||||
#include "mu-msg-flags.h"
|
#include "mu-flags.h"
|
||||||
#include "mu-store.h"
|
#include "mu-store.h"
|
||||||
|
|
||||||
#define VIEW_TERMINATOR '\f' /* form-feed */
|
#define VIEW_TERMINATOR '\f' /* form-feed */
|
||||||
|
@ -283,7 +283,7 @@ mu_cmd_mkdir (MuConfig *opts)
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
mv_check_params (MuConfig *opts, MuMsgFlags *flags)
|
mv_check_params (MuConfig *opts, MuFlags *flags)
|
||||||
{
|
{
|
||||||
if (!opts->params[1] || !opts->params[2]) {
|
if (!opts->params[1] || !opts->params[2]) {
|
||||||
g_warning ("usage: mu mv [--flags=<flags>] <sourcefile> "
|
g_warning ("usage: mu mv [--flags=<flags>] <sourcefile> "
|
||||||
|
@ -293,9 +293,9 @@ mv_check_params (MuConfig *opts, MuMsgFlags *flags)
|
||||||
|
|
||||||
/* FIXME: check for invalid flags */
|
/* FIXME: check for invalid flags */
|
||||||
if (!opts->flagstr)
|
if (!opts->flagstr)
|
||||||
*flags = MU_MSG_FLAG_INVALID; /* ie., ignore flags */
|
*flags = MU_FLAG_INVALID; /* ie., ignore flags */
|
||||||
else
|
else
|
||||||
*flags = mu_msg_flags_from_str (opts->flagstr);
|
*flags = mu_flags_from_str (opts->flagstr, MU_FLAG_TYPE_ANY);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ mu_cmd_mv (MuConfig *opts)
|
||||||
{
|
{
|
||||||
GError *err;
|
GError *err;
|
||||||
gchar *fullpath;
|
gchar *fullpath;
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
|
|
||||||
if (!mv_check_params (opts, &flags))
|
if (!mv_check_params (opts, &flags))
|
||||||
return MU_ERROR_IN_PARAMETERS;
|
return MU_ERROR_IN_PARAMETERS;
|
||||||
|
|
|
@ -0,0 +1,197 @@
|
||||||
|
/*
|
||||||
|
** Copyright (C) 2011 <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
|
||||||
|
** Free Software Foundation; either version 3, or (at your option) any
|
||||||
|
** later version.
|
||||||
|
**
|
||||||
|
** 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, write to the Free Software Foundation,
|
||||||
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
#include "mu-flags.h"
|
||||||
|
|
||||||
|
struct _FlagInfo {
|
||||||
|
MuFlags flag;
|
||||||
|
char kar;
|
||||||
|
const char *name;
|
||||||
|
MuFlagType flag_type;
|
||||||
|
};
|
||||||
|
typedef struct _FlagInfo FlagInfo;
|
||||||
|
|
||||||
|
static const FlagInfo FLAG_INFO[] = {
|
||||||
|
|
||||||
|
/* NOTE: order of this is significant, due to optimizations
|
||||||
|
* below */
|
||||||
|
|
||||||
|
{ MU_FLAG_DRAFT, 'D', "draft", MU_FLAG_TYPE_MAILFILE },
|
||||||
|
{ MU_FLAG_FLAGGED, 'F', "flagged", MU_FLAG_TYPE_MAILFILE },
|
||||||
|
{ MU_FLAG_PASSED, 'P', "passed", MU_FLAG_TYPE_MAILFILE },
|
||||||
|
{ MU_FLAG_REPLIED, 'R', "replied", MU_FLAG_TYPE_MAILFILE },
|
||||||
|
{ MU_FLAG_SEEN, 'S', "seen", MU_FLAG_TYPE_MAILFILE },
|
||||||
|
{ MU_FLAG_TRASHED, 'T', "trashed", MU_FLAG_TYPE_MAILFILE },
|
||||||
|
|
||||||
|
{ MU_FLAG_NEW, 'N', "new", MU_FLAG_TYPE_MAILDIR },
|
||||||
|
{ MU_FLAG_UNREAD, 'U', "unread", MU_FLAG_TYPE_PSEUDO },
|
||||||
|
|
||||||
|
{ MU_FLAG_SIGNED, 's', "signed", MU_FLAG_TYPE_CONTENT },
|
||||||
|
{ MU_FLAG_ENCRYPTED, 'x', "encrypted", MU_FLAG_TYPE_CONTENT },
|
||||||
|
{ MU_FLAG_HAS_ATTACH, 'a', "attach", MU_FLAG_TYPE_CONTENT }
|
||||||
|
};
|
||||||
|
|
||||||
|
/* does not use FLAG_INFO, optimized */
|
||||||
|
MuFlagType
|
||||||
|
mu_flag_type (MuFlags flag)
|
||||||
|
{
|
||||||
|
if (flag >= MU_FLAG_DRAFT && flag <= MU_FLAG_TRASHED)
|
||||||
|
return MU_FLAG_TYPE_MAILFILE;
|
||||||
|
if (flag == MU_FLAG_NEW)
|
||||||
|
return MU_FLAG_TYPE_MAILDIR;
|
||||||
|
if (flag == MU_FLAG_UNREAD)
|
||||||
|
return MU_FLAG_TYPE_PSEUDO;
|
||||||
|
if (flag >= MU_FLAG_SIGNED && flag <= MU_FLAG_HAS_ATTACH)
|
||||||
|
return MU_FLAG_TYPE_CONTENT;
|
||||||
|
|
||||||
|
return MU_FLAG_TYPE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* does not use FLAG_INFO, optimized */
|
||||||
|
char
|
||||||
|
mu_flag_char (MuFlags flag)
|
||||||
|
{
|
||||||
|
switch (flag) {
|
||||||
|
|
||||||
|
case MU_FLAG_DRAFT: return 'D';
|
||||||
|
case MU_FLAG_FLAGGED: return 'F';
|
||||||
|
case MU_FLAG_PASSED: return 'P';
|
||||||
|
case MU_FLAG_REPLIED: return 'R';
|
||||||
|
case MU_FLAG_SEEN: return 'S';
|
||||||
|
case MU_FLAG_TRASHED: return 'T';
|
||||||
|
|
||||||
|
case MU_FLAG_NEW: return 'N';
|
||||||
|
case MU_FLAG_UNREAD: return 'U';
|
||||||
|
|
||||||
|
case MU_FLAG_SIGNED: return 's';
|
||||||
|
case MU_FLAG_ENCRYPTED: return 'x';
|
||||||
|
case MU_FLAG_HAS_ATTACH: return 'a';
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_message ("unsupported flag %u", flag);
|
||||||
|
g_return_val_if_reached (0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static MuFlags
|
||||||
|
mu_flag_from_char (char kar)
|
||||||
|
{
|
||||||
|
switch (kar) {
|
||||||
|
|
||||||
|
case 'D': return MU_FLAG_DRAFT;
|
||||||
|
case 'F': return MU_FLAG_FLAGGED;
|
||||||
|
case 'P': return MU_FLAG_PASSED;
|
||||||
|
case 'R': return MU_FLAG_REPLIED;
|
||||||
|
case 'S': return MU_FLAG_SEEN;
|
||||||
|
case 'T': return MU_FLAG_TRASHED;
|
||||||
|
|
||||||
|
case 'N': return MU_FLAG_NEW;
|
||||||
|
case 'U': return MU_FLAG_UNREAD;
|
||||||
|
|
||||||
|
case 's': return MU_FLAG_SIGNED;
|
||||||
|
case 'x': return MU_FLAG_ENCRYPTED;
|
||||||
|
case 'a': return MU_FLAG_HAS_ATTACH;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_message ("unsupported char %c", kar);
|
||||||
|
g_return_val_if_reached (MU_FLAG_INVALID);
|
||||||
|
return MU_FLAG_INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* does not use FLAG_INFO, optimized */
|
||||||
|
const char*
|
||||||
|
mu_flag_name (MuFlags flag)
|
||||||
|
{
|
||||||
|
switch (flag) {
|
||||||
|
case MU_FLAG_DRAFT: return "draft";
|
||||||
|
case MU_FLAG_FLAGGED: return "flagged";
|
||||||
|
case MU_FLAG_PASSED: return "passed";
|
||||||
|
case MU_FLAG_REPLIED: return "replied";
|
||||||
|
case MU_FLAG_SEEN: return "seen";
|
||||||
|
case MU_FLAG_TRASHED: return "trashed";
|
||||||
|
|
||||||
|
case MU_FLAG_NEW: return "new";
|
||||||
|
case MU_FLAG_UNREAD: return "unread";
|
||||||
|
|
||||||
|
case MU_FLAG_SIGNED: return "signed";
|
||||||
|
case MU_FLAG_ENCRYPTED: return "encrypted";
|
||||||
|
case MU_FLAG_HAS_ATTACH: return "attach";
|
||||||
|
default:
|
||||||
|
g_return_val_if_reached (NULL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char*
|
||||||
|
mu_flags_to_str_s (MuFlags flags, MuFlagType types)
|
||||||
|
{
|
||||||
|
unsigned u,v;
|
||||||
|
static char str[sizeof(FLAG_INFO) + 1];
|
||||||
|
|
||||||
|
for (u = 0, v = 0; u != G_N_ELEMENTS(FLAG_INFO); ++u)
|
||||||
|
if (flags & FLAG_INFO[u].flag &&
|
||||||
|
types & FLAG_INFO[u].flag_type)
|
||||||
|
str[v++] = FLAG_INFO[u].kar;
|
||||||
|
str[v] = '\0';
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MuFlags
|
||||||
|
mu_flags_from_str (const char *str, MuFlagType types)
|
||||||
|
{
|
||||||
|
const char *cur;
|
||||||
|
MuFlags flag;
|
||||||
|
|
||||||
|
g_return_val_if_fail (str, MU_FLAG_INVALID);
|
||||||
|
|
||||||
|
for (cur = str, flag = MU_FLAG_NONE; *cur; ++cur) {
|
||||||
|
|
||||||
|
MuFlags f;
|
||||||
|
|
||||||
|
f = mu_flag_from_char (*cur);
|
||||||
|
if (mu_flag_type (f) & types)
|
||||||
|
flag |= f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
mu_flags_foreach (MuFlagsForeachFunc func, gpointer user_data)
|
||||||
|
{
|
||||||
|
unsigned u;
|
||||||
|
|
||||||
|
g_return_if_fail (func);
|
||||||
|
|
||||||
|
for (u = 0; u != G_N_ELEMENTS(FLAG_INFO); ++u)
|
||||||
|
func (FLAG_INFO[u].flag, user_data);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
** Copyright (C) 2011 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
|
||||||
|
** Free Software Foundation; either version 3, or (at your option) any
|
||||||
|
** later version.
|
||||||
|
**
|
||||||
|
** 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, write to the Free Software Foundation,
|
||||||
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __MU_FLAGS_H__
|
||||||
|
#define __MU_FLAGS_H__
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
enum _MuFlags {
|
||||||
|
MU_FLAG_NONE = 0,
|
||||||
|
|
||||||
|
MU_FLAG_DRAFT = 1 << 0,
|
||||||
|
MU_FLAG_FLAGGED = 1 << 1,
|
||||||
|
MU_FLAG_PASSED = 1 << 2,
|
||||||
|
MU_FLAG_REPLIED = 1 << 3,
|
||||||
|
MU_FLAG_SEEN = 1 << 4,
|
||||||
|
MU_FLAG_TRASHED = 1 << 5,
|
||||||
|
|
||||||
|
MU_FLAG_NEW = 1 << 6,
|
||||||
|
MU_FLAG_UNREAD = 1 << 7,
|
||||||
|
MU_FLAG_SIGNED = 1 << 8,
|
||||||
|
MU_FLAG_ENCRYPTED = 1 << 9,
|
||||||
|
MU_FLAG_HAS_ATTACH = 1 << 10,
|
||||||
|
};
|
||||||
|
typedef enum _MuFlags MuFlags;
|
||||||
|
|
||||||
|
#define MU_FLAG_INVALID ((unsigned)-1)
|
||||||
|
|
||||||
|
enum _MuFlagType {
|
||||||
|
MU_FLAG_TYPE_MAILFILE = 1 << 0,
|
||||||
|
MU_FLAG_TYPE_MAILDIR = 1 << 1,
|
||||||
|
MU_FLAG_TYPE_PSEUDO = 1 << 2,
|
||||||
|
MU_FLAG_TYPE_CONTENT = 1 << 3,
|
||||||
|
};
|
||||||
|
typedef enum _MuFlagType MuFlagType;
|
||||||
|
|
||||||
|
#define MU_FLAG_TYPE_ANY ((MuFlags)-1)
|
||||||
|
#define MU_FLAG_TYPE_INVALID ((MuFlagType)-1)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the type of flag (mailfile, maildir, pseudo or content)
|
||||||
|
*
|
||||||
|
* @param flag a MuFlag
|
||||||
|
*
|
||||||
|
* @return the flag type or MU_FLAG_TYPE_INVALID in case of error
|
||||||
|
*/
|
||||||
|
MuFlagType mu_flag_type (MuFlags flag);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the flag character
|
||||||
|
*
|
||||||
|
* @param flag a MuFlag (single)
|
||||||
|
*
|
||||||
|
* @return the character, or 0 in case of error
|
||||||
|
*/
|
||||||
|
char mu_flag_char (MuFlags flag);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the flag name
|
||||||
|
*
|
||||||
|
* @param flag a single MuFlag
|
||||||
|
*
|
||||||
|
* @return the name (don't free) as string or NULL in case of error
|
||||||
|
*/
|
||||||
|
const char* mu_flag_name (MuFlags flag);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the string representation of an OR'ed set of flags
|
||||||
|
*
|
||||||
|
* @param flags MuFlag (OR'ed)
|
||||||
|
* @param types allowable types (OR'ed) for the result; the rest is ignored
|
||||||
|
*
|
||||||
|
* @return The string representation (static, don't free), or NULL in
|
||||||
|
* case of error
|
||||||
|
*/
|
||||||
|
const char* mu_flags_to_str_s (MuFlags flags, MuFlagType types);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the (OR'ed) flags corresponding to a string representation
|
||||||
|
*
|
||||||
|
* @param str the string representation
|
||||||
|
* @param types the flag types to acceps (other will be ignored)
|
||||||
|
*
|
||||||
|
* @return the (OR'ed) flags
|
||||||
|
*/
|
||||||
|
MuFlags mu_flags_from_str (const char *str, MuFlagType types);
|
||||||
|
|
||||||
|
|
||||||
|
typedef void (*MuFlagsForeachFunc) (MuFlags flag, gpointer user_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* call a function for each available flag
|
||||||
|
*
|
||||||
|
* @param func a function to call
|
||||||
|
* @param user_data a user pointer to pass to the function
|
||||||
|
*/
|
||||||
|
void mu_flags_foreach (MuFlagsForeachFunc func, gpointer user_data);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /*__MU_FLAGS_H__*/
|
|
@ -671,35 +671,34 @@ check_msg_type (const char *path, char **info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MuMsgFlags
|
MuFlags
|
||||||
mu_maildir_get_flags_from_path (const char *path)
|
mu_maildir_get_flags_from_path (const char *path)
|
||||||
{
|
{
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
MsgType mtype;
|
MsgType mtype;
|
||||||
char *info = NULL, *cursor;
|
char *info = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (path, MU_MSG_FLAG_NONE);
|
g_return_val_if_fail (path, MU_FLAG_NONE);
|
||||||
g_return_val_if_fail (!g_str_has_suffix(path, G_DIR_SEPARATOR_S),
|
g_return_val_if_fail (!g_str_has_suffix(path, G_DIR_SEPARATOR_S),
|
||||||
MU_MSG_FLAG_NONE);
|
MU_FLAG_NONE);
|
||||||
|
|
||||||
mtype = check_msg_type (path, &info);
|
mtype = check_msg_type (path, &info);
|
||||||
if (mtype == MSG_TYPE_NEW) { /* we ignore any new-msg flags */
|
if (mtype == MSG_TYPE_NEW) { /* we ignore any new-msg flags */
|
||||||
/* note NEW implies UNREAD */
|
/* note NEW implies UNREAD */
|
||||||
flags = MU_MSG_FLAG_NEW | MU_MSG_FLAG_UNREAD;
|
flags = MU_FLAG_NEW | MU_FLAG_UNREAD;
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = MU_MSG_FLAG_NONE;
|
flags = MU_FLAG_NONE;
|
||||||
if ((mtype != MSG_TYPE_CUR && mtype != MSG_TYPE_OTHER) ||
|
if ((mtype != MSG_TYPE_CUR && mtype != MSG_TYPE_OTHER) ||
|
||||||
!(info && info[0] == '2' && info[1] == ','))
|
!(info && info[0] == '2' && info[1] == ','))
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
for (cursor = info + 2; *cursor; ++cursor)
|
flags |= mu_flags_from_str (info + 2, MU_FLAG_TYPE_MAILFILE);
|
||||||
flags |= mu_msg_flag_from_file_char (*cursor);
|
|
||||||
|
|
||||||
/* the UNREAD pseudo flag => NEW OR NOT SEEN */
|
/* the UNREAD pseudo flag => NEW OR NOT SEEN */
|
||||||
if (!(flags & MU_MSG_FLAG_SEEN))
|
if (!(flags & MU_FLAG_SEEN))
|
||||||
flags |= MU_MSG_FLAG_UNREAD;
|
flags |= MU_FLAG_UNREAD;
|
||||||
leave:
|
leave:
|
||||||
g_free(info);
|
g_free(info);
|
||||||
return flags;
|
return flags;
|
||||||
|
@ -707,7 +706,7 @@ leave:
|
||||||
|
|
||||||
/* note: returns static string, non-reentrant */
|
/* note: returns static string, non-reentrant */
|
||||||
static const char*
|
static const char*
|
||||||
get_flags_str_s (MuMsgFlags flags)
|
get_flags_str_s (MuFlags flags)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
static char flagstr[7];
|
static char flagstr[7];
|
||||||
|
@ -715,17 +714,17 @@ get_flags_str_s (MuMsgFlags flags)
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
/* now, determine the flags to use */
|
/* now, determine the flags to use */
|
||||||
if (flags & MU_MSG_FLAG_DRAFT)
|
if (flags & MU_FLAG_DRAFT)
|
||||||
flagstr[i++] = 'D';
|
flagstr[i++] = 'D';
|
||||||
if (flags & MU_MSG_FLAG_FLAGGED)
|
if (flags & MU_FLAG_FLAGGED)
|
||||||
flagstr[i++] = 'F';
|
flagstr[i++] = 'F';
|
||||||
if (flags & MU_MSG_FLAG_PASSED)
|
if (flags & MU_FLAG_PASSED)
|
||||||
flagstr[i++] = 'P';
|
flagstr[i++] = 'P';
|
||||||
if (flags & MU_MSG_FLAG_REPLIED)
|
if (flags & MU_FLAG_REPLIED)
|
||||||
flagstr[i++] = 'R';
|
flagstr[i++] = 'R';
|
||||||
if (flags & MU_MSG_FLAG_SEEN)
|
if (flags & MU_FLAG_SEEN)
|
||||||
flagstr[i++] = 'S';
|
flagstr[i++] = 'S';
|
||||||
if (flags & MU_MSG_FLAG_TRASHED)
|
if (flags & MU_FLAG_TRASHED)
|
||||||
flagstr[i++] = 'T';
|
flagstr[i++] = 'T';
|
||||||
|
|
||||||
flagstr[i] = '\0';
|
flagstr[i] = '\0';
|
||||||
|
@ -738,17 +737,17 @@ get_flags_str_s (MuMsgFlags flags)
|
||||||
* take an exising message path, and return a new path, based on
|
* take an exising message path, and return a new path, based on
|
||||||
* whether it should be in 'new' or 'cur'; ie.
|
* whether it should be in 'new' or 'cur'; ie.
|
||||||
*
|
*
|
||||||
* /home/user/Maildir/foo/bar/cur/abc:2,F and flags == MU_MSG_FLAG_NEW
|
* /home/user/Maildir/foo/bar/cur/abc:2,F and flags == MU_FLAG_NEW
|
||||||
* => /home/user/Maildir/foo/bar/new
|
* => /home/user/Maildir/foo/bar/new
|
||||||
* and
|
* and
|
||||||
* /home/user/Maildir/foo/bar/new/abc and flags == MU_MSG_FLAG_REPLIED
|
* /home/user/Maildir/foo/bar/new/abc and flags == MU_FLAG_REPLIED
|
||||||
* => /home/user/Maildir/foo/bar/cur
|
* => /home/user/Maildir/foo/bar/cur
|
||||||
*
|
*
|
||||||
* so only difference is whether MuMsgFlags matches MU_MSG_FLAG_NEW is set or not
|
* so only difference is whether MuFlags matches MU_FLAG_NEW is set or not
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static char*
|
static char*
|
||||||
get_new_dir_name (const char* oldpath, MuMsgFlags flags)
|
get_new_dir_name (const char* oldpath, MuFlags flags)
|
||||||
{
|
{
|
||||||
char *newpath, *dirpart;
|
char *newpath, *dirpart;
|
||||||
|
|
||||||
|
@ -760,9 +759,9 @@ get_new_dir_name (const char* oldpath, MuMsgFlags flags)
|
||||||
const char* new5 = G_DIR_SEPARATOR_S "new" G_DIR_SEPARATOR_S;
|
const char* new5 = G_DIR_SEPARATOR_S "new" G_DIR_SEPARATOR_S;
|
||||||
|
|
||||||
g_return_val_if_fail (oldpath, NULL);
|
g_return_val_if_fail (oldpath, NULL);
|
||||||
/* if MU_MSG_FLAG_NEW is set, it must be the only flag */
|
/* if MU_FLAG_NEW is set, it must be the only flag */
|
||||||
/* g_return_val_if_fail (flags & MU_MSG_FLAG_NEW ? */
|
/* g_return_val_if_fail (flags & MU_FLAG_NEW ? */
|
||||||
/* flags == MU_MSG_FLAG_NEW : TRUE, NULL); */
|
/* flags == MU_FLAG_NEW : TRUE, NULL); */
|
||||||
|
|
||||||
newpath = g_path_get_dirname (oldpath);
|
newpath = g_path_get_dirname (oldpath);
|
||||||
if (g_str_has_suffix (newpath, cur4) || g_str_has_suffix (newpath, new4))
|
if (g_str_has_suffix (newpath, cur4) || g_str_has_suffix (newpath, new4))
|
||||||
|
@ -776,7 +775,7 @@ get_new_dir_name (const char* oldpath, MuMsgFlags flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now, copy the desired dir part behind this */
|
/* now, copy the desired dir part behind this */
|
||||||
if (flags & MU_MSG_FLAG_NEW)
|
if (flags & MU_FLAG_NEW)
|
||||||
memcpy (dirpart, new4, strlen(new4) + 1);
|
memcpy (dirpart, new4, strlen(new4) + 1);
|
||||||
else
|
else
|
||||||
memcpy (dirpart, cur4, strlen(cur4) + 1);
|
memcpy (dirpart, cur4, strlen(cur4) + 1);
|
||||||
|
@ -786,18 +785,18 @@ get_new_dir_name (const char* oldpath, MuMsgFlags flags)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get a new filename for the message, based on the new flags; if the
|
* get a new filename for the message, based on the new flags; if the
|
||||||
* message has MU_MSG_FLAG_NEW, it will loose its flags
|
* message has MU_FLAG_NEW, it will loose its flags
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static char*
|
static char*
|
||||||
get_new_file_name (const char *oldpath, MuMsgFlags flags)
|
get_new_file_name (const char *oldpath, MuFlags flags)
|
||||||
{
|
{
|
||||||
gchar *newname, *sep;
|
gchar *newname, *sep;
|
||||||
gchar sepa;
|
gchar sepa;
|
||||||
|
|
||||||
/* if MU_MSG_FLAG_NEW is set, it must be the only flag */
|
/* if MU_FLAG_NEW is set, it must be the only flag */
|
||||||
/* g_return_val_if_fail (flags & MU_MSG_FLAG_NEW ? */
|
/* g_return_val_if_fail (flags & MU_FLAG_NEW ? */
|
||||||
/* flags == MU_MSG_FLAG_NEW : TRUE, NULL); */
|
/* flags == MU_FLAG_NEW : TRUE, NULL); */
|
||||||
|
|
||||||
/* the normal separator is ':', but on e.g. vfat, '!' is seen
|
/* the normal separator is ':', but on e.g. vfat, '!' is seen
|
||||||
* as well */
|
* as well */
|
||||||
|
@ -808,7 +807,7 @@ get_new_file_name (const char *oldpath, MuMsgFlags flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 'INVALID' means: "don't change flags" */
|
/* 'INVALID' means: "don't change flags" */
|
||||||
if (flags == (unsigned)MU_MSG_FLAG_INVALID)
|
if (flags == (unsigned)MU_FLAG_INVALID)
|
||||||
return newname;
|
return newname;
|
||||||
|
|
||||||
/* the filename may or may not end in "[:!]2,..." */
|
/* the filename may or may not end in "[:!]2,..." */
|
||||||
|
@ -832,15 +831,14 @@ get_new_file_name (const char *oldpath, MuMsgFlags flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
mu_maildir_get_path_from_flags (const char *oldpath, MuMsgFlags newflags)
|
mu_maildir_get_path_from_flags (const char *oldpath, MuFlags newflags)
|
||||||
{
|
{
|
||||||
char *newname, *newdir, *newpath;
|
char *newname, *newdir, *newpath;
|
||||||
|
|
||||||
g_return_val_if_fail (oldpath, NULL);
|
g_return_val_if_fail (oldpath, NULL);
|
||||||
g_return_val_if_fail (newflags != MU_MSG_FLAG_NONE, NULL);
|
/* if MU_FLAG_NEW is set, it must be the only flag */
|
||||||
/* if MU_MSG_FLAG_NEW is set, it must be the only flag */
|
/* g_return_val_if_fail (newflags & MU_FLAG_NEW ? */
|
||||||
/* g_return_val_if_fail (newflags & MU_MSG_FLAG_NEW ? */
|
/* newflags == MU_FLAG_NEW : TRUE, NULL); */
|
||||||
/* newflags == MU_MSG_FLAG_NEW : TRUE, NULL); */
|
|
||||||
|
|
||||||
newname = get_new_file_name (oldpath, newflags);
|
newname = get_new_file_name (oldpath, newflags);
|
||||||
if (!newname)
|
if (!newname)
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/types.h> /* for mode_t */
|
#include <sys/types.h> /* for mode_t */
|
||||||
#include <mu-util.h>
|
#include <mu-util.h>
|
||||||
#include <mu-msg-flags.h>
|
#include <mu-flags.h>
|
||||||
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
@ -132,7 +132,7 @@ gboolean mu_maildir_clear_links (const gchar* dir, GError **err);
|
||||||
*
|
*
|
||||||
* @return the flags, or MU_MSG_FILE_FLAG_UNKNOWN in case of error
|
* @return the flags, or MU_MSG_FILE_FLAG_UNKNOWN in case of error
|
||||||
*/
|
*/
|
||||||
MuMsgFlags mu_maildir_get_flags_from_path (const char* pathname);
|
MuFlags mu_maildir_get_flags_from_path (const char* pathname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the new pathname for a message, based on the old path and the
|
* get the new pathname for a message, based on the old path and the
|
||||||
|
@ -151,7 +151,7 @@ MuMsgFlags mu_maildir_get_flags_from_path (const char* pathname);
|
||||||
* error.
|
* error.
|
||||||
*/
|
*/
|
||||||
char* mu_maildir_get_path_from_flags (const char *oldpath,
|
char* mu_maildir_get_path_from_flags (const char *oldpath,
|
||||||
MuMsgFlags newflags);
|
MuFlags newflags);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mu-msg-flags.h"
|
#include "mu-flags.h"
|
||||||
#include "mu-msg-prio.h"
|
#include "mu-msg-prio.h"
|
||||||
#include "mu-msg-cache.h"
|
#include "mu-msg-cache.h"
|
||||||
#include "mu-str.h"
|
#include "mu-str.h"
|
||||||
|
@ -31,7 +31,7 @@ struct _MuMsgCache {
|
||||||
|
|
||||||
time_t _timestamp, _date;
|
time_t _timestamp, _date;
|
||||||
size_t _size;
|
size_t _size;
|
||||||
MuMsgFlags _flags;
|
MuFlags _flags;
|
||||||
MuMsgPrio _prio;
|
MuMsgPrio _prio;
|
||||||
|
|
||||||
/* <private> */
|
/* <private> */
|
||||||
|
@ -61,7 +61,7 @@ cache_clear (MuMsgCache *self)
|
||||||
|
|
||||||
self->_timestamp = (time_t)-1;
|
self->_timestamp = (time_t)-1;
|
||||||
self->_size = (size_t)-1;
|
self->_size = (size_t)-1;
|
||||||
self->_flags = MU_MSG_FLAG_NONE;
|
self->_flags = MU_FLAG_NONE;
|
||||||
self->_prio = MU_MSG_PRIO_NONE;
|
self->_prio = MU_MSG_PRIO_NONE;
|
||||||
self->_date = (time_t)-1;
|
self->_date = (time_t)-1;
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ mu_msg_cache_set_num (MuMsgCache *self, MuMsgFieldId mfid, gint64 val)
|
||||||
self->_prio = (MuMsgPrio)val;
|
self->_prio = (MuMsgPrio)val;
|
||||||
break;
|
break;
|
||||||
case MU_MSG_FIELD_ID_FLAGS:
|
case MU_MSG_FIELD_ID_FLAGS:
|
||||||
self->_flags = (MuMsgFlags)val;
|
self->_flags = (MuFlags)val;
|
||||||
break;
|
break;
|
||||||
case MU_MSG_FIELD_ID_SIZE:
|
case MU_MSG_FIELD_ID_SIZE:
|
||||||
self->_size = (size_t)val;
|
self->_size = (size_t)val;
|
||||||
|
|
|
@ -272,29 +272,29 @@ part_looks_like_attachment (GMimeObject *part)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
msg_cflags_cb (GMimeObject *parent, GMimeObject *part, MuMsgFlags *flags)
|
msg_cflags_cb (GMimeObject *parent, GMimeObject *part, MuFlags *flags)
|
||||||
{
|
{
|
||||||
if (*flags & MU_MSG_FLAG_HAS_ATTACH)
|
if (*flags & MU_FLAG_HAS_ATTACH)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!GMIME_IS_PART(part))
|
if (!GMIME_IS_PART(part))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (part_looks_like_attachment(part))
|
if (part_looks_like_attachment(part))
|
||||||
*flags |= MU_MSG_FLAG_HAS_ATTACH;
|
*flags |= MU_FLAG_HAS_ATTACH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static MuMsgFlags
|
static MuFlags
|
||||||
get_content_flags (MuMsgFile *self)
|
get_content_flags (MuMsgFile *self)
|
||||||
{
|
{
|
||||||
GMimeContentType *ctype;
|
GMimeContentType *ctype;
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
GMimeObject *part;
|
GMimeObject *part;
|
||||||
|
|
||||||
if (!GMIME_IS_MESSAGE(self->_mime_msg))
|
if (!GMIME_IS_MESSAGE(self->_mime_msg))
|
||||||
return MU_MSG_FLAG_NONE;
|
return MU_FLAG_NONE;
|
||||||
|
|
||||||
flags = 0;
|
flags = 0;
|
||||||
g_mime_message_foreach (self->_mime_msg,
|
g_mime_message_foreach (self->_mime_msg,
|
||||||
|
@ -315,10 +315,10 @@ get_content_flags (MuMsgFile *self)
|
||||||
if (ctype) {
|
if (ctype) {
|
||||||
if (g_mime_content_type_is_type
|
if (g_mime_content_type_is_type
|
||||||
(ctype,"*", "signed"))
|
(ctype,"*", "signed"))
|
||||||
flags |= MU_MSG_FLAG_SIGNED;
|
flags |= MU_FLAG_SIGNED;
|
||||||
if (g_mime_content_type_is_type
|
if (g_mime_content_type_is_type
|
||||||
(ctype,"*", "encrypted"))
|
(ctype,"*", "encrypted"))
|
||||||
flags |= MU_MSG_FLAG_ENCRYPTED;
|
flags |= MU_FLAG_ENCRYPTED;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
g_warning ("no top level mime part found");
|
g_warning ("no top level mime part found");
|
||||||
|
@ -327,12 +327,12 @@ get_content_flags (MuMsgFile *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static MuMsgFlags
|
static MuFlags
|
||||||
get_flags (MuMsgFile *self)
|
get_flags (MuMsgFile *self)
|
||||||
{
|
{
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
|
|
||||||
g_return_val_if_fail (self, MU_MSG_FLAG_NONE);
|
g_return_val_if_fail (self, MU_FLAG_NONE);
|
||||||
|
|
||||||
flags = mu_maildir_get_flags_from_path (self->_path);
|
flags = mu_maildir_get_flags_from_path (self->_path);
|
||||||
flags |= get_content_flags (self);
|
flags |= get_content_flags (self);
|
||||||
|
|
|
@ -1,188 +0,0 @@
|
||||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
** 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
|
|
||||||
** Free Software Foundation; either version 3, or (at your option) any
|
|
||||||
** later version.
|
|
||||||
**
|
|
||||||
** 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, write to the Free Software Foundation,
|
|
||||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "mu-util.h"
|
|
||||||
#include "mu-msg-flags.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* put these in alpha-order, so output strings are ordered correctly
|
|
||||||
* (that's the way the Maildir spec teaches us)
|
|
||||||
*/
|
|
||||||
static const MuMsgFlags ALL_FLAGS[] = {
|
|
||||||
/* a */ MU_MSG_FLAG_HAS_ATTACH, /* non-maildir flag */
|
|
||||||
/* D */ MU_MSG_FLAG_DRAFT,
|
|
||||||
/* F */ MU_MSG_FLAG_FLAGGED,
|
|
||||||
/* N */ MU_MSG_FLAG_NEW,
|
|
||||||
/* P */ MU_MSG_FLAG_PASSED,
|
|
||||||
/* R */ MU_MSG_FLAG_REPLIED,
|
|
||||||
/* S */ MU_MSG_FLAG_SEEN,
|
|
||||||
/* T */ MU_MSG_FLAG_TRASHED,
|
|
||||||
/* U */ MU_MSG_FLAG_UNREAD, /* pseudo flag */
|
|
||||||
/* x */ MU_MSG_FLAG_ENCRYPTED, /* non-maildir flag */
|
|
||||||
/* z */ MU_MSG_FLAG_SIGNED /* non-maildir flag */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
MuMsgFlags
|
|
||||||
mu_msg_flag_from_char (char k)
|
|
||||||
{
|
|
||||||
switch (k) {
|
|
||||||
case 'N': return MU_MSG_FLAG_NEW;
|
|
||||||
case 'P': return MU_MSG_FLAG_PASSED;
|
|
||||||
case 'R': return MU_MSG_FLAG_REPLIED;
|
|
||||||
case 'S': return MU_MSG_FLAG_SEEN;
|
|
||||||
case 'T': return MU_MSG_FLAG_TRASHED;
|
|
||||||
case 'D': return MU_MSG_FLAG_DRAFT;
|
|
||||||
case 'F': return MU_MSG_FLAG_FLAGGED;
|
|
||||||
|
|
||||||
/* NEW OR NOT SEEN */
|
|
||||||
case 'U': return MU_MSG_FLAG_UNREAD;
|
|
||||||
|
|
||||||
case 'z': return MU_MSG_FLAG_SIGNED;
|
|
||||||
case 'x': return MU_MSG_FLAG_ENCRYPTED;
|
|
||||||
case 'a': return MU_MSG_FLAG_HAS_ATTACH;
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_return_val_if_reached (MU_MSG_FLAG_NONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MuMsgFlags
|
|
||||||
mu_msg_flag_from_file_char (char k)
|
|
||||||
{
|
|
||||||
switch (k) {
|
|
||||||
case 'D': return MU_MSG_FLAG_DRAFT;
|
|
||||||
case 'F': return MU_MSG_FLAG_FLAGGED;
|
|
||||||
case 'P': return MU_MSG_FLAG_PASSED;
|
|
||||||
case 'R': return MU_MSG_FLAG_REPLIED;
|
|
||||||
case 'S': return MU_MSG_FLAG_SEEN;
|
|
||||||
case 'T': return MU_MSG_FLAG_TRASHED;
|
|
||||||
default: return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_msg_flag_name (MuMsgFlags flag)
|
|
||||||
{
|
|
||||||
switch (flag) {
|
|
||||||
|
|
||||||
/* real maildir flags */
|
|
||||||
case MU_MSG_FLAG_DRAFT: return "draft";
|
|
||||||
case MU_MSG_FLAG_FLAGGED: return "flagged";
|
|
||||||
case MU_MSG_FLAG_NEW: return "new";
|
|
||||||
case MU_MSG_FLAG_PASSED: return "passed";
|
|
||||||
case MU_MSG_FLAG_REPLIED: return "replied";
|
|
||||||
case MU_MSG_FLAG_SEEN: return "seen";
|
|
||||||
case MU_MSG_FLAG_TRASHED: return "trashed";
|
|
||||||
|
|
||||||
/* ie., NEW or NOT SEEN */
|
|
||||||
case MU_MSG_FLAG_UNREAD: return "unread";
|
|
||||||
|
|
||||||
case MU_MSG_FLAG_SIGNED: return "signed";
|
|
||||||
case MU_MSG_FLAG_ENCRYPTED: return "encrypted";
|
|
||||||
case MU_MSG_FLAG_HAS_ATTACH: return "attach";
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_return_val_if_reached (NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char
|
|
||||||
mu_msg_flag_char (MuMsgFlags flag)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (flag != MU_MSG_FLAG_NONE, 0);
|
|
||||||
|
|
||||||
switch (flag) {
|
|
||||||
|
|
||||||
case MU_MSG_FLAG_NEW: return 'N';
|
|
||||||
case MU_MSG_FLAG_PASSED: return 'P';
|
|
||||||
case MU_MSG_FLAG_REPLIED: return 'R';
|
|
||||||
case MU_MSG_FLAG_SEEN: return 'S';
|
|
||||||
case MU_MSG_FLAG_TRASHED: return 'T';
|
|
||||||
case MU_MSG_FLAG_DRAFT: return 'D';
|
|
||||||
case MU_MSG_FLAG_FLAGGED: return 'F';
|
|
||||||
|
|
||||||
/* NEW OR NOT SEEN */
|
|
||||||
case MU_MSG_FLAG_UNREAD: return 'U';
|
|
||||||
|
|
||||||
case MU_MSG_FLAG_SIGNED: return 'z';
|
|
||||||
case MU_MSG_FLAG_ENCRYPTED: return 'x';
|
|
||||||
case MU_MSG_FLAG_HAS_ATTACH: return 'a';
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_return_val_if_reached (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char*
|
|
||||||
mu_msg_flags_str_s (MuMsgFlags flags)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
static char buf[16]; /* more than enough */
|
|
||||||
|
|
||||||
for (i = j = 0; i != G_N_ELEMENTS(ALL_FLAGS); ++i) {
|
|
||||||
if (flags & ALL_FLAGS[i]) {
|
|
||||||
char k;
|
|
||||||
if ((k = mu_msg_flag_char (ALL_FLAGS[i])) == 0)
|
|
||||||
return NULL;
|
|
||||||
buf[j++] = k;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buf[j] = '\0';
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
MuMsgFlags
|
|
||||||
mu_msg_flags_from_str (const char* str)
|
|
||||||
{
|
|
||||||
MuMsgFlags flags;
|
|
||||||
|
|
||||||
for (flags = MU_MSG_FLAG_NONE; str && *str; ++str) {
|
|
||||||
MuMsgFlags flag;
|
|
||||||
if ((flag = mu_msg_flag_from_char (*str)) == 0) {
|
|
||||||
flags = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
flags |= flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
mu_msg_flags_foreach (MuMsgFlagsForeachFunc func, gpointer user_data)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
g_return_if_fail (func);
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(ALL_FLAGS); ++i)
|
|
||||||
func (ALL_FLAGS[i], user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,183 +0,0 @@
|
||||||
/*
|
|
||||||
** 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
|
|
||||||
** Free Software Foundation; either version 3, or (at your option) any
|
|
||||||
** later version.
|
|
||||||
**
|
|
||||||
** 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, write to the Free Software Foundation,
|
|
||||||
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __MU_MSG_FLAGS_H__
|
|
||||||
#define __MU_MSG_FLAGS_H__
|
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
/* 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,
|
|
||||||
|
|
||||||
/* 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,
|
|
||||||
|
|
||||||
/* NOTE: the only flag characters actually seen in Maildir
|
|
||||||
* files are: PRSTDF
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* "U"->unread message; it's a pseudo/convenience flag that
|
|
||||||
* means (NEW or not SEEN) */
|
|
||||||
MU_MSG_FLAG_UNREAD = 1 << 7,
|
|
||||||
|
|
||||||
/* these we get from the contents */
|
|
||||||
|
|
||||||
/* "z"->signed message */
|
|
||||||
MU_MSG_FLAG_SIGNED = 1 << 8,
|
|
||||||
/* "x"->encrypted message */
|
|
||||||
MU_MSG_FLAG_ENCRYPTED = 1 << 9,
|
|
||||||
/* "a"->message has attachment */
|
|
||||||
MU_MSG_FLAG_HAS_ATTACH = 1 << 10,
|
|
||||||
};
|
|
||||||
typedef enum _MuMsgFlags MuMsgFlags;
|
|
||||||
|
|
||||||
#define MU_MSG_FLAG_INVALID (-1)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 are accepted; if
|
|
||||||
* any other characters are seen, MU_MSG_FLAG_INVALID is returned.
|
|
||||||
*
|
|
||||||
* @param str a string
|
|
||||||
*
|
|
||||||
* @return a MuMSgFlags value, or MU_MSG_FLAG_INVALID in case of error
|
|
||||||
*/
|
|
||||||
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
|
|
||||||
*
|
|
||||||
* @return a MuMSgFlags value, or MU_MSG_FLAG_UNKNOWN in case of error
|
|
||||||
*/
|
|
||||||
MuMsgFlags mu_msg_flags_from_char (char c) G_GNUC_CONST;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* convert the char-per-flag description into a MuMsgFlags value. The
|
|
||||||
* difference is that with 'mu_msg_flags_from_char' is that this
|
|
||||||
* function only cares about the chars that are part of the
|
|
||||||
* Maildir-standard (ie., in files), and that is ignores unknown chars
|
|
||||||
* (returns 0), rather than printing warnings
|
|
||||||
*
|
|
||||||
* @param c a character
|
|
||||||
*
|
|
||||||
* @return a MuMSgFlags value, or 0 if the char is not known as a
|
|
||||||
* maildir char
|
|
||||||
*/
|
|
||||||
MuMsgFlags mu_msg_flag_from_file_char (char k) 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
|
|
||||||
* a=has-attachment,s=signed, x=encrypted
|
|
||||||
*
|
|
||||||
* mu_msg_flags_to_str_s returns a ptr to a static buffer, ie.,
|
|
||||||
* ie, is not re-entrant. copy the string if needed.
|
|
||||||
*
|
|
||||||
* @param flags file flags
|
|
||||||
*
|
|
||||||
* @return a string representation of the flags
|
|
||||||
*/
|
|
||||||
const char* mu_msg_flags_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_flag_char (MuMsgFlags flag) G_GNUC_CONST;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a string describing this flag
|
|
||||||
*
|
|
||||||
* @param flag a single flag (not OR'ed)
|
|
||||||
*
|
|
||||||
* @return a string describing this flag, e.g.,
|
|
||||||
* MU_MSG_FLAG_ATTACH=>"attach"
|
|
||||||
*/
|
|
||||||
const char* mu_msg_flag_name (MuMsgFlags flag) G_GNUC_CONST;
|
|
||||||
|
|
||||||
|
|
||||||
typedef void (*MuMsgFlagsForeachFunc)
|
|
||||||
(MuMsgFlags flag, gpointer user_data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* call a function for each available message flag
|
|
||||||
*
|
|
||||||
* @param func a function to call (callback)
|
|
||||||
* @param user_data user pointer passed to the callback
|
|
||||||
*/
|
|
||||||
void mu_msg_flags_foreach (MuMsgFlagsForeachFunc func, gpointer user_data);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* not some flags OR'ed together
|
|
||||||
*
|
|
||||||
* @return TRUE if it is a file flag, FALSE otherwise
|
|
||||||
*/
|
|
||||||
gboolean mu_msg_flags_is_file_flag (MuMsgFlags flag) G_GNUC_CONST;
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
#endif /*__MU_MSG_FLAGS_H__*/
|
|
||||||
|
|
||||||
|
|
|
@ -155,22 +155,22 @@ append_sexp_contacts (GString *gstr, MuMsg *msg)
|
||||||
|
|
||||||
struct _FlagData {
|
struct _FlagData {
|
||||||
char *flagstr;
|
char *flagstr;
|
||||||
MuMsgFlags msgflags;
|
MuFlags msgflags;
|
||||||
};
|
};
|
||||||
typedef struct _FlagData FlagData;
|
typedef struct _FlagData FlagData;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
each_flag (MuMsgFlags flag, FlagData *fdata)
|
each_flag (MuFlags flag, FlagData *fdata)
|
||||||
{
|
{
|
||||||
if (!(flag & fdata->msgflags))
|
if (!(flag & fdata->msgflags))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!fdata->flagstr)
|
if (!fdata->flagstr)
|
||||||
fdata->flagstr = g_strdup (mu_msg_flag_name(flag));
|
fdata->flagstr = g_strdup (mu_flag_name(flag));
|
||||||
else {
|
else {
|
||||||
gchar *tmp;
|
gchar *tmp;
|
||||||
tmp = g_strconcat (fdata->flagstr, " ",
|
tmp = g_strconcat (fdata->flagstr, " ",
|
||||||
mu_msg_flag_name(flag), NULL);
|
mu_flag_name(flag), NULL);
|
||||||
g_free (fdata->flagstr);
|
g_free (fdata->flagstr);
|
||||||
fdata->flagstr = tmp;
|
fdata->flagstr = tmp;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ append_sexp_flags (GString *gstr, MuMsg *msg)
|
||||||
fdata.msgflags = mu_msg_get_flags (msg);
|
fdata.msgflags = mu_msg_get_flags (msg);
|
||||||
fdata.flagstr = NULL;
|
fdata.flagstr = NULL;
|
||||||
|
|
||||||
mu_msg_flags_foreach ((MuMsgFlagsForeachFunc)each_flag, &fdata);
|
mu_flags_foreach ((MuFlagsForeachFunc)each_flag, &fdata);
|
||||||
if (fdata.flagstr)
|
if (fdata.flagstr)
|
||||||
g_string_append_printf (gstr, "\t:flags (%s)\n",
|
g_string_append_printf (gstr, "\t:flags (%s)\n",
|
||||||
fdata.flagstr);
|
fdata.flagstr);
|
||||||
|
|
15
src/mu-msg.c
15
src/mu-msg.c
|
@ -375,11 +375,11 @@ mu_msg_get_date (MuMsg *self)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MuMsgFlags
|
MuFlags
|
||||||
mu_msg_get_flags (MuMsg *self)
|
mu_msg_get_flags (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, MU_MSG_FLAG_NONE);
|
g_return_val_if_fail (self, MU_FLAG_NONE);
|
||||||
return (MuMsgFlags)get_num_field (self, MU_MSG_FIELD_ID_FLAGS);
|
return (MuFlags)get_num_field (self, MU_MSG_FIELD_ID_FLAGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
@ -713,7 +713,7 @@ get_maildir_type (const char *path)
|
||||||
|
|
||||||
char*
|
char*
|
||||||
get_new_fullpath (const char *oldpath, const char *targetmdir,
|
get_new_fullpath (const char *oldpath, const char *targetmdir,
|
||||||
MaildirType mtype, MuMsgFlags flags)
|
MaildirType mtype, MuFlags flags)
|
||||||
{
|
{
|
||||||
char *filename, *newfullpath;
|
char *filename, *newfullpath;
|
||||||
const char* mdirsub;
|
const char* mdirsub;
|
||||||
|
@ -740,12 +740,11 @@ get_new_fullpath (const char *oldpath, const char *targetmdir,
|
||||||
|
|
||||||
/* we update the filename for the new flags; in case the NEW
|
/* we update the filename for the new flags; in case the NEW
|
||||||
* flag is set/unset, this can also influence the dir */
|
* flag is set/unset, this can also influence the dir */
|
||||||
if (flags != MU_MSG_FLAG_NONE) {
|
if (flags != MU_FLAG_NONE) {
|
||||||
gchar *tmp;
|
gchar *tmp;
|
||||||
tmp = mu_maildir_get_path_from_flags (newfullpath, flags);
|
tmp = mu_maildir_get_path_from_flags (newfullpath, flags);
|
||||||
g_free (newfullpath);
|
g_free (newfullpath);
|
||||||
newfullpath = tmp;
|
newfullpath = tmp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newfullpath;
|
return newfullpath;
|
||||||
|
@ -836,7 +835,7 @@ check_target_dir (const char* targetmdir, GError **err)
|
||||||
*/
|
*/
|
||||||
gchar*
|
gchar*
|
||||||
mu_msg_file_move_to_maildir (const char* oldpath, const char* targetmdir,
|
mu_msg_file_move_to_maildir (const char* oldpath, const char* targetmdir,
|
||||||
MuMsgFlags flags, GError **err)
|
MuFlags flags, GError **err)
|
||||||
{
|
{
|
||||||
MaildirType mtype;
|
MaildirType mtype;
|
||||||
char *newfullpath;
|
char *newfullpath;
|
||||||
|
@ -881,7 +880,7 @@ mu_msg_file_move_to_maildir (const char* oldpath, const char* targetmdir,
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
mu_msg_move_to_maildir (MuMsg *self, const char* targetmdir,
|
mu_msg_move_to_maildir (MuMsg *self, const char* targetmdir,
|
||||||
MuMsgFlags flags, GError **err)
|
MuFlags flags, GError **err)
|
||||||
{
|
{
|
||||||
char *newfullpath;
|
char *newfullpath;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#ifndef __MU_MSG_H__
|
#ifndef __MU_MSG_H__
|
||||||
#define __MU_MSG_H__
|
#define __MU_MSG_H__
|
||||||
|
|
||||||
#include <mu-msg-flags.h>
|
#include <mu-flags.h>
|
||||||
#include <mu-msg-fields.h>
|
#include <mu-msg-fields.h>
|
||||||
#include <mu-msg-prio.h>
|
#include <mu-msg-prio.h>
|
||||||
#include <mu-util.h> /* for MuResult, MuError and XapianDocument */
|
#include <mu-util.h> /* for MuResult, MuError and XapianDocument */
|
||||||
|
@ -241,7 +241,7 @@ time_t mu_msg_get_date (MuMsg *msg);
|
||||||
* @return the fileflags as logically OR'd #Mu MsgFlags or 0 if
|
* @return the fileflags as logically OR'd #Mu MsgFlags or 0 if
|
||||||
* there are none.
|
* there are none.
|
||||||
*/
|
*/
|
||||||
MuMsgFlags mu_msg_get_flags (MuMsg *msg);
|
MuFlags mu_msg_get_flags (MuMsg *msg);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -405,9 +405,9 @@ char* mu_msg_to_sexp (MuMsg *msg, gboolean dbonly);
|
||||||
* @return TRUE if it worked, FALSE otherwise (mu_msg_move_to_maildir) or the full path name of the target file (g_free) for mu_msg_file_move_to_maildir
|
* @return TRUE if it worked, FALSE otherwise (mu_msg_move_to_maildir) or the full path name of the target file (g_free) for mu_msg_file_move_to_maildir
|
||||||
*/
|
*/
|
||||||
gboolean mu_msg_move_to_maildir (MuMsg *msg, const char* targetmdir,
|
gboolean mu_msg_move_to_maildir (MuMsg *msg, const char* targetmdir,
|
||||||
MuMsgFlags flags, GError **err);
|
MuFlags flags, GError **err);
|
||||||
char* mu_msg_file_move_to_maildir (const char *msgpath, const char* targetmdir,
|
char* mu_msg_file_move_to_maildir (const char *msgpath, const char* targetmdir,
|
||||||
MuMsgFlags flags, GError **err);
|
MuFlags flags, GError **err);
|
||||||
|
|
||||||
enum _MuMsgContactType { /* Reply-To:? */
|
enum _MuMsgContactType { /* Reply-To:? */
|
||||||
MU_MSG_CONTACT_TYPE_TO = 0,
|
MU_MSG_CONTACT_TYPE_TO = 0,
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
#include "mu-str.h"
|
#include "mu-str.h"
|
||||||
#include "mu-date.h"
|
#include "mu-date.h"
|
||||||
#include "mu-msg-flags.h"
|
#include "mu-flags.h"
|
||||||
#include "mu-contacts.h"
|
#include "mu-contacts.h"
|
||||||
|
|
||||||
/* by default, use transactions of 30000 messages */
|
/* by default, use transactions of 30000 messages */
|
||||||
|
@ -115,13 +115,13 @@ prefix (MuMsgFieldId mfid)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_synonym_for_flag (MuMsgFlags flag, Xapian::WritableDatabase *db)
|
add_synonym_for_flag (MuFlags flag, Xapian::WritableDatabase *db)
|
||||||
{
|
{
|
||||||
const std::string pfx(prefix(MU_MSG_FIELD_ID_FLAGS));
|
const std::string pfx(prefix(MU_MSG_FIELD_ID_FLAGS));
|
||||||
|
|
||||||
db->clear_synonyms (pfx + mu_msg_flag_name (flag));
|
db->clear_synonyms (pfx + mu_flag_name (flag));
|
||||||
db->add_synonym (pfx + mu_msg_flag_name (flag), pfx +
|
db->add_synonym (pfx + mu_flag_name (flag), pfx +
|
||||||
(std::string(1, tolower(mu_msg_flag_char (flag)))));
|
(std::string(1, tolower(mu_flag_char (flag)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ add_synonym_for_prio (MuMsgPrio prio, Xapian::WritableDatabase *db)
|
||||||
static void
|
static void
|
||||||
add_synonyms (MuStore *store)
|
add_synonyms (MuStore *store)
|
||||||
{
|
{
|
||||||
mu_msg_flags_foreach ((MuMsgFlagsForeachFunc)add_synonym_for_flag,
|
mu_flags_foreach ((MuFlagsForeachFunc)add_synonym_for_flag,
|
||||||
&store->_db);
|
&store->_db);
|
||||||
mu_msg_prio_foreach ((MuMsgPrioForeachFunc)add_synonym_for_prio,
|
mu_msg_prio_foreach ((MuMsgPrioForeachFunc)add_synonym_for_prio,
|
||||||
&store->_db);
|
&store->_db);
|
||||||
|
@ -335,7 +335,9 @@ add_terms_values_number (Xapian::Document& doc, MuMsg *msg, MuMsgFieldId mfid)
|
||||||
doc.add_value ((Xapian::valueno)mfid, numstr);
|
doc.add_value ((Xapian::valueno)mfid, numstr);
|
||||||
|
|
||||||
if (mfid == MU_MSG_FIELD_ID_FLAGS) {
|
if (mfid == MU_MSG_FIELD_ID_FLAGS) {
|
||||||
for (const char *cur = mu_msg_flags_str_s ((MuMsgFlags)num);
|
for (const char *cur =
|
||||||
|
mu_flags_to_str_s ((MuFlags)num,
|
||||||
|
(MuFlagType)MU_FLAG_TYPE_ANY);
|
||||||
cur && *cur; ++cur)
|
cur && *cur; ++cur)
|
||||||
doc.add_term (prefix(mfid) + (char)tolower (*cur));
|
doc.add_term (prefix(mfid) + (char)tolower (*cur));
|
||||||
|
|
||||||
|
@ -478,7 +480,7 @@ add_terms_values_body (Xapian::Document& doc, MuMsg *msg,
|
||||||
const char *str;
|
const char *str;
|
||||||
char *norm;
|
char *norm;
|
||||||
|
|
||||||
if (mu_msg_get_flags(msg) & MU_MSG_FLAG_ENCRYPTED)
|
if (mu_msg_get_flags(msg) & MU_FLAG_ENCRYPTED)
|
||||||
return; /* ignore encrypted bodies */
|
return; /* ignore encrypted bodies */
|
||||||
|
|
||||||
str = mu_msg_get_body_text (msg);
|
str = mu_msg_get_body_text (msg);
|
||||||
|
|
10
src/mu-str.c
10
src/mu-str.c
|
@ -42,7 +42,6 @@
|
||||||
#endif /*PATH_MAX*/
|
#endif /*PATH_MAX*/
|
||||||
|
|
||||||
#include "mu-str.h"
|
#include "mu-str.h"
|
||||||
#include "mu-msg-flags.h"
|
|
||||||
#include "mu-msg-fields.h"
|
#include "mu-msg-fields.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,13 +77,13 @@ mu_str_size (size_t s)
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_str_flags_s (MuMsgFlags flags)
|
mu_str_flags_s (MuFlags flags)
|
||||||
{
|
{
|
||||||
return mu_msg_flags_str_s (flags);
|
return mu_flags_to_str_s (flags, MU_FLAG_TYPE_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
mu_str_flags (MuMsgFlags flags)
|
mu_str_flags (MuFlags flags)
|
||||||
{
|
{
|
||||||
return g_strdup (mu_str_flags_s(flags));
|
return g_strdup (mu_str_flags_s(flags));
|
||||||
}
|
}
|
||||||
|
@ -456,8 +455,7 @@ mu_str_escape_c_literal (const gchar* str, gboolean in_quotes)
|
||||||
|
|
||||||
if (in_quotes)
|
if (in_quotes)
|
||||||
g_string_append_c (tmp, '"');
|
g_string_append_c (tmp, '"');
|
||||||
|
return g_string_free (tmp, FALSE);
|
||||||
return g_string_free (tmp, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <mu-msg.h>
|
#include <mu-msg.h>
|
||||||
#include <mu-msg-flags.h>
|
#include <mu-flags.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ char* mu_str_size (size_t s) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
* @return a string representation of the flags; see above
|
* @return a string representation of the flags; see above
|
||||||
* for what to do with it
|
* for what to do with it
|
||||||
*/
|
*/
|
||||||
const char* mu_str_flags_s (MuMsgFlags flags) G_GNUC_CONST;
|
const char* mu_str_flags_s (MuFlags flags) G_GNUC_CONST;
|
||||||
char* mu_str_flags (MuMsgFlags flags)
|
char* mu_str_flags (MuFlags flags)
|
||||||
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -235,24 +235,24 @@ test_mu_maildir_get_flags_from_path (void)
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
const char *path;
|
const char *path;
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
} paths[] = {
|
} paths[] = {
|
||||||
{
|
{
|
||||||
"/home/foo/Maildir/test/cur/123456:2,FSR",
|
"/home/foo/Maildir/test/cur/123456:2,FSR",
|
||||||
MU_MSG_FLAG_REPLIED | MU_MSG_FLAG_SEEN | MU_MSG_FLAG_FLAGGED}, {
|
MU_FLAG_REPLIED | MU_FLAG_SEEN | MU_FLAG_FLAGGED}, {
|
||||||
"/home/foo/Maildir/test/new/123456",
|
"/home/foo/Maildir/test/new/123456",
|
||||||
MU_MSG_FLAG_NEW | MU_MSG_FLAG_UNREAD}, {
|
MU_FLAG_NEW | MU_FLAG_UNREAD}, {
|
||||||
"/home/foo/Maildir/test/new/123456:2,FR",
|
"/home/foo/Maildir/test/new/123456:2,FR",
|
||||||
MU_MSG_FLAG_NEW | MU_MSG_FLAG_UNREAD}, {
|
MU_FLAG_NEW | MU_FLAG_UNREAD}, {
|
||||||
"/home/foo/Maildir/test/cur/123456:2,DTP",
|
"/home/foo/Maildir/test/cur/123456:2,DTP",
|
||||||
MU_MSG_FLAG_DRAFT | MU_MSG_FLAG_TRASHED |
|
MU_FLAG_DRAFT | MU_FLAG_TRASHED |
|
||||||
MU_MSG_FLAG_PASSED | MU_MSG_FLAG_UNREAD }, {
|
MU_FLAG_PASSED | MU_FLAG_UNREAD }, {
|
||||||
"/home/foo/Maildir/test/cur/123456:2,S",
|
"/home/foo/Maildir/test/cur/123456:2,S",
|
||||||
MU_MSG_FLAG_SEEN}
|
MU_FLAG_SEEN}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
flags = mu_maildir_get_flags_from_path(paths[i].path);
|
flags = mu_maildir_get_flags_from_path(paths[i].path);
|
||||||
g_assert_cmpuint(flags, ==, paths[i].flags);
|
g_assert_cmpuint(flags, ==, paths[i].flags);
|
||||||
}
|
}
|
||||||
|
@ -265,30 +265,28 @@ test_mu_maildir_get_path_from_flags (void)
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
const char *oldpath;
|
const char *oldpath;
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
const char *newpath;
|
const char *newpath;
|
||||||
} paths[] = {
|
} paths[] = {
|
||||||
{
|
{
|
||||||
"/home/foo/Maildir/test/cur/123456:2,FR",
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
||||||
MU_MSG_FLAG_REPLIED,
|
MU_FLAG_REPLIED,
|
||||||
"/home/foo/Maildir/test/cur/123456:2,R"
|
"/home/foo/Maildir/test/cur/123456:2,R"
|
||||||
}, {
|
}, {
|
||||||
"/home/foo/Maildir/test/cur/123456:2,FR",
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
||||||
MU_MSG_FLAG_NEW,
|
MU_FLAG_NEW,
|
||||||
"/home/foo/Maildir/test/new/123456:2,"
|
"/home/foo/Maildir/test/new/123456:2,"
|
||||||
}, {
|
}, {
|
||||||
"/home/foo/Maildir/test/new/123456:2,FR",
|
"/home/foo/Maildir/test/new/123456:2,FR",
|
||||||
MU_MSG_FLAG_SEEN | MU_MSG_FLAG_REPLIED,
|
MU_FLAG_SEEN | MU_FLAG_REPLIED,
|
||||||
"/home/foo/Maildir/test/cur/123456:2,RS"
|
"/home/foo/Maildir/test/cur/123456:2,RS"
|
||||||
}, {
|
}, {
|
||||||
"/home/foo/Maildir/test/new/1313038887_0.697:2,",
|
"/home/foo/Maildir/test/new/1313038887_0.697:2,",
|
||||||
MU_MSG_FLAG_SEEN | MU_MSG_FLAG_FLAGGED | MU_MSG_FLAG_PASSED,
|
MU_FLAG_SEEN | MU_FLAG_FLAGGED | MU_FLAG_PASSED,
|
||||||
"/home/foo/Maildir/test/cur/1313038887_0.697:2,FPS"
|
"/home/foo/Maildir/test/cur/1313038887_0.697:2,FPS"
|
||||||
},
|
}, {
|
||||||
|
|
||||||
{
|
|
||||||
"/home/djcb/Maildir/trash/new/1312920597.2206_16.cthulhu",
|
"/home/djcb/Maildir/trash/new/1312920597.2206_16.cthulhu",
|
||||||
MU_MSG_FLAG_SEEN,
|
MU_FLAG_SEEN,
|
||||||
"/home/djcb/Maildir/trash/cur/1312920597.2206_16.cthulhu:2,S"
|
"/home/djcb/Maildir/trash/cur/1312920597.2206_16.cthulhu:2,S"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -155,7 +155,7 @@ test_mu_msg_02 (void)
|
||||||
g_assert_cmpint (i,==,2);
|
g_assert_cmpint (i,==,2);
|
||||||
|
|
||||||
g_assert_cmpuint (mu_msg_get_flags(msg),
|
g_assert_cmpuint (mu_msg_get_flags(msg),
|
||||||
==, MU_MSG_FLAG_SEEN);
|
==, MU_FLAG_SEEN);
|
||||||
|
|
||||||
mu_msg_unref (msg);
|
mu_msg_unref (msg);
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ test_mu_msg_03 (void)
|
||||||
"\nLet's write some fünkÿ text\nusing umlauts.\n\nFoo.\n");
|
"\nLet's write some fünkÿ text\nusing umlauts.\n\nFoo.\n");
|
||||||
|
|
||||||
g_assert_cmpuint (mu_msg_get_flags(msg),
|
g_assert_cmpuint (mu_msg_get_flags(msg),
|
||||||
==, MU_MSG_FLAG_UNREAD);
|
==, MU_FLAG_UNREAD);
|
||||||
|
|
||||||
|
|
||||||
mu_msg_unref (msg);
|
mu_msg_unref (msg);
|
||||||
|
@ -211,7 +211,7 @@ test_mu_msg_04 (void)
|
||||||
==, 0);
|
==, 0);
|
||||||
|
|
||||||
g_assert_cmpuint (mu_msg_get_flags(msg),
|
g_assert_cmpuint (mu_msg_get_flags(msg),
|
||||||
==, MU_MSG_FLAG_HAS_ATTACH);
|
==, MU_FLAG_HAS_ATTACH);
|
||||||
|
|
||||||
mu_msg_unref (msg);
|
mu_msg_unref (msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,15 +124,15 @@ static void
|
||||||
treecell_func (GtkTreeViewColumn * tree_column, GtkCellRenderer * renderer,
|
treecell_func (GtkTreeViewColumn * tree_column, GtkCellRenderer * renderer,
|
||||||
GtkTreeModel * tree_model, GtkTreeIter * iter, gpointer data)
|
GtkTreeModel * tree_model, GtkTreeIter * iter, gpointer data)
|
||||||
{
|
{
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
MuMsgPrio prio;
|
MuMsgPrio prio;
|
||||||
|
|
||||||
gtk_tree_model_get (tree_model, iter,
|
gtk_tree_model_get (tree_model, iter,
|
||||||
MUG_COL_FLAGS, &flags, MUG_COL_PRIO, &prio, -1);
|
MUG_COL_FLAGS, &flags, MUG_COL_PRIO, &prio, -1);
|
||||||
|
|
||||||
g_object_set (G_OBJECT (renderer),
|
g_object_set (G_OBJECT (renderer),
|
||||||
"weight", (flags & MU_MSG_FLAG_NEW) ? 800 : 400,
|
"weight", (flags & MU_FLAG_NEW) ? 800 : 400,
|
||||||
"weight", (flags & MU_MSG_FLAG_SEEN) ? 400 : 800,
|
"weight", (flags & MU_FLAG_SEEN) ? 400 : 800,
|
||||||
"foreground", prio == MU_MSG_PRIO_HIGH ? "red" : NULL,
|
"foreground", prio == MU_MSG_PRIO_HIGH ? "red" : NULL,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ add_row (GtkListStore * store, MuMsg *msg)
|
||||||
datestr = timeval == 0 ? "-" : mu_date_display_s (timeval);
|
datestr = timeval == 0 ? "-" : mu_date_display_s (timeval);
|
||||||
from = empty_or_display_contact (mu_msg_get_from (msg));
|
from = empty_or_display_contact (mu_msg_get_from (msg));
|
||||||
to = empty_or_display_contact (mu_msg_get_to (msg));
|
to = empty_or_display_contact (mu_msg_get_to (msg));
|
||||||
flagstr = mu_msg_flags_str_s (mu_msg_get_flags (msg));
|
flagstr = mu_flags_to_str_s (mu_msg_get_flags (msg), MU_FLAG_TYPE_ANY);
|
||||||
|
|
||||||
gtk_list_store_append (store, &treeiter);
|
gtk_list_store_append (store, &treeiter);
|
||||||
gtk_list_store_set (store, &treeiter,
|
gtk_list_store_set (store, &treeiter,
|
||||||
|
|
|
@ -125,15 +125,15 @@ static void
|
||||||
treecell_func (GtkTreeViewColumn * tree_column, GtkCellRenderer * renderer,
|
treecell_func (GtkTreeViewColumn * tree_column, GtkCellRenderer * renderer,
|
||||||
GtkTreeModel * tree_model, GtkTreeIter * iter, gpointer data)
|
GtkTreeModel * tree_model, GtkTreeIter * iter, gpointer data)
|
||||||
{
|
{
|
||||||
MuMsgFlags flags;
|
MuFlags flags;
|
||||||
MuMsgPrio prio;
|
MuMsgPrio prio;
|
||||||
|
|
||||||
gtk_tree_model_get (tree_model, iter,
|
gtk_tree_model_get (tree_model, iter,
|
||||||
MUG_COL_FLAGS, &flags, MUG_COL_PRIO, &prio, -1);
|
MUG_COL_FLAGS, &flags, MUG_COL_PRIO, &prio, -1);
|
||||||
|
|
||||||
g_object_set (G_OBJECT (renderer),
|
g_object_set (G_OBJECT (renderer),
|
||||||
"weight", (flags & MU_MSG_FLAG_NEW) ? 800 : 400,
|
"weight", (flags & MU_FLAG_NEW) ? 800 : 400,
|
||||||
"weight", (flags & MU_MSG_FLAG_SEEN) ? 400 : 800,
|
"weight", (flags & MU_FLAG_SEEN) ? 400 : 800,
|
||||||
"foreground", prio == MU_MSG_PRIO_HIGH ? "red" : NULL,
|
"foreground", prio == MU_MSG_PRIO_HIGH ? "red" : NULL,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
@ -364,7 +364,7 @@ add_row (GtkTreeStore * store, MuMsg *msg, GtkTreeIter *treeiter)
|
||||||
datestr = timeval == 0 ? "-" : mu_date_display_s (timeval);
|
datestr = timeval == 0 ? "-" : mu_date_display_s (timeval);
|
||||||
from = empty_or_display_contact (mu_msg_get_from (msg));
|
from = empty_or_display_contact (mu_msg_get_from (msg));
|
||||||
to = empty_or_display_contact (mu_msg_get_to (msg));
|
to = empty_or_display_contact (mu_msg_get_to (msg));
|
||||||
flagstr = mu_msg_flags_str_s (mu_msg_get_flags (msg));
|
flagstr = mu_flags_to_str_s (mu_msg_get_flags (msg), MU_FLAG_TYPE_ANY);
|
||||||
|
|
||||||
/* if (0) { */
|
/* if (0) { */
|
||||||
/* GtkTreeIter myiter; */
|
/* GtkTreeIter myiter; */
|
||||||
|
|
Loading…
Reference in New Issue