centralize message flag pretty-printing somewhat
the flag values themselves are central, so we can centralize their most common representation (Maildir's) just as well.
This commit is contained in:
parent
d789f0c1ce
commit
f2450cc4b8
14
src/driver.c
14
src/driver.c
|
@ -9,6 +9,20 @@
|
||||||
|
|
||||||
driver_t *drivers[N_DRIVERS] = { &maildir_driver, &imap_driver };
|
driver_t *drivers[N_DRIVERS] = { &maildir_driver, &imap_driver };
|
||||||
|
|
||||||
|
// Keep the MESSAGE_FLAGS in sync (grep that)!
|
||||||
|
const char MsgFlags[] = { 'D', 'F', 'P', 'R', 'S', 'T' };
|
||||||
|
|
||||||
|
void
|
||||||
|
make_flags( uchar flags, char *buf )
|
||||||
|
{
|
||||||
|
uint i, d;
|
||||||
|
|
||||||
|
for (i = d = 0; i < as(MsgFlags); i++)
|
||||||
|
if (flags & (1 << i))
|
||||||
|
buf[d++] = MsgFlags[i];
|
||||||
|
buf[d] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint
|
uint
|
||||||
count_generic_messages( message_t *msgs )
|
count_generic_messages( message_t *msgs )
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,8 +31,7 @@ typedef struct store_conf {
|
||||||
} store_conf_t;
|
} store_conf_t;
|
||||||
|
|
||||||
/* For message->flags */
|
/* For message->flags */
|
||||||
/* Keep the mailbox driver flag definitions in sync: */
|
// Keep the MESSAGE_FLAGS in sync (grep that)!
|
||||||
/* grep for MAILBOX_DRIVER_FLAG */
|
|
||||||
/* The order is according to alphabetical maildir flag sort */
|
/* The order is according to alphabetical maildir flag sort */
|
||||||
#define F_DRAFT (1<<0) /* Draft */
|
#define F_DRAFT (1<<0) /* Draft */
|
||||||
#define F_FLAGGED (1<<1) /* Flagged */
|
#define F_FLAGGED (1<<1) /* Flagged */
|
||||||
|
@ -42,6 +41,9 @@ typedef struct store_conf {
|
||||||
#define F_DELETED (1<<5) /* Trashed */
|
#define F_DELETED (1<<5) /* Trashed */
|
||||||
#define NUM_FLAGS 6
|
#define NUM_FLAGS 6
|
||||||
|
|
||||||
|
extern const char MsgFlags[NUM_FLAGS];
|
||||||
|
void make_flags( uchar flags, char *buf );
|
||||||
|
|
||||||
/* For message->status */
|
/* For message->status */
|
||||||
#define M_RECENT (1<<0) /* unsyncable flag; maildir_* depend on this being 1<<0 */
|
#define M_RECENT (1<<0) /* unsyncable flag; maildir_* depend on this being 1<<0 */
|
||||||
#define M_DEAD (1<<1) /* expunged */
|
#define M_DEAD (1<<1) /* expunged */
|
||||||
|
|
|
@ -266,9 +266,7 @@ static int imap_deref( imap_store_t *ctx );
|
||||||
|
|
||||||
static void imap_invoke_bad_callback( imap_store_t *ctx );
|
static void imap_invoke_bad_callback( imap_store_t *ctx );
|
||||||
|
|
||||||
/* Keep the mailbox driver flag definitions in sync: */
|
// Keep the MESSAGE_FLAGS in sync (grep that)!
|
||||||
/* grep for MAILBOX_DRIVER_FLAG */
|
|
||||||
/* The order is according to alphabetical maildir flag sort */
|
|
||||||
static const char *Flags[] = {
|
static const char *Flags[] = {
|
||||||
"\\Draft", /* 'D' */
|
"\\Draft", /* 'D' */
|
||||||
"\\Flagged", /* 'F' */
|
"\\Flagged", /* 'F' */
|
||||||
|
|
|
@ -87,11 +87,6 @@ static struct flock lck;
|
||||||
|
|
||||||
static int MaildirCount;
|
static int MaildirCount;
|
||||||
|
|
||||||
/* Keep the mailbox driver flag definitions in sync: */
|
|
||||||
/* grep for MAILBOX_DRIVER_FLAG */
|
|
||||||
/* The order is according to alphabetical maildir flag sort */
|
|
||||||
static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' };
|
|
||||||
|
|
||||||
static uchar
|
static uchar
|
||||||
maildir_parse_flags( const char *info_prefix, const char *base )
|
maildir_parse_flags( const char *info_prefix, const char *base )
|
||||||
{
|
{
|
||||||
|
@ -101,8 +96,8 @@ maildir_parse_flags( const char *info_prefix, const char *base )
|
||||||
|
|
||||||
flags = 0;
|
flags = 0;
|
||||||
if ((s = strstr( base, info_prefix )))
|
if ((s = strstr( base, info_prefix )))
|
||||||
for (s += 3, i = 0; i < as(Flags); i++)
|
for (s += 3, i = 0; i < as(MsgFlags); i++)
|
||||||
if (strchr( s, Flags[i] ))
|
if (strchr( s, MsgFlags[i] ))
|
||||||
flags |= (1 << i);
|
flags |= (1 << i);
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
@ -1570,9 +1565,9 @@ maildir_make_flags( char info_delimiter, uchar flags, char *buf )
|
||||||
buf[0] = info_delimiter;
|
buf[0] = info_delimiter;
|
||||||
buf[1] = '2';
|
buf[1] = '2';
|
||||||
buf[2] = ',';
|
buf[2] = ',';
|
||||||
for (d = 3, i = 0; i < (int)as(Flags); i++)
|
for (d = 3, i = 0; i < (int)as(MsgFlags); i++)
|
||||||
if (flags & (1 << i))
|
if (flags & (1 << i))
|
||||||
buf[d++] = Flags[i];
|
buf[d++] = MsgFlags[i];
|
||||||
buf[d] = 0;
|
buf[d] = 0;
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
@ -1690,24 +1685,24 @@ maildir_set_msg_flags( store_t *gctx, message_t *gmsg, uint uid ATTR_UNUSED, int
|
||||||
for (;;) {
|
for (;;) {
|
||||||
bl = bbl + nfsnprintf( buf + bbl, _POSIX_PATH_MAX - bbl, "%s/", subdirs[gmsg->status & M_RECENT] );
|
bl = bbl + nfsnprintf( buf + bbl, _POSIX_PATH_MAX - bbl, "%s/", subdirs[gmsg->status & M_RECENT] );
|
||||||
ol = strlen( msg->base );
|
ol = strlen( msg->base );
|
||||||
if (_POSIX_PATH_MAX - bl < ol + 3 + NUM_FLAGS)
|
if (_POSIX_PATH_MAX - bl < ol + 3 + (int)as(MsgFlags))
|
||||||
oob();
|
oob();
|
||||||
memcpy( buf + bl, msg->base, (size_t)ol + 1 );
|
memcpy( buf + bl, msg->base, (size_t)ol + 1 );
|
||||||
memcpy( nbuf + bl, msg->base, (size_t)ol + 1 );
|
memcpy( nbuf + bl, msg->base, (size_t)ol + 1 );
|
||||||
if ((s = strstr( nbuf + bl, conf->info_prefix ))) {
|
if ((s = strstr( nbuf + bl, conf->info_prefix ))) {
|
||||||
s += 3;
|
s += 3;
|
||||||
fl = ol - (s - (nbuf + bl));
|
fl = ol - (s - (nbuf + bl));
|
||||||
for (i = 0; i < as(Flags); i++) {
|
for (i = 0; i < as(MsgFlags); i++) {
|
||||||
if ((p = strchr( s, Flags[i] ))) {
|
if ((p = strchr( s, MsgFlags[i] ))) {
|
||||||
if (del & (1 << i)) {
|
if (del & (1 << i)) {
|
||||||
memmove( p, p + 1, (size_t)fl - (size_t)(p - s) );
|
memmove( p, p + 1, (size_t)fl - (size_t)(p - s) );
|
||||||
fl--;
|
fl--;
|
||||||
}
|
}
|
||||||
} else if (add & (1 << i)) {
|
} else if (add & (1 << i)) {
|
||||||
for (j = 0; j < fl && Flags[i] > s[j]; j++);
|
for (j = 0; j < fl && MsgFlags[i] > s[j]; j++);
|
||||||
fl++;
|
fl++;
|
||||||
memmove( s + j + 1, s + j, (size_t)(fl - j) );
|
memmove( s + j + 1, s + j, (size_t)(fl - j) );
|
||||||
s[j] = Flags[i];
|
s[j] = MsgFlags[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tl = ol + 3 + fl;
|
tl = ol + 3 + fl;
|
||||||
|
|
|
@ -27,23 +27,6 @@ typedef union proxy_store {
|
||||||
};
|
};
|
||||||
} proxy_store_t;
|
} proxy_store_t;
|
||||||
|
|
||||||
/* Keep the mailbox driver flag definitions in sync: */
|
|
||||||
/* grep for MAILBOX_DRIVER_FLAG */
|
|
||||||
/* The order is according to alphabetical maildir flag sort */
|
|
||||||
static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' };
|
|
||||||
|
|
||||||
static char *
|
|
||||||
proxy_make_flags( uchar flags, char *buf )
|
|
||||||
{
|
|
||||||
uint i, d;
|
|
||||||
|
|
||||||
for (d = 0, i = 0; i < as(Flags); i++)
|
|
||||||
if (flags & (1 << i))
|
|
||||||
buf[d++] = Flags[i];
|
|
||||||
buf[d] = 0;
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
proxy_store_deref( proxy_store_t *ctx )
|
proxy_store_deref( proxy_store_t *ctx )
|
||||||
{
|
{
|
||||||
|
@ -274,10 +257,10 @@ static @type@proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@v
|
||||||
//# DEFINE load_box_print_pass_cb_args , cmd->sts, cmd->total_msgs, cmd->recent_msgs
|
//# DEFINE load_box_print_pass_cb_args , cmd->sts, cmd->total_msgs, cmd->recent_msgs
|
||||||
//# DEFINE load_box_print_cb_args
|
//# DEFINE load_box_print_cb_args
|
||||||
if (cmd->sts == DRV_OK) {
|
if (cmd->sts == DRV_OK) {
|
||||||
char fbuf[as(Flags) + 1];
|
char fbuf[as(MsgFlags) + 1];
|
||||||
for (message_t *msg = cmd->msgs; msg; msg = msg->next)
|
for (message_t *msg = cmd->msgs; msg; msg = msg->next)
|
||||||
debug( " uid=%-5u flags=%-4s size=%-6u tuid=%." stringify(TUIDL) "s\n",
|
debug( " uid=%-5u flags=%-4s size=%-6u tuid=%." stringify(TUIDL) "s\n",
|
||||||
msg->uid, (msg->status & M_FLAGS) ? (proxy_make_flags( msg->flags, fbuf ), fbuf) : "?", msg->size, *msg->tuid ? msg->tuid : "?" );
|
msg->uid, (msg->status & M_FLAGS) ? (make_flags( msg->flags, fbuf ), fbuf) : "?", msg->size, *msg->tuid ? msg->tuid : "?" );
|
||||||
}
|
}
|
||||||
//# END
|
//# END
|
||||||
|
|
||||||
|
@ -299,8 +282,8 @@ static @type@proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@v
|
||||||
//# DEFINE fetch_msg_print_fmt_args , uid=%u, want_flags=%s, want_date=%s
|
//# DEFINE fetch_msg_print_fmt_args , uid=%u, want_flags=%s, want_date=%s
|
||||||
//# DEFINE fetch_msg_print_pass_args , msg->uid, !(msg->status & M_FLAGS) ? "yes" : "no", data->date ? "yes" : "no"
|
//# DEFINE fetch_msg_print_pass_args , msg->uid, !(msg->status & M_FLAGS) ? "yes" : "no", data->date ? "yes" : "no"
|
||||||
//# DEFINE fetch_msg_pre_print_cb_args
|
//# DEFINE fetch_msg_pre_print_cb_args
|
||||||
char fbuf[as(Flags) + 1];
|
char fbuf[as(MsgFlags) + 1];
|
||||||
proxy_make_flags( cmd->data->flags, fbuf );
|
make_flags( cmd->data->flags, fbuf );
|
||||||
//# END
|
//# END
|
||||||
//# DEFINE fetch_msg_print_fmt_cb_args , flags=%s, date=%lld, size=%u
|
//# DEFINE fetch_msg_print_fmt_cb_args , flags=%s, date=%lld, size=%u
|
||||||
//# DEFINE fetch_msg_print_pass_cb_args , fbuf, (long long)cmd->data->date, cmd->data->len
|
//# DEFINE fetch_msg_print_pass_cb_args , fbuf, (long long)cmd->data->date, cmd->data->len
|
||||||
|
@ -314,8 +297,8 @@ static @type@proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@v
|
||||||
//# END
|
//# END
|
||||||
|
|
||||||
//# DEFINE store_msg_pre_print_args
|
//# DEFINE store_msg_pre_print_args
|
||||||
char fbuf[as(Flags) + 1];
|
char fbuf[as(MsgFlags) + 1];
|
||||||
proxy_make_flags( data->flags, fbuf );
|
make_flags( data->flags, fbuf );
|
||||||
//# END
|
//# END
|
||||||
//# DEFINE store_msg_print_fmt_args , flags=%s, date=%lld, size=%u, to_trash=%s
|
//# DEFINE store_msg_print_fmt_args , flags=%s, date=%lld, size=%u, to_trash=%s
|
||||||
//# DEFINE store_msg_print_pass_args , fbuf, (long long)data->date, data->len, to_trash ? "yes" : "no"
|
//# DEFINE store_msg_print_pass_args , fbuf, (long long)data->date, data->len, to_trash ? "yes" : "no"
|
||||||
|
@ -329,9 +312,9 @@ static @type@proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@v
|
||||||
//# END
|
//# END
|
||||||
|
|
||||||
//# DEFINE set_msg_flags_pre_print_args
|
//# DEFINE set_msg_flags_pre_print_args
|
||||||
char fbuf1[as(Flags) + 1], fbuf2[as(Flags) + 1];
|
char fbuf1[as(MsgFlags) + 1], fbuf2[as(MsgFlags) + 1];
|
||||||
proxy_make_flags( add, fbuf1 );
|
make_flags( add, fbuf1 );
|
||||||
proxy_make_flags( del, fbuf2 );
|
make_flags( del, fbuf2 );
|
||||||
//# END
|
//# END
|
||||||
//# DEFINE set_msg_flags_print_fmt_args , uid=%u, add=%s, del=%s
|
//# DEFINE set_msg_flags_print_fmt_args , uid=%u, add=%s, del=%s
|
||||||
//# DEFINE set_msg_flags_print_pass_args , uid, fbuf1, fbuf2
|
//# DEFINE set_msg_flags_print_pass_args , uid, fbuf1, fbuf2
|
||||||
|
|
21
src/sync.c
21
src/sync.c
|
@ -29,19 +29,14 @@ int trash_total[2], trash_done[2];
|
||||||
const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" };
|
const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" };
|
||||||
|
|
||||||
|
|
||||||
/* Keep the mailbox driver flag definitions in sync: */
|
|
||||||
/* grep for MAILBOX_DRIVER_FLAG */
|
|
||||||
/* The order is according to alphabetical maildir flag sort */
|
|
||||||
static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' };
|
|
||||||
|
|
||||||
static uchar
|
static uchar
|
||||||
parse_flags( const char *buf )
|
parse_flags( const char *buf )
|
||||||
{
|
{
|
||||||
uint i, d;
|
uint i, d;
|
||||||
uchar flags;
|
uchar flags;
|
||||||
|
|
||||||
for (flags = i = d = 0; i < as(Flags); i++) {
|
for (flags = i = d = 0; i < as(MsgFlags); i++) {
|
||||||
if (buf[d] == Flags[i]) {
|
if (buf[d] == MsgFlags[i]) {
|
||||||
flags |= (1 << i);
|
flags |= (1 << i);
|
||||||
d++;
|
d++;
|
||||||
}
|
}
|
||||||
|
@ -49,18 +44,6 @@ parse_flags( const char *buf )
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint
|
|
||||||
make_flags( uchar flags, char *buf )
|
|
||||||
{
|
|
||||||
uint i, d;
|
|
||||||
|
|
||||||
for (i = d = 0; i < as(Flags); i++)
|
|
||||||
if (flags & (1 << i))
|
|
||||||
buf[d++] = Flags[i];
|
|
||||||
buf[d] = 0;
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is the (mostly) persistent status of the sync record.
|
// This is the (mostly) persistent status of the sync record.
|
||||||
// Most of these bits are actually mutually exclusive. It is a
|
// Most of these bits are actually mutually exclusive. It is a
|
||||||
// bitfield to allow for easy testing for multiple states.
|
// bitfield to allow for easy testing for multiple states.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user