Commit ea01b2f9 ea01b2f9a46d6eb0666e613f1c536f9ee69dcf3e by Sergey Poznyakoff

imap4d: remove functions duplicated in the library

* imap4d/imap4d.h (util_format_attribute_flags)
(util_attribute_to_type): Remove. All uses changed to
mu_imap_format_flags and mu_imap_flag_to_attribute, respectively.
(util_type_to_attribute): Remove.
1 parent cef5f35d
......@@ -220,13 +220,13 @@ imap4d_append (struct imap4d_command *command, imap4d_tokbuf_t tok)
{
while (++i < argc)
{
int type;
char *arg = imap4d_tokbuf_getarg (tok, i);
if (!util_attribute_to_type (arg, &type))
flags |= type;
else if (arg[0] == ')')
if (arg[0] == ')')
break;
if (mu_imap_flag_to_attribute (arg, &flags))
return io_completion_response (command, RESP_BAD,
"Unrecognized flag");
}
if (i == argc)
return io_completion_response (command, RESP_BAD,
......
......@@ -105,6 +105,7 @@
#include <mailutils/cstr.h>
#include <mailutils/io.h>
#include <mailutils/prog.h>
#include <mailutils/imapio.h>
#include <mu_umaxtostr.h>
#include <muaux.h>
......@@ -397,10 +398,8 @@ extern char *util_localname (void);
extern int util_wcard_match (const char *string, const char *pattern,
const char *delim);
int util_format_attribute_flags (mu_stream_t str, int flags);
void util_print_flags (mu_attribute_t attr);
int util_attribute_to_type (const char *item, int *type);
int util_type_to_attribute (int type, char **attr_str);
int util_attribute_matches_flag (mu_attribute_t attr, const char *item);
int util_uidvalidity (mu_mailbox_t smbox, unsigned long *uidvp);
......
......@@ -80,13 +80,8 @@ store_thunk (imap4d_parsebuf_t p)
imap4d_parsebuf_next (p, 1);
do
{
int t;
if (util_attribute_to_type (p->token, &t))
imap4d_parsebuf_exit (p, "Failed to parse flags");
else
pclos->type |= t;
}
if (mu_imap_flag_to_attribute (p->token, &pclos->type))
imap4d_parsebuf_exit (p, "Unrecognized flag");
while (imap4d_parsebuf_next (p, 1) && p->token[0] != ')');
return RESP_OK;
}
......
......@@ -100,7 +100,7 @@ notify (void)
if (nflags != attr_table[i-1])
{
io_sendf ("* %lu FETCH FLAGS (", (unsigned long) i);
util_format_attribute_flags (iostream, nflags);
mu_imap_format_flags (iostream, nflags);
io_sendf (")\n");
attr_table[i-1] = nflags;
}
......
......@@ -30,16 +30,20 @@ util_tilde_expansion (const char *ref, const char *delim)
char *
util_getfullpath (const char *name, const char *delim)
{
char *p = util_tilde_expansion (name, delim);
if (*p != delim[0])
char *exp = util_tilde_expansion (name, delim);
if (*exp != delim[0])
{
char *s =
calloc (strlen (imap4d_homedir) + strlen (delim) + strlen (p) + 1, 1);
sprintf (s, "%s%s%s", imap4d_homedir, delim, p);
free (p);
p = s;
char *p, *s =
malloc (strlen (imap4d_homedir) + strlen (delim) + strlen (exp) + 1);
if (!s)
imap4d_bye (ERR_NO_MEM);
p = strcpy (s, imap4d_homedir);
p = mu_stpcpy (p, (char*) delim);
strcpy (p, exp);
free (exp);
exp = s;
}
return mu_normalize_path (p);
return mu_normalize_path (exp);
}
/* A message set is defined as:
......@@ -496,76 +500,13 @@ util_strcasestr (const char *haystack, const char *needle)
return mu_c_strcasestr (haystack, needle);
}
struct
{
char *name;
int flag;
}
_imap4d_attrlist[] =
{
{ "\\Answered", MU_ATTRIBUTE_ANSWERED },
{ "\\Flagged", MU_ATTRIBUTE_FLAGGED },
{ "\\Deleted", MU_ATTRIBUTE_DELETED },
{ "\\Draft", MU_ATTRIBUTE_DRAFT },
{ "\\Seen", MU_ATTRIBUTE_SEEN|MU_ATTRIBUTE_READ },
};
#define NATTR sizeof(_imap4d_attrlist)/sizeof(_imap4d_attrlist[0])
int _imap4d_nattr = NATTR;
int
util_attribute_to_type (const char *item, int *type)
{
int i;
if (mu_c_strcasecmp (item, "\\Recent") == 0)
{
*type = MU_ATTRIBUTE_RECENT;
return 0;
}
for (i = 0; i < _imap4d_nattr; i++)
if (mu_c_strcasecmp (item, _imap4d_attrlist[i].name) == 0)
{
*type = _imap4d_attrlist[i].flag;
return 0;
}
return 1;
}
int
util_format_attribute_flags (mu_stream_t str, int flags)
{
int i;
int delim = 0;
for (i = 0; i < _imap4d_nattr; i++)
if (flags & _imap4d_attrlist[i].flag)
{
if (delim)
mu_stream_printf (str, " ");
mu_stream_printf (str, "%s", _imap4d_attrlist[i].name);
delim = 1;
}
if (MU_ATTRIBUTE_IS_UNSEEN (flags))
{
if (delim)
mu_stream_printf (str, " ");
mu_stream_printf (str, "\\Recent");
}
return 0;
}
void
util_print_flags (mu_attribute_t attr)
{
int flags = 0;
mu_attribute_get_flags (attr, &flags);
util_format_attribute_flags (iostream, flags);
mu_imap_format_flags (iostream, flags);
}
int
......@@ -574,7 +515,7 @@ util_attribute_matches_flag (mu_attribute_t attr, const char *item)
int flags = 0, mask = 0;
mu_attribute_get_flags (attr, &flags);
util_attribute_to_type (item, &mask);
mu_imap_flag_to_attribute (item, &mask);
if (mask == MU_ATTRIBUTE_RECENT)
return MU_ATTRIBUTE_IS_UNSEEN (flags);
......