Commit bd9d296b bd9d296b1cec6d2613ea11b1acd13208e7b727e8 by Sam Roberts

Moved date/time parsing utility functions to mailbox/mutil.c.

Added braces to initializers and removed unused variables prototyped shared
functions, made functions that didn't return return void. (to quiet gcc
-Wall),
1 parent 5ab52037
......@@ -23,7 +23,6 @@ imap4d_append (struct imap4d_command *command, char *arg)
{
char *sp;
char *mboxname;
char *attr_str;
int flags = 0;
mailbox_t dest_mbox = NULL;
int status;
......
......@@ -61,12 +61,6 @@ static int fetch_io __P ((stream_t, unsigned long, unsigned long,
static int fetch_header_fields __P ((message_t, char **, unsigned long, unsigned long));
static int fetch_header_fields_not __P ((message_t, char **, unsigned long, unsigned long));
static int fetch_send_address __P ((char *));
/* The internal date of the message. */
static const char *MONTHS[] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
static struct fetch_command* fetch_getcommand __P ((char *, struct fetch_command[]));
......
......@@ -69,15 +69,17 @@
# include <paths.h>
#endif
#include <mailutils/address.h>
#include <mailutils/body.h>
#include <mailutils/error.h>
#include <mailutils/filter.h>
#include <mailutils/folder.h>
#include <mailutils/header.h>
#include <mailutils/mailbox.h>
#include <mailutils/message.h>
#include <mailutils/header.h>
#include <mailutils/body.h>
#include <mailutils/address.h>
#include <mailutils/parse822.h>
#include <mailutils/registrar.h>
#include <mailutils/filter.h>
#include <mailutils/stream.h>
#include <mailutils/error.h>
#ifndef _PATH_MAILDIR
# define _PATH_MAILDIR "/usr/spool/mail"
......@@ -150,6 +152,7 @@ extern volatile size_t children;
/* Imap4 commands */
extern int imap4d_append __P ((struct imap4d_command *, char *));
extern int imap4d_append0 __P((mailbox_t mbox, int flags, char *text));
extern int imap4d_authenticate __P ((struct imap4d_command *, char *));
extern int imap4d_capability __P ((struct imap4d_command *, char *));
extern int imap4d_check __P ((struct imap4d_command *, char *));
......@@ -169,6 +172,7 @@ extern int imap4d_logout __P ((struct imap4d_command *, char *));
extern int imap4d_noop __P ((struct imap4d_command *, char *));
extern int imap4d_rename __P ((struct imap4d_command *, char *));
extern int imap4d_search __P ((struct imap4d_command *, char *));
extern int imap4d_search0 __P((char *arg, int isuid, char *replybuf, size_t replysize));
extern int imap4d_select __P ((struct imap4d_command *, char *));
extern int imap4d_select0 __P ((struct imap4d_command *, char *, int));
extern void imap4d_select_status __P((void));
......@@ -191,6 +195,8 @@ extern RETSIGTYPE imap4d_signal __P ((int));
extern int imap4d_bye __P ((int));
/* Namespace functions */
extern int set_namespace __P((int i, char *str));
extern int namespace_init __P((char *path));
extern char * namespace_getfullpath __P((char *name, const char *delim));
extern char * namespace_checkfullpath __P((char *name, const char *pattern,
const char *delim));
......@@ -218,9 +224,10 @@ extern struct imap4d_command *util_getcommand __P ((char *,
extern int util_parse_internal_date0 __P((char *date, time_t *timep, char **endp));
extern int util_parse_internal_date __P((char *date, time_t *timep));
extern int util_parse_822_date __P((char *date, time_t *timep));
extern int util_parse_ctime_date __P((char *date, time_t *timep));
extern int util_parse_ctime_date __P((const char *date, time_t *timep));
extern char *util_strcasestr __P((const char *haystack, const char *needle));
extern char *util_normalize_path (char *path, const char *delim);
extern char *util_normalize_path __P((char *path, const char *delim));
extern int util_parse_attributes __P((char *items, char **save, int *flags));
#ifdef __cplusplus
}
......
......@@ -74,7 +74,7 @@ printable_pathname(char *str)
return str;
}
static int
static void
print_namespace(int n)
{
int i;
......@@ -99,7 +99,7 @@ namespace_enumerate(int ns, nsfp_t f, void *closure)
int i, rc;
for (i = 0; i < namespace[ns].subdir_c; i++)
if (rc = (*f)(closure, ns, namespace[ns].subdir_v[i], '/'))
if ((rc = (*f)(closure, ns, namespace[ns].subdir_v[i], '/')))
return rc;
return 0;
}
......@@ -207,4 +207,5 @@ int
namespace_init(char *path)
{
set_namespace(NS_PRIVATE, path);
return 0;
}
......
......@@ -81,26 +81,26 @@ struct cond
/* List of basic conditions. <message set> is handled separately */
struct cond condlist[] =
{
"ALL", NULL, cond_all,
"BCC", "s", cond_bcc,
"BEFORE", "d", cond_before,
"BODY", "s", cond_body,
"CC", "s", cond_cc,
"FROM", "s", cond_from,
"HEADER", "ss", cond_header,
"KEYWORD", "s", cond_keyword,
"LARGER", "n", cond_larger,
"ON", "d", cond_on,
"SENTBEFORE", "d", cond_sentbefore,
"SENTON", "d", cond_senton,
"SENTSINCE", "d", cond_sentsince,
"SINCE", "d", cond_since,
"SMALLER", "n", cond_smaller,
"SUBJECT", "s", cond_subject,
"TEXT", "s", cond_text,
"TO", "s", cond_to,
"UID", "m", cond_uid,
NULL,
{ "ALL", NULL, cond_all },
{ "BCC", "s", cond_bcc },
{ "BEFORE", "d", cond_before },
{ "BODY", "s", cond_body },
{ "CC", "s", cond_cc },
{ "FROM", "s", cond_from },
{ "HEADER", "ss", cond_header },
{ "KEYWORD", "s", cond_keyword },
{ "LARGER", "n", cond_larger },
{ "ON", "d", cond_on },
{ "SENTBEFORE", "d", cond_sentbefore },
{ "SENTON", "d", cond_senton },
{ "SENTSINCE", "d", cond_sentsince },
{ "SINCE", "d", cond_since },
{ "SMALLER", "n", cond_smaller },
{ "SUBJECT", "s", cond_subject },
{ "TEXT", "s", cond_text },
{ "TO", "s", cond_to },
{ "UID", "m", cond_uid },
{ NULL }
};
/* Other search keys described by rfc2060 are implemented on top of these
......@@ -115,21 +115,21 @@ struct cond_equiv
struct cond_equiv equiv_list[] =
{
"ANSWERED", "KEYWORD \\Answered",
"DELETED", "KEYWORD \\Deleted",
"DRAFT", "KEYWORD \\Draft",
"FLAGGED", "KEYWORD \\Flagged",
"NEW", "(RECENT UNSEEN)",
"OLD", "NOT RECENT",
"RECENT", "KEYWORD \\Recent",
"SEEN", "KEYWORD \\Seen",
"UNANSWERED", "NOT KEYWORD \\Answered",
"UNDELETED", "NOT KEYWORD \\Deleted",
"UNDRAFT", "NOT KEYWORD \\Draft",
"UNFLAGGED", "NOT KEYWORD \\Flagged",
"UNKEYWORD", "NOT KEYWORD",
"UNSEEN", "NOT KEYWORD \\Seen",
NULL
{ "ANSWERED", "KEYWORD \\Answered" },
{ "DELETED", "KEYWORD \\Deleted" },
{ "DRAFT", "KEYWORD \\Draft" },
{ "FLAGGED", "KEYWORD \\Flagged" },
{ "NEW", "(RECENT UNSEEN)" },
{ "OLD", "NOT RECENT" },
{ "RECENT", "KEYWORD \\Recent" },
{ "SEEN", "KEYWORD \\Seen" },
{ "UNANSWERED", "NOT KEYWORD \\Answered" },
{ "UNDELETED", "NOT KEYWORD \\Deleted" },
{ "UNDRAFT", "NOT KEYWORD \\Draft" },
{ "UNFLAGGED", "NOT KEYWORD \\Flagged" },
{ "UNKEYWORD", "NOT KEYWORD" },
{ "UNSEEN", "NOT KEYWORD \\Seen" },
{ NULL }
};
/* A memory allocation chain used to keep track of objects allocated during
......@@ -204,8 +204,6 @@ imap4d_search (struct imap4d_command *command, char *arg)
int
imap4d_search0 (char *arg, int isuid, char *replybuf, size_t replysize)
{
char *sp ;
char *str;
struct parsebuf parsebuf;
memset (&parsebuf, 0, sizeof(parsebuf));
......@@ -277,8 +275,6 @@ void
do_search (struct parsebuf *pb)
{
size_t count = 0;
size_t *set = NULL;
int n = 0;
mailbox_messages_count (mbox, &count);
......@@ -411,6 +407,9 @@ parse_strdup (struct parsebuf *pb, char *s)
;
*/
int parse_simple_key (struct parsebuf *pb);
int parse_equiv_key (struct parsebuf *pb);
int
parse_search_key_list (struct parsebuf *pb)
{
......@@ -498,7 +497,6 @@ int
parse_simple_key (struct parsebuf *pb)
{
struct cond *condp;
char *t;
time_t time;
size_t *set = NULL;
int n = 0;
......@@ -614,7 +612,7 @@ _search_arg (struct parsebuf *pb)
return (void*)pb->code[pb->pc++];
}
static int
static void
_search_push (struct parsebuf *pb, int val)
{
if (pb->tos == pb->stacksize)
......@@ -793,7 +791,6 @@ cond_before (struct parsebuf *pb)
time_t mesg_time;
char buffer[512];
envelope_t env;
int rc = 0;
message_get_envelope (pb->msg, &env);
envelope_date (env, buffer, sizeof (buffer), NULL);
......@@ -878,7 +875,6 @@ cond_on (struct parsebuf *pb)
time_t mesg_time;
char buffer[512];
envelope_t env;
int rc = 0;
message_get_envelope (pb->msg, &env);
envelope_date (env, buffer, sizeof (buffer), NULL);
......@@ -923,7 +919,6 @@ cond_since (struct parsebuf *pb)
time_t mesg_time;
char buffer[512];
envelope_t env;
int rc = 0;
message_get_envelope (pb->msg, &env);
envelope_date (env, buffer, sizeof (buffer), NULL);
......
......@@ -671,21 +671,18 @@ add2set (size_t **set, int *n, unsigned long val)
return 0;
}
extern int imap_parse_date_time __P((const char **p, struct tm *tm, int *tz));
extern time_t mu_mktime __P((struct tm *timeptr, int tz));
int
util_parse_internal_date0 (char *date, time_t *timep, char **endp)
{
struct tm tm;
int tz;
mu_timezone tz;
time_t time;
char **datep = &date;
if (imap_parse_date_time((const char **)datep, &tm, &tz))
if (mu_parse_imap_date_time((const char **)datep, &tm, &tz))
return 1;
time = mu_mktime (&tm, tz);
time = mu_tm2time (&tm, &tz);
if (time == (time_t) -1)
return 2;
......@@ -706,58 +703,29 @@ int
util_parse_822_date (char *date, time_t *timep)
{
struct tm tm;
mu_timezone tz;
const char* p = date;
if (parse822_date_time(&date, date+strlen(date), &tm) == 0)
if (parse822_date_time(&p, date+strlen(date), &tm, &tz) == 0)
{
*timep = mu_mktime (&tm, 0);
*timep = mu_tm2time (&tm, &tz);
return 0;
}
return 1;
}
static const char *months[] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
int
util_parse_ctime_date (char *date, time_t *timep)
util_parse_ctime_date (const char *date, time_t *timep)
{
int year, mon, day, hour, min, sec;
int offt;
int i;
struct tm tm;
char month[5];
char wday[5];
month[0] = '\0';
wday[0] = '\0';
day = mon = year = hour = min = sec = offt = 0;
mu_timezone tz;
if (sscanf (date, "%3s %3s %2d %2d:%2d:%2d %d\n", wday, month, &day,
&hour, &min, &sec, &year) != 7)
return 1;
tm.tm_sec = sec;
tm.tm_min = min;
tm.tm_hour = hour;
for (i = 0; i < 12; i++)
if (mu_parse_ctime_date_time(&date, &tm, &tz) == 0)
{
if (strncasecmp (month, months[i], 3) == 0)
{
mon = i;
break;
}
}
tm.tm_mday = day;
tm.tm_mon = mon;
tm.tm_year = (year > 1900) ? year - 1900 : year;
tm.tm_yday = 0; /* unknown. */
tm.tm_wday = 0; /* unknown. */
tm.tm_isdst = -1; /* unknown. */
/* MOTE: UTC */
*timep = mu_mktime (&tm, 0);
*timep = mu_tm2time (&tm, &tz);
return 0;
}
return 1;
}
/* Return the first ocurrence of NEEDLE in HAYSTACK. Case insensitive
......