comparison src/plugins/mbox-snarf/mbox-snarf-plugin.c @ 9330:cf93e420fc57 HEAD

mbox-snarf: Keep the mailbox locked while snarfing to avoid duplicates.
author Timo Sirainen <tss@iki.fi>
date Mon, 17 Aug 2009 10:42:12 -0400
parents 66b6cd495702
children a40f5c34ace8
comparison
equal deleted inserted replaced
9329:956d2f962e97 9330:cf93e420fc57
21 bool open_spool_inbox; 21 bool open_spool_inbox;
22 }; 22 };
23 23
24 struct mbox_snarf_mailbox { 24 struct mbox_snarf_mailbox {
25 union mailbox_module_context module_ctx; 25 union mailbox_module_context module_ctx;
26
27 struct mailbox *spool_mbox;
28 }; 26 };
29 27
30 const char *mbox_snarf_plugin_version = PACKAGE_VERSION; 28 const char *mbox_snarf_plugin_version = PACKAGE_VERSION;
31 29
32 static void (*mbox_snarf_next_hook_mail_storage_created) 30 static void (*mbox_snarf_next_hook_mail_storage_created)
106 { 104 {
107 struct mbox_snarf_mail_storage *mstorage = 105 struct mbox_snarf_mail_storage *mstorage =
108 MBOX_SNARF_CONTEXT(box->storage); 106 MBOX_SNARF_CONTEXT(box->storage);
109 struct mail_storage *storage; 107 struct mail_storage *storage;
110 struct mbox_snarf_mailbox *mbox = MBOX_SNARF_CONTEXT(box); 108 struct mbox_snarf_mailbox *mbox = MBOX_SNARF_CONTEXT(box);
111 109 struct mailbox *spool_mbox;
112 if (mbox->spool_mbox == NULL) { 110 static struct mailbox_sync_context *ctx;
113 /* try to open the spool mbox */ 111
114 mstorage->open_spool_inbox = TRUE; 112 /* try to open the spool mbox */
115 storage = box->storage; 113 mstorage->open_spool_inbox = TRUE;
116 mbox->spool_mbox = 114 storage = box->storage;
117 mailbox_open(&storage, "INBOX", NULL, 115 spool_mbox = mailbox_open(&storage, "INBOX", NULL,
118 MAILBOX_OPEN_KEEP_RECENT | 116 MAILBOX_OPEN_KEEP_LOCKED |
119 MAILBOX_OPEN_NO_INDEX_FILES); 117 MAILBOX_OPEN_KEEP_RECENT |
120 mstorage->open_spool_inbox = FALSE; 118 MAILBOX_OPEN_NO_INDEX_FILES);
121 } 119 mstorage->open_spool_inbox = FALSE;
122 120
123 if (mbox->spool_mbox != NULL) 121 if (spool_mbox != NULL)
124 mbox_snarf(mbox->spool_mbox, box); 122 mbox_snarf(spool_mbox, box);
125 123
126 return mbox->module_ctx.super.sync_init(box, flags); 124 ctx = mbox->module_ctx.super.sync_init(box, flags);
127 } 125
128 126 if (spool_mbox != NULL)
129 static int mbox_snarf_close(struct mailbox *box) 127 mailbox_close(&spool_mbox);
130 { 128 return ctx;
131 struct mbox_snarf_mailbox *mbox = MBOX_SNARF_CONTEXT(box);
132
133 if (mbox->spool_mbox != NULL)
134 mailbox_close(&mbox->spool_mbox);
135 return mbox->module_ctx.super.close(box);
136 } 129 }
137 130
138 static struct mailbox * 131 static struct mailbox *
139 mbox_snarf_mailbox_open(struct mail_storage *storage, const char *name, 132 mbox_snarf_mailbox_open(struct mail_storage *storage, const char *name,
140 struct istream *input, enum mailbox_open_flags flags) 133 struct istream *input, enum mailbox_open_flags flags)
176 169
177 mbox = p_new(box->pool, struct mbox_snarf_mailbox, 1); 170 mbox = p_new(box->pool, struct mbox_snarf_mailbox, 1);
178 mbox->module_ctx.super = box->v; 171 mbox->module_ctx.super = box->v;
179 172
180 box->v.sync_init = mbox_snarf_sync_init; 173 box->v.sync_init = mbox_snarf_sync_init;
181 box->v.close = mbox_snarf_close;
182 MODULE_CONTEXT_SET(box, mbox_snarf_storage_module, mbox); 174 MODULE_CONTEXT_SET(box, mbox_snarf_storage_module, mbox);
183 return box; 175 return box;
184 } 176 }
185 177
186 static void mbox_snarf_mail_storage_created(struct mail_storage *storage) 178 static void mbox_snarf_mail_storage_created(struct mail_storage *storage)