pop3-migration-plugin.c revision 71748cca1bacd74451fd228db5536828bdfeb190
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2007-2016 Dovecot authors, see the included COPYING file */
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainen MODULE_CONTEXT(obj, pop3_migration_storage_module)
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainen MODULE_CONTEXT(obj, pop3_migration_mail_module)
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainen /* sha1(header) - set only when needed */
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen /* LIST size */
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen/* NOTE: these headers must be sorted */
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainenstatic const char *hdr_hash_skip_headers[] = {
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen "Content-Length",
b42697a5749b85659a24316d97f1c208d469e4e8Timo Sirainen "Return-Path", /* Yahoo IMAP has Return-Path, Yahoo POP3 doesn't */
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen "X-IMAPbase",
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen "X-Keywords",
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen "X-Message-Flag",
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainen "X-Yahoo-Newman-Property"
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainenconst char *pop3_migration_plugin_version = DOVECOT_ABI_VERSION;
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(pop3_migration_storage_module,
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(pop3_migration_mail_module,
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainenstatic int imap_msg_map_uid_cmp(const struct imap_msg_map *map1,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic int pop3_uidl_map_pop3_seq_cmp(const struct pop3_uidl_map *map1,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic int pop3_uidl_map_hdr_cmp(const struct pop3_uidl_map *map1,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen return memcmp(map1->common.hdr_sha1, map2->common.hdr_sha1,
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainenstatic int imap_msg_map_hdr_cmp(const struct imap_msg_map *map1,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen return memcmp(map1->common.hdr_sha1, map2->common.hdr_sha1,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic bool header_name_is_valid(const char *name)
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen unsigned int i;
09c08fad8e7cc694a6c8d1711e67839acd3a2f04Timo Sirainen if ((uint8_t)name[i] <= 0x20 || name[i] >= 0x7f)
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainenpop3_header_filter_callback(struct header_filter_istream *input ATTR_UNUSED,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen /* matched is handled differently for eoh by
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen istream-header-filter. a design bug I guess.. */
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (strspn(hdr->name, "\r") == hdr->name_len) {
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen /* CR+CR+LF - some servers stop the header processing
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen here while others don't. To make sure they can be
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen matched correctly we want to stop here entirely. */
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen /* Yahoo IMAP drops headers with invalid names, while
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen Yahoo POP3 preserves them. Drop them all. */
bool *have_eoh_r)
const unsigned char *data;
const char *errstr;
bool have_eoh;
if (have_eoh) {
return TRUE;
return FALSE;
struct mailbox_transaction_context *t;
const char *uidl;
int ret = 0;
(void)mailbox_transaction_commit(&t);
return ret;
struct mailbox_transaction_context *t;
int ret = 0;
if (ret > 0)
(void)mailbox_transaction_commit(&t);
unsigned first_seq)
first_seq) < 0)
struct mailbox_transaction_context *t;
int ret = 0;
(void)mailbox_transaction_commit(&t);
return ret;
return FALSE;
for (i = 0; i < count; i++) {
return i == count;
int ret;
pop3_idx++;
imap_idx++;
if (ret < 0)
pop3_idx++;
else if (ret > 0)
imap_idx++;
missing_uids_count = 0;
unsigned int i, count;
prev_uid = 0;
for (i = 0; i < count; i++) {
const char **value_r)
static struct mail_search_context *
MAIL_FETCH_POP3_ORDER)) != 0 &&
const char *pop3_box_vname;
void pop3_migration_plugin_deinit(void)