From 0121220339a702eb4871beebd3fe0829821065ad Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 12 Jan 2004 01:24:47 +0000 Subject: [PATCH] Optimized isync by not fetching the sizes of messages if they are unneeded (i.e., if MaxSize is not specified in the config file). Patch and idea originally from Nicolas Boullis , modified/polished by Theodore Ts'o per comments by Oswald Buddenhagen. --- debian/patches/00list | 2 - debian/patches/10-size-opt.dpatch | 81 ------------------------------- src/imap.c | 7 +-- src/isync.h | 5 ++ src/main.c | 10 ++-- 5 files changed, 15 insertions(+), 90 deletions(-) delete mode 100755 debian/patches/10-size-opt.dpatch diff --git a/debian/patches/00list b/debian/patches/00list index cb19ca8..92f7f91 100644 --- a/debian/patches/00list +++ b/debian/patches/00list @@ -1,3 +1 @@ -10-size-opt.dpatch 20-cleanup.dpatch - diff --git a/debian/patches/10-size-opt.dpatch b/debian/patches/10-size-opt.dpatch deleted file mode 100755 index 8f07fc0..0000000 --- a/debian/patches/10-size-opt.dpatch +++ /dev/null @@ -1,81 +0,0 @@ -#! /bin/sh -e -## 10-size-opt.dpatch by Nicolas Boullis -## -## DP: This patch from Nicolas Boullis optimizes isync -## DP: by not fetching the sizes of messages if they are unneeded (i.e., if -## DP: MaxSize is not specified in the config file). - -[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts -patch_opts="${patch_opts:--f --no-backup-if-mismatch}" - -if [ $# -ne 1 ]; then - echo >&2 "`basename $0`: script expects -patch|-unpatch as argument" - exit 1 -fi -case "$1" in - -patch) patch $patch_opts -p1 < $0;; - -unpatch) patch $patch_opts -p1 -R < $0;; - *) - echo >&2 "`basename $0`: script expects -patch|-unpatch as argument" - exit 1;; -esac - -exit 0 -@DPATCH@ - -=================================================================== -RCS file: isync-0.9.2/src/RCS/isync.h,v -retrieving revision 1.1 -diff -u -r1.1 isync-0.9.2/src/isync.h ---- isync-0.9.2/src/isync.h 2004/01/09 23:06:52 1.1 -+++ isync-0.9.2/src/isync.h 2004/01/09 23:07:08 -@@ -205,7 +205,7 @@ - int imap_set_flags (imap_t *, unsigned int, unsigned int); - int imap_expunge (imap_t *); - imap_t *imap_connect (config_t *); --imap_t *imap_open (config_t *, unsigned int, imap_t *, int); -+imap_t *imap_open (config_t *, unsigned int, imap_t *, int, int); - int imap_append_message (imap_t *, int, message_t *); - int imap_list (imap_t *); - -=================================================================== -RCS file: isync-0.9.2/src/RCS/imap.c,v -retrieving revision 1.1 -diff -u -r1.1 isync-0.9.2/src/imap.c ---- isync-0.9.2/src/imap.c 2004/01/09 23:08:20 1.1 -+++ isync-0.9.2/src/imap.c 2004/01/09 23:09:54 -@@ -874,7 +874,8 @@ - * mailbox. - */ - imap_t * --imap_open (config_t * box, unsigned int minuid, imap_t * imap, int imap_create) -+imap_open (config_t * box, unsigned int minuid, imap_t * imap, -+ int imap_create, int get_size) - { - if (imap) - { -@@ -940,7 +941,8 @@ - imap->minuid = minuid; - if (imap->count > 0) - { -- if (imap_exec (imap, "UID FETCH %d:* (FLAGS RFC822.SIZE)", minuid)) -+ if (imap_exec (imap, "UID FETCH %d:* (FLAGS%s)", minuid, -+ get_size ? " RFC822.SIZE" : "")) - goto bail; - } - -=================================================================== -RCS file: isync-0.9.2/src/RCS/main.c,v -retrieving revision 1.1 -diff -u -r1.1 isync-0.9.2/src/main.c ---- isync-0.9.2/src/main.c 2004/01/09 23:08:20 1.1 -+++ isync-0.9.2/src/main.c 2004/01/09 23:08:31 -@@ -396,7 +396,7 @@ - break; - } - -- imap = imap_open (box, fast ? mail->maxuid + 1 : 1, imap, imap_create); -+ imap = imap_open (box, fast ? mail->maxuid + 1 : 1, imap, imap_create, box->max_size!=0); - if (!imap) - { - fprintf (stderr, "%s: skipping mailbox due to IMAP error\n", diff --git a/src/imap.c b/src/imap.c index 134b56c..d4939bf 100644 --- a/src/imap.c +++ b/src/imap.c @@ -874,7 +874,7 @@ mstrcmp (const char *s1, const char *s2) * mailbox. */ imap_t * -imap_open (config_t * box, unsigned int minuid, imap_t * imap, int imap_create) +imap_open (config_t * box, unsigned int minuid, imap_t * imap, int imap_flags) { if (imap) { @@ -926,7 +926,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int imap_create) info ("Selecting IMAP mailbox... "); fflush (stdout); if (imap_exec (imap, "SELECT \"%s%s\"", imap->prefix, box->box)) { - if (imap_create) { + if (imap_flags & IMAP_CREATE) { if (imap_exec (imap, "CREATE \"%s%s\"", imap->prefix, box->box)) goto bail; if (imap_exec (imap, "SELECT \"%s%s\"", imap->prefix, box->box)) @@ -940,7 +940,8 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int imap_create) imap->minuid = minuid; if (imap->count > 0) { - if (imap_exec (imap, "UID FETCH %d:* (FLAGS RFC822.SIZE)", minuid)) + if (imap_exec (imap, "UID FETCH %d:* (FLAGS%s)", minuid, + (imap_flags & IMAP_GET_SIZE) ? " RFC822.SIZE" : "")) goto bail; } diff --git a/src/isync.h b/src/isync.h index 0e1e771..a579f15 100644 --- a/src/isync.h +++ b/src/isync.h @@ -171,6 +171,11 @@ imap_t; #define OPEN_FAST (1<<0) /* fast open - don't parse */ #define OPEN_CREATE (1<<1) /* create mailbox if nonexistent */ +/* flags for imap_open */ +#define IMAP_CREATE (1<<0) /* Create remote mailboxes if necessary */ +#define IMAP_GET_SIZE (1<<1) /* Request the RFC 822 SIZE */ + + extern config_t global; extern config_t *boxes; extern unsigned int Tag; diff --git a/src/main.c b/src/main.c index c2b01d6..ec1e035 100644 --- a/src/main.c +++ b/src/main.c @@ -197,7 +197,7 @@ main (int argc, char **argv) int list = 0; int o2o = 0; int mbox_open_mode = 0; - int imap_create = 0; + int imap_flags = 0; pw = getpwuid (getuid ()); @@ -240,13 +240,13 @@ main (int argc, char **argv) break; case 'C': mbox_open_mode |= OPEN_CREATE; - imap_create = 1; + imap_flags |= IMAP_CREATE; break; case 'L': mbox_open_mode |= OPEN_CREATE; break; case 'R': - imap_create = 1; + imap_flags |= IMAP_CREATE; break; case 'c': config = optarg; @@ -403,7 +403,9 @@ main (int argc, char **argv) break; } - imap = imap_open (box, fast ? mail->maxuid + 1 : 1, imap, imap_create); + if (box->max_size) + imap_flags |= IMAP_GET_SIZE; + imap = imap_open (box, fast ? mail->maxuid + 1 : 1, imap, imap_flags); if (!imap) { fprintf (stderr, "%s: skipping mailbox due to IMAP error\n",