diff options
| author | Sam Varshavchik | 2015-03-04 20:10:05 -0500 |
|---|---|---|
| committer | Sam Varshavchik | 2015-03-04 20:10:05 -0500 |
| commit | 070a5986a3ada0cd6cbb74c77f4e41ed3c4eb48c (patch) | |
| tree | 96f6fe07a4a3be2812f20feb5611d6efdf820e95 /imap | |
| parent | 0feb9a21453515e53fbf024fd09455af42d01bf1 (diff) | |
| download | courier-libs-070a5986a3ada0cd6cbb74c77f4e41ed3c4eb48c.tar.bz2 | |
imap: handle 01-Jan-1970 as a valid search date.
Diffstat (limited to 'imap')
| -rw-r--r-- | imap/ChangeLog | 4 | ||||
| -rw-r--r-- | imap/imapd.c | 41 | ||||
| -rw-r--r-- | imap/search.c | 48 | ||||
| -rw-r--r-- | imap/smap.c | 11 | ||||
| -rw-r--r-- | imap/thread.c | 9 |
5 files changed, 65 insertions, 48 deletions
diff --git a/imap/ChangeLog b/imap/ChangeLog index 66063b3..f773664 100644 --- a/imap/ChangeLog +++ b/imap/ChangeLog @@ -1,3 +1,7 @@ +2015-03-04 Sam Varshavchik <mrsam@courier-mta.com> + + * Handle 01-Jan-1970 for date-based searches. + 2015-02-28 Sam Varshavchik <mrsam@courier-mta.com> * Update to courier-unicode 1.2. diff --git a/imap/imapd.c b/imap/imapd.c index 1396429..0b00b3c 100644 --- a/imap/imapd.c +++ b/imap/imapd.c @@ -84,6 +84,7 @@ #include "maildir/maildirkeywords.h" #include "maildir/maildirinfo.h" #include "maildir/loginexec.h" +#include "rfc822/rfc822.h" #include <courier-unicode.h> #include "maildir/maildirkeywords.h" @@ -92,7 +93,6 @@ #define KEYWORD_IMAPVERBOTTEN " (){%*\"\\]" #define KEYWORD_SMAPVERBOTTEN "," -extern time_t rfc822_parsedt(const char *); extern void fetchflags(unsigned long); extern unsigned long header_count, body_count; extern time_t start_time; @@ -175,7 +175,7 @@ void quotainfo_out(const char* qroot) char quotabuf[QUOTABUFSIZE]; char qresult[200]=""; char qbuf[200]; - + if ((maildir_getquota(".", quotabuf) == 0) && (strcmp(qroot,"ROOT") == 0)) { struct maildirsize quotainfo; @@ -186,7 +186,7 @@ void quotainfo_out(const char* qroot) quotainfo.quota.nbytes=quotainfo.size.nbytes= quotainfo.quota.nmessages= quotainfo.size.nmessages=0; - + if (quotainfo.quota.nbytes > 0) { sprintf(qbuf,"STORAGE %ld %ld", @@ -403,7 +403,7 @@ char *decode_valid_mailbox(const char *p, int autosubscribe) return (NULL); } -static time_t decode_date_time(char *p) +static int decode_date_time(char *p, time_t *tret) { unsigned i; @@ -414,7 +414,7 @@ unsigned i; if (!p[i]) return (0); if (p[i] == '-') p[i]=' '; } - return (rfc822_parsedt(p)); + return (rfc822_parsedate_chk(p, tret)); } int get_flagname(const char *p, struct imapflags *flags) @@ -716,7 +716,7 @@ int rb; nbytes -= n; if (p[n-1] == '\n') lastnl = 1; else lastnl = 0; - + while (n) { e = memchr(p, '\r', n); @@ -729,7 +729,7 @@ int rb; rb = fwrite(p, 1, e-p, fp); } else - { + { rb = fwrite(p, 1, n, fp); } n -= rb; @@ -759,7 +759,7 @@ int rb; nbytes=ftell(fp); if (nbytes == (unsigned long)-1 || (p=maildir_requota(newname, nbytes)) == 0) - + { fclose(fp); unlink(tmpname); @@ -1162,7 +1162,7 @@ void doNoop(int real_noop) #endif struct noopKeywordUpdateInfo kui; - imapscan_init(&new_maildir_info); + imapscan_init(&new_maildir_info); if (imapscan_maildir(&new_maildir_info, current_mailbox, 0, current_mailbox_ro, NULL)) @@ -1484,7 +1484,7 @@ static int doId() writes("\" \"os-version\" \""); writeqs(uts.release); } - + } } #endif @@ -2782,7 +2782,7 @@ static void writeacl(const char *aclstr) writeqs(p); free(p); } - + static int list_acl_cb(const char *ident, const maildir_aclt *acl, void *cb_arg) @@ -3273,7 +3273,7 @@ void aclminimum(const char *identifier) writes(*identifier == '-' ? "\"\"":ACL_ADMINISTER ACL_LOOKUP); writes(" " ACL_CREATE - " " ACL_EXPUNGE + " " ACL_EXPUNGE " " ACL_INSERT " " ACL_POST " " ACL_READ @@ -3886,8 +3886,7 @@ static int append(const char *tag, const char *mailbox, const char *path) if (curtoken->tokentype == IT_QUOTED_STRING) { - timestamp=decode_date_time(curtoken->tokenbuf); - if (timestamp == 0) + if (decode_date_time(curtoken->tokenbuf, ×tamp)) { libmail_kwmDestroy(keywords); return (-1); @@ -4270,7 +4269,7 @@ int uid=0; rc=mailbox_scan(reference, name, list_flags, list_callback, cmdbuf); - + free(reference); free(name); if (rc == 0) @@ -4324,7 +4323,7 @@ int uid=0; ACL_INSERT); return 0; } - + rc=append(tag, tok->tokenbuf, p); free(p); maildir_info_destroy(&mi); @@ -6122,7 +6121,7 @@ int uid=0; append_rights, ACL_INSERT ACL_DELETEMSGS ACL_SEEN ACL_WRITE); - + if (strchr(append_rights, ACL_INSERT[0]) == NULL) { writes(tag); @@ -6334,7 +6333,7 @@ char *p, *q; *p=0; p=strrchr(q, '/'); } - + if (p) p[1]=0; else *q=0; @@ -6568,14 +6567,14 @@ int main(int argc, char **argv) if (!p) dogethostname(); - if ((p=getenv("IMAP_TRASHFOLDERNAME")) != 0 && *p) + if ((p=getenv("IMAP_TRASHFOLDERNAME")) != 0 && *p) { trash = strdup(p); dot_trash = malloc(strlen(trash) + 2); dot_trash[0] = '.'; - strcpy(&dot_trash[1], trash); + strcpy(&dot_trash[1], trash); } - + #if 0 mdcreate("." DRAFTS); #endif diff --git a/imap/search.c b/imap/search.c index 1aa0007..cc64bbf 100644 --- a/imap/search.c +++ b/imap/search.c @@ -215,12 +215,12 @@ int rc; { /* No, search the headers then */ /* struct rfc2045 *rfcp=rfc2045_fromfp(fp); */ - struct rfc2045 *rfcp=rfc2045header_fromfp(fp); + struct rfc2045 *rfcp=rfc2045header_fromfp(fp); fill_search_header(sihead, charset, rfcp, fp, current_maildir_info.msgs+i); rc=search_evaluate(si); - rfc2045_free(rfcp); + rfc2045_free(rfcp); if (rc < 0) { @@ -302,16 +302,16 @@ unsigned long i, j; ** Use convenient RFC822 functions for that purpose. */ -static time_t decode_date(char *p) +static int decode_date(char *p, time_t *tret) { -char *s=malloc(strlen(p)+sizeof(" 00:00:00")); -unsigned i; -time_t t; + char *s=malloc(strlen(p)+sizeof(" 00:00:00")); + unsigned i; + int ret; if (!s) write_error_exit(0); /* Convert to format rfc822_parsedt likes */ - + for (i=1; p[i] != ' '; i++) { if (!p[i]) break; @@ -324,9 +324,9 @@ time_t t; s[i]=' '; } - t=rfc822_parsedt(s); + ret=rfc822_parsedate_chk(s, tret); free(s); - return (t); + return (ret); } /* Given a time_t that falls on, say, 3-Aug-1999 9:50:43 local time, @@ -345,7 +345,10 @@ char buf1[60], buf2[80]; strcat(buf2, " "); strcat(buf2, strtok(0, " ")); strcat(buf2, " 00:00:00"); - return (rfc822_parsedt(buf2)); + + rfc822_parsedate_chk(buf2, &t); + + return t; } static char *timestamp_for_sorting(time_t t) @@ -474,27 +477,30 @@ static void fill_search_quick(struct searchinfo *p, case search_before: p->value=0; { - time_t t=decode_date(p->as); + time_t t; - if (t && timestamp_to_day(stat_buf->st_mtime) < t) + if (decode_date(p->as, &t) == 0 && + timestamp_to_day(stat_buf->st_mtime) < t) p->value=1; } break; case search_since: p->value=0; { - time_t t=decode_date(p->as); + time_t t; - if (t && timestamp_to_day(stat_buf->st_mtime) >= t) + if (decode_date(p->as, &t) == 0 && + timestamp_to_day(stat_buf->st_mtime) >= t) p->value=1; } break; case search_on: p->value=0; { - time_t t=decode_date(p->as); + time_t t; - if (t && timestamp_to_day(stat_buf->st_mtime) == t) + if (decode_date(p->as, &t) == 0 && + timestamp_to_day(stat_buf->st_mtime) == t) p->value=1; } break; @@ -787,8 +793,9 @@ static int headerfilter_func(const char *name, const char *value, void *arg) if (isdate == 0 && sip->as == 0) { - time_t msg_time=rfc822_parsedt(value); + time_t msg_time; + rfc822_parsedate_chk(value, &msg_time); sip->as=timestamp_for_sorting(msg_time); } break; @@ -802,10 +809,11 @@ static int headerfilter_func(const char *name, const char *value, void *arg) if (isdate == 0) { - time_t given_time=decode_date(sip->as); - time_t msg_time=rfc822_parsedt(value); + time_t given_time; + time_t msg_time; - if (given_time == 0 || msg_time == 0) + if (decode_date(sip->as, &given_time) + || rfc822_parsedate_chk(value, &msg_time)) break; msg_time=timestamp_to_day(msg_time); diff --git a/imap/smap.c b/imap/smap.c index b7669cf..2b528a9 100644 --- a/imap/smap.c +++ b/imap/smap.c @@ -3376,9 +3376,9 @@ void smap() if (strcmp(p, "INTERNALDATE") == 0 && q) { - add_internaldate=rfc822_parsedt(q); - - if (add_internaldate) + if (rfc822_parsedate_chk(q, + &add_internaldate) + == 0) okmsg="INTERNALDATE set"; } @@ -4359,9 +4359,8 @@ void smap() up(p); - t=rfc822_parsedt(p+13); - - if (t && + if (rfc822_parsedate_chk(p+13, &t) + == 0 && (dummy=applymsgset(&setdate, &t)) != 0) break; diff --git a/imap/thread.c b/imap/thread.c index 791a7a8..883ae59 100644 --- a/imap/thread.c +++ b/imap/thread.c @@ -198,11 +198,18 @@ static void thread_os_callback(struct searchinfo *si, void *voidarg) { if (sihead->type == search_orderedsubj) + { /* SHOULD BE ALWAYS TRUE */ + time_t t=0; + + if (sihead->bs) + rfc822_parsedate_chk(sihead->bs, &t); + os_add( (struct os_struct *)voidarg, isuid ? current_maildir_info.msgs[i].uid:i+1, sihead->as ? sihead->as:"", - sihead->bs ? rfc822_parsedt(sihead->bs):0); + t); + } } static void printthread(struct imap_refmsg *, int); |
