16 |
int action_delete(char *mesgs, char *args); |
int action_delete(char *mesgs, char *args); |
17 |
int action_copy(char *mbox, char *mesgs, char *destmbox, char *args); |
int action_copy(char *mbox, char *mesgs, char *destmbox, char *args); |
18 |
int action_move(char *mbox, char *mesgs, char *destmbox, char *args); |
int action_move(char *mbox, char *mesgs, char *destmbox, char *args); |
19 |
int action_rcopy(char *mbox, char *mesgs, account_t * destacc, char *destmbox, char *args); |
int action_rcopy(char *mbox, char *mesgs, account_t * destacct, char *destmbox, char *args); |
20 |
int action_rmove(char *mbox, char *mesgs, account_t * destacc, char *destmbox, char *args); |
int action_rmove(char *mbox, char *mesgs, account_t * destacct, char *destmbox, char *args); |
21 |
int action_flag(char *mesgs, unsigned int *type, unsigned int *msgflags, char *args); |
int action_flag(char *mesgs, unsigned int *type, unsigned int *msgflags, char *args); |
22 |
int action_list(char *mesgs, char *args); |
int action_list(char *mesgs, char *args); |
23 |
|
|
33 |
* Apply the appropriate action. |
* Apply the appropriate action. |
34 |
*/ |
*/ |
35 |
int |
int |
36 |
apply_action(char *mbox, char *mesgs, unsigned int *type, account_t * raccount, |
apply_action(char *mbox, char *mesgs, unsigned int *type, account_t * destacct, |
37 |
char *destmbox, unsigned int *msgflags, char *args) |
char *destmbox, unsigned int *msgflags, char *args) |
38 |
{ |
{ |
39 |
unsigned int cnt; |
unsigned int cnt; |
42 |
return 0; |
return 0; |
43 |
|
|
44 |
log_info(LOG_ACTION, type); |
log_info(LOG_ACTION, type); |
45 |
log_info(LOG_DEST_ACCOUNT, raccount->key); |
log_info(LOG_DEST_ACCOUNT, destacct->key); |
46 |
log_info(LOG_DEST_MBOX, destmbox); |
log_info(LOG_DEST_MBOX, destmbox); |
47 |
|
|
48 |
cnt = count_messages(mesgs); |
cnt = count_messages(mesgs); |
56 |
info("%d message%s copied from \"%s\" to mailbox \"%s\".\n", |
info("%d message%s copied from \"%s\" to mailbox \"%s\".\n", |
57 |
cnt, plural(cnt), mbox, destmbox); |
cnt, plural(cnt), mbox, destmbox); |
58 |
action_copy(mbox, mesgs, apply_namespace(destmbox, |
action_copy(mbox, mesgs, apply_namespace(destmbox, |
59 |
connpri.ns.prefix, connpri.ns.delim), args); |
connpri.ns.prefix, connpri.ns.delim), args); |
60 |
break; |
break; |
61 |
case ACTION_MOVE: |
case ACTION_MOVE: |
62 |
info("%d message%s moved from \"%s\" to mailbox \"%s\".\n", |
info("%d message%s moved from \"%s\" to mailbox \"%s\".\n", |
63 |
cnt, plural(cnt), mbox, destmbox); |
cnt, plural(cnt), mbox, destmbox); |
64 |
action_move(mbox, mesgs, apply_namespace(destmbox, |
action_move(mbox, mesgs, apply_namespace(destmbox, |
65 |
connpri.ns.prefix, connpri.ns.delim), args); |
connpri.ns.prefix, connpri.ns.delim), args); |
66 |
break; |
break; |
67 |
case ACTION_RCOPY: |
case ACTION_RCOPY: |
68 |
info("%d message%s copied from \"%s\" to mailbox " |
info("%d message%s copied from \"%s\" to mailbox " |
69 |
"\"%s\" at account %s.\n", cnt, plural(cnt), |
"\"%s\" at account %s.\n", cnt, plural(cnt), mbox, |
70 |
mbox, destmbox, raccount->key); |
destmbox, destacct->key); |
71 |
action_rcopy(mbox, mesgs, raccount, destmbox, args); |
action_rcopy(mbox, mesgs, destacct, destmbox, args); |
72 |
break; |
break; |
73 |
case ACTION_RMOVE: |
case ACTION_RMOVE: |
74 |
info("%d message%s moved from \"%s\" to mailbox " |
info("%d message%s moved from \"%s\" to mailbox " |
75 |
"\"%s\" at account %s.\n", cnt, plural(cnt), |
"\"%s\" at account %s.\n", cnt, plural(cnt), mbox, |
76 |
mbox, destmbox, raccount->key); |
destmbox, destacct->key); |
77 |
action_rmove(mbox, mesgs, raccount, destmbox, args); |
action_rmove(mbox, mesgs, destacct, destmbox, args); |
78 |
break; |
break; |
79 |
case ACTION_FLAG_REPLACE: |
case ACTION_FLAG_REPLACE: |
80 |
case ACTION_FLAG_ADD: |
case ACTION_FLAG_ADD: |
110 |
tok = strtok_r(m, " ", &m); |
tok = strtok_r(m, " ", &m); |
111 |
while (tok) { |
while (tok) { |
112 |
response_generic(&connpri, imap_store(&connpri, tok, |
response_generic(&connpri, imap_store(&connpri, tok, |
113 |
ACTION_FLAG_ADD, "\\Deleted")); |
ACTION_FLAG_ADD, "\\Deleted")); |
114 |
|
|
115 |
tok = strtok_r(NULL, " ", &m); |
tok = strtok_r(NULL, " ", &m); |
116 |
} |
} |
153 |
message_date(tok, dm[1]); |
message_date(tok, dm[1]); |
154 |
|
|
155 |
if ((r = response_copy(&connpri, imap_copy(&connpri, tok, |
if ((r = response_copy(&connpri, imap_copy(&connpri, tok, |
156 |
dm[1]))) == RESPONSE_TRYCREATE) |
dm[1]))) == RESPONSE_TRYCREATE) |
157 |
if (!response_generic(&connpri, imap_create(&connpri, |
if (!response_generic(&connpri, imap_create(&connpri, |
158 |
dm[1]))) { |
dm[1]))) { |
159 |
if (opts.subscribe) |
if (opts.subscribe) |
160 |
response_generic(&connpri, |
response_generic(&connpri, |
161 |
imap_subscribe(&connpri, dm[1])); |
imap_subscribe(&connpri, dm[1])); |
189 |
* Copy messages to the specified mailbox of another mail server. |
* Copy messages to the specified mailbox of another mail server. |
190 |
*/ |
*/ |
191 |
int |
int |
192 |
action_rcopy(char *mbox, char *mesgs, account_t * destacc, char *destmbox, |
action_rcopy(char *mbox, char *mesgs, account_t * destacct, char *destmbox, |
193 |
char *args) |
char *args) |
194 |
{ |
{ |
195 |
int r, ta, tf; |
int r, ta, tf; |
202 |
*dm[0] = *dm[1] = *dm[2] = '\0'; |
*dm[0] = *dm[1] = *dm[2] = '\0'; |
203 |
flags = date = NULL; |
flags = date = NULL; |
204 |
|
|
205 |
if (init_connection(&connaux, destacc->server, destacc->port, |
if (init_connection(&connaux, destacct->server, destacct->port, |
206 |
destacc->ssl)) |
destacct->ssl)) |
207 |
return ERROR_NETWORK; |
return ERROR_NETWORK; |
208 |
|
|
209 |
r = response_greeting(&connaux); |
r = response_greeting(&connaux); |
215 |
return ERROR_NETWORK; |
return ERROR_NETWORK; |
216 |
|
|
217 |
#ifdef SSL_TLS |
#ifdef SSL_TLS |
218 |
if (destacc->ssl == SSL_DISABLED && connaux.caps & CAPS_STARTTLS) |
if (destacct->ssl == SSL_DISABLED && connaux.caps & CAPS_STARTTLS) |
219 |
if (negotiate_tls(&connaux) == RESPONSE_OK) |
if (negotiate_tls(&connaux) == RESPONSE_OK) |
220 |
check_capabilities(&connaux); |
check_capabilities(&connaux); |
221 |
#endif |
#endif |
222 |
|
|
223 |
if (r != RESPONSE_PREAUTH) { |
if (r != RESPONSE_PREAUTH) { |
224 |
if (destacc->pass_attr == PASS_ATTR_NONE) { |
if (destacct->pass_attr == PASS_ATTR_NONE) { |
225 |
printf("Enter password for %s@%s: ", destacc->user, |
printf("Enter password for %s@%s: ", destacct->user, |
226 |
destacc->server); |
destacct->server); |
227 |
get_password(destacc->pass, PASS_LEN); |
get_password(destacct->pass, PASS_LEN); |
228 |
destacc->pass_attr = PASS_ATTR_PLAIN; |
destacct->pass_attr = PASS_ATTR_PLAIN; |
229 |
} |
} |
230 |
#ifdef CRAM_MD5 |
#ifdef CRAM_MD5 |
231 |
if (connaux.caps & CAPS_CRAMMD5) |
if (connaux.caps & CAPS_CRAMMD5) |
232 |
r = auth_cram_md5(&connaux, destacc->user, |
r = auth_cram_md5(&connaux, destacct->user, |
233 |
destacc->pass); |
destacct->pass); |
234 |
else |
else |
235 |
#endif |
#endif |
236 |
r = login(&connaux, destacc->user, |
r = login(&connaux, destacct->user, destacct->pass); |
|
destacc->pass); |
|
237 |
|
|
238 |
if (r == RESPONSE_NO) { |
if (r == RESPONSE_NO) { |
239 |
error("username %s or password rejected at %s\n", |
error("username %s or password rejected at %s\n", |
240 |
destacc->user, destacc->server); |
destacct->user, destacct->server); |
241 |
return ERROR_NETWORK; |
return ERROR_NETWORK; |
242 |
} |
} |
243 |
} |
} |
322 |
* Move messages to the specified mailbox of another mail server. |
* Move messages to the specified mailbox of another mail server. |
323 |
*/ |
*/ |
324 |
int |
int |
325 |
action_rmove(char *mbox, char *mesgs, account_t * destacc, char *destmbox, |
action_rmove(char *mbox, char *mesgs, account_t * destacct, char *destmbox, |
326 |
char *args) |
char *args) |
327 |
{ |
{ |
328 |
|
|
329 |
if (!action_rcopy(mbox, mesgs, destacc, destmbox, args)) |
if (!action_rcopy(mbox, mesgs, destacct, destmbox, args)) |
330 |
action_delete(mesgs, "\0"); |
action_delete(mesgs, "\0"); |
331 |
|
|
332 |
return 0; |
return 0; |
448 |
|
|
449 |
|
|
450 |
/* |
/* |
451 |
* Convert messages with contiguous sequence number to the corresponding |
* Convert messages with contiguous sequence number to the corresponding number |
452 |
* number range, eg. 1 2 3 5 7 8 --> 1:3 5 7:8 and return a newly allocated |
* range, eg. 1 2 3 5 7 8 --> 1:3 5 7:8 and return a newly allocated buffer |
453 |
* buffer with the results. |
* with the results. |
454 |
*/ |
*/ |
455 |
char * |
char * |
456 |
convert_messages(char *mesgs) |
convert_messages(char *mesgs) |
502 |
|
|
503 |
|
|
504 |
/* |
/* |
505 |
* Substitute all occurences of the '@' character with the '%' character, |
* Substitute all occurences of the '@' character with the '%' character, and |
506 |
* and any double '@' characters with a signle '@' character, returning the |
* any double '@' characters with a signle '@' character, returning the number |
507 |
* number of replacements. |
* of replacements. |
508 |
*/ |
*/ |
509 |
int |
int |
510 |
substitute_date(char *str) |
substitute_date(char *str) |
586 |
while (response_fetch(&connpri, t, 0, dbuf) == RESPONSE_NONE); |
while (response_fetch(&connpri, t, 0, dbuf) == RESPONSE_NONE); |
587 |
|
|
588 |
if (((strptime(dbuf, "Date: %a, %d %b %Y %H:%M:%S", &tl) || |
if (((strptime(dbuf, "Date: %a, %d %b %Y %H:%M:%S", &tl) || |
589 |
strptime(dbuf, "Date: %d %b %Y %H:%M:%S", &tl)) && |
strptime(dbuf, "Date: %d %b %Y %H:%M:%S", &tl)) && |
590 |
strftime(s, MBOX_LEN - 1, destmbox, &tl))) |
strftime(s, MBOX_LEN - 1, destmbox, &tl))) |
591 |
xstrncpy(destmbox, s, MBOX_LEN - 1); |
xstrncpy(destmbox, s, MBOX_LEN - 1); |
592 |
} |
} |
593 |
|
|