Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/pop3/commands.c @ 3663:6d485bf73429 HEAD
Don't send duplicate lines in LIST command when buffer is full.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 16 Oct 2005 19:22:15 +0300 |
parents | 58e3fa234ef4 |
children | 74b27d1e17a4 |
rev | line source |
---|---|
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (C) 2002 Timo Sirainen */ |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "common.h" |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
4 #include "istream.h" |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
5 #include "ostream.h" |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "str.h" |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
7 #include "var-expand.h" |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "message-size.h" |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "mail-storage.h" |
1845
bd8b6ed35327
Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
10 #include "mail-search.h" |
1059
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
11 #include "capability.h" |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "commands.h" |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #define MSGS_BITMASK_SIZE(client) \ |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 ((client->messages_count + (CHAR_BIT-1)) / CHAR_BIT) |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 static const char *get_msgnum(struct client *client, const char *args, |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 unsigned int *msgnum) |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 unsigned int num, last_num; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 num = 0; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 while (*args != '\0' && *args != ' ') { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 if (*args < '0' || *args > '9') { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 client_send_line(client, |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 "-ERR Invalid message number: %s", args); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 return NULL; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 last_num = num; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 num = num*10 + (*args - '0'); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 if (num < last_num) { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 client_send_line(client, |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 "-ERR Message number too large: %s", args); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 return NULL; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 args++; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 |
1051 | 40 if (num == 0 || num > client->messages_count) { |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 client_send_line(client, |
1051 | 42 "-ERR There's no message %u.", num); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 return NULL; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 } |
1051 | 45 num--; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 if (client->deleted) { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 if (client->deleted_bitmask[num / CHAR_BIT] & |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 (1 << (num % CHAR_BIT))) { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 client_send_line(client, "-ERR Message is deleted."); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 return NULL; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 while (*args == ' ') args++; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 *msgnum = num; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 return args; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 static const char *get_size(struct client *client, const char *args, |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 uoff_t *size) |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 uoff_t num, last_num; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 num = 0; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 while (*args != '\0' && *args != ' ') { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 if (*args < '0' || *args > '9') { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 client_send_line(client, "-ERR Invalid size: %s", |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 args); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 return NULL; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 last_num = num; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 num = num*10 + (*args - '0'); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 if (num < last_num) { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 client_send_line(client, "-ERR Size too large: %s", |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 args); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 return NULL; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 args++; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 while (*args == ' ') args++; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 *size = num; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 return args; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 |
1059
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
90 static int cmd_capa(struct client *client, const char *args __attr_unused__) |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
91 { |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
92 client_send_line(client, "+OK\r\n"POP3_CAPABILITY_REPLY"."); |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
93 return TRUE; |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
94 } |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
95 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
96 static int cmd_dele(struct client *client, const char *args) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 unsigned int msgnum; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 if (get_msgnum(client, args, &msgnum) == NULL) |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
101 return FALSE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 if (!client->deleted) { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 client->deleted_bitmask = i_malloc(MSGS_BITMASK_SIZE(client)); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 client->deleted = TRUE; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 client->deleted_bitmask[msgnum / CHAR_BIT] |= 1 << (msgnum % CHAR_BIT); |
1994
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
109 client->deleted_count++; |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
110 client->deleted_size += client->message_sizes[msgnum]; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 client_send_line(client, "+OK Marked to be deleted."); |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
112 return TRUE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
115 struct cmd_list_context { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
116 unsigned int msgnum; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
117 }; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
118 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
119 static void cmd_list_callback(struct client *client) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
120 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
121 struct cmd_list_context *ctx = client->cmd_context; |
3663
6d485bf73429
Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents:
3567
diff
changeset
|
122 int ret = 1; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
123 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
124 for (; ctx->msgnum != client->messages_count; ctx->msgnum++) { |
3663
6d485bf73429
Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents:
3567
diff
changeset
|
125 if (ret == 0) { |
6d485bf73429
Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents:
3567
diff
changeset
|
126 /* buffer full */ |
6d485bf73429
Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents:
3567
diff
changeset
|
127 return; |
6d485bf73429
Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents:
3567
diff
changeset
|
128 } |
6d485bf73429
Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents:
3567
diff
changeset
|
129 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
130 if (client->deleted) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
131 if (client->deleted_bitmask[ctx->msgnum / CHAR_BIT] & |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
132 (1 << (ctx->msgnum % CHAR_BIT))) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
133 continue; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
134 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
135 ret = client_send_line(client, "%u %"PRIuUOFF_T, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
136 ctx->msgnum+1, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
137 client->message_sizes[ctx->msgnum]); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
138 if (ret < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
139 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
140 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
141 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
142 client_send_line(client, "."); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
143 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
144 i_free(ctx); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
145 client->cmd = NULL; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
146 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
147 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
148 static int cmd_list(struct client *client, const char *args) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
150 struct cmd_list_context *ctx; |
1044
50d258907c99
Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents:
1043
diff
changeset
|
151 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 if (*args == '\0') { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
153 ctx = i_new(struct cmd_list_context, 1); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 client_send_line(client, "+OK %u messages:", |
1994
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
155 client->messages_count - client->deleted_count); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
156 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
157 client->cmd = cmd_list_callback; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
158 client->cmd_context = ctx; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
159 cmd_list_callback(client); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 } else { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 unsigned int msgnum; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
163 if (get_msgnum(client, args, &msgnum) == NULL) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
164 return FALSE; |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
165 |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
166 client_send_line(client, "+OK %u %"PRIuUOFF_T, msgnum+1, |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
167 client->message_sizes[msgnum]); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 } |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
169 |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
170 return TRUE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
173 static int cmd_last(struct client *client, const char *args __attr_unused__) |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
174 { |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
175 client_send_line(client, "+OK %u", client->last_seen); |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
176 return TRUE; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
177 } |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
178 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
179 static int cmd_noop(struct client *client, const char *args __attr_unused__) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 client_send_line(client, "+OK"); |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
182 return TRUE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
185 static int expunge_mails(struct client *client) |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
186 { |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
187 struct mail_search_arg search_arg; |
3557
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
188 struct mail_search_seqset seqset; |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
189 struct mail_search_context *ctx; |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
190 struct mail *mail; |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
191 uint32_t idx; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
192 int ret = TRUE; |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
193 |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
194 if (client->deleted_bitmask == NULL) |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
195 return TRUE; |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
196 |
3558 | 197 memset(&seqset, 0, sizeof(seqset)); |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
198 memset(&search_arg, 0, sizeof(search_arg)); |
3557
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
199 seqset.seq1 = 1; |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
200 seqset.seq2 = client->messages_count; |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
201 search_arg.type = SEARCH_SEQSET; |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
202 search_arg.value.seqset = &seqset; |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
203 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
204 ctx = mailbox_search_init(client->trans, NULL, &search_arg, NULL); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
205 mail = mail_alloc(client->trans, 0, NULL); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
206 while (mailbox_search_next(ctx, mail) > 0) { |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
207 idx = mail->seq - 1; |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
208 if ((client->deleted_bitmask[idx / CHAR_BIT] & |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
209 1 << (idx % CHAR_BIT)) != 0) { |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
210 if (mail_expunge(mail) < 0) { |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
211 ret = FALSE; |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
212 break; |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
213 } |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
214 } |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
215 } |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
216 mail_free(mail); |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
217 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
218 if (mailbox_search_deinit(ctx) < 0) |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
219 ret = FALSE; |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
220 return ret; |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
221 } |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
222 |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
223 static int cmd_quit(struct client *client, const char *args __attr_unused__) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 { |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
225 if (client->deleted) { |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
226 if (!expunge_mails(client)) { |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
227 client_send_storage_error(client); |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
228 client_disconnect(client, "Storage error during logout."); |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
229 return TRUE; |
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
230 } |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
231 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
233 mailbox_transaction_commit(client->trans, MAILBOX_SYNC_FLAG_FULL_WRITE); |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
234 client->trans = NULL; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 |
1640
db14aa8e2b5c
API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents:
1507
diff
changeset
|
236 if (!client->deleted) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 client_send_line(client, "+OK Logging out."); |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
238 else |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 client_send_line(client, "+OK Logging out, messages deleted."); |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
241 client_disconnect(client, "Logout."); |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
242 return TRUE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
245 struct fetch_context { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
246 struct mail_search_context *search_ctx; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
247 struct mail *mail; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
248 struct istream *stream; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
249 uoff_t body_lines; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
250 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
251 struct mail_search_arg search_arg; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
252 struct mail_search_seqset seqset; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
253 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
254 unsigned char last; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
255 int cr_skipped, in_body; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
256 }; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
257 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
258 static void fetch_deinit(struct fetch_context *ctx) |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
259 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
260 (void)mailbox_search_deinit(ctx->search_ctx); |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
261 mail_free(ctx->mail); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
262 i_free(ctx); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
263 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
264 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
265 static void fetch_callback(struct client *client) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
266 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
267 struct fetch_context *ctx = client->cmd_context; |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
268 const unsigned char *data; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
269 unsigned char add; |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
270 size_t i, size; |
2712
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
271 int ret; |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
272 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
273 while ((ctx->body_lines > 0 || !ctx->in_body) && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
274 i_stream_read_data(ctx->stream, &data, &size, 0) > 0) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
275 if (size > 4096) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
276 size = 4096; |
1051 | 277 |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
278 add = '\0'; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
279 for (i = 0; i < size; i++) { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
280 if ((data[i] == '\r' || data[i] == '\n') && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
281 !ctx->in_body) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
282 if (i == 0 && (ctx->last == '\0' || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
283 ctx->last == '\n')) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
284 ctx->in_body = TRUE; |
1051 | 285 else if (i > 0 && data[i-1] == '\n') |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
286 ctx->in_body = TRUE; |
1051 | 287 } |
288 | |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
289 if (data[i] == '\n') { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
290 if ((i == 0 && ctx->last != '\r') || |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
291 (i > 0 && data[i-1] != '\r')) { |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
292 /* missing CR */ |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
293 add = '\r'; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
294 break; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
295 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
296 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
297 if (ctx->in_body) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
298 if (--ctx->body_lines == 0) { |
1051 | 299 i++; |
300 break; | |
301 } | |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
302 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
303 } else if (data[i] == '.' && |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
304 ((i == 0 && ctx->last == '\n') || |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
305 (i > 0 && data[i-1] == '\n'))) { |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
306 /* escape the dot */ |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
307 add = '.'; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
308 break; |
2316
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2238
diff
changeset
|
309 } else if (data[i] == '\0' && |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2238
diff
changeset
|
310 (client_workarounds & |
1c1ed4494aa4
Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents:
2238
diff
changeset
|
311 WORKAROUND_OUTLOOK_NO_NULS) != 0) { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
312 add = 0x80; |
2323 | 313 break; |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
314 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
315 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
316 |
2520 | 317 if (i > 0) { |
318 if (o_stream_send(client->output, data, i) < 0) | |
319 break; | |
320 ctx->last = data[i-1]; | |
321 i_stream_skip(ctx->stream, i); | |
322 } | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
323 |
2712
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
324 if (o_stream_get_buffer_used_size(client->output) >= 4096) { |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
325 if ((ret = o_stream_flush(client->output)) < 0) |
2694
7b24c608f225
Make sure fetching is uninitialized always. Do full read/write syncing when
Timo Sirainen <tss@iki.fi>
parents:
2684
diff
changeset
|
326 break; |
2712
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
327 if (ret == 0) { |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
328 /* continue later */ |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
329 return; |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
330 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
331 } |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
332 |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
333 if (add != '\0') { |
2494 | 334 if (o_stream_send(client->output, &add, 1) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
335 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
336 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
337 ctx->last = add; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
338 if (add == 0x80) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
339 i_stream_skip(ctx->stream, 1); |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
340 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
341 } |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
342 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
343 if (ctx->last != '\n') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
344 /* didn't end with CRLF */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
345 (void)o_stream_send(client->output, "\r\n", 2); |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
346 } |
1507
1fad8b3d7ef1
If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents:
1071
diff
changeset
|
347 |
2952 | 348 if (!ctx->in_body && (client_workarounds & WORKAROUND_OE_NS_EOH) != 0) { |
349 /* Add the missing end of headers line. */ | |
350 (void)o_stream_send(client->output, "\r\n", 2); | |
351 } | |
352 | |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
353 *client->byte_counter += |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
354 client->output->offset - client->byte_counter_offset; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
355 client->byte_counter = NULL; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
356 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
357 client_send_line(client, "."); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
358 fetch_deinit(ctx); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
359 client->cmd = NULL; |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
360 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
361 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
362 static void fetch(struct client *client, unsigned int msgnum, uoff_t body_lines) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
363 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
364 struct fetch_context *ctx; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
365 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
366 ctx = i_new(struct fetch_context, 1); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
368 ctx->seqset.seq1 = ctx->seqset.seq2 = msgnum+1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
369 ctx->search_arg.type = SEARCH_SEQSET; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
370 ctx->search_arg.value.seqset = &ctx->seqset; |
1845
bd8b6ed35327
Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
371 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
372 ctx->search_ctx = mailbox_search_init(client->trans, NULL, |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
373 &ctx->search_arg, NULL); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
374 ctx->mail = mail_alloc(client->trans, MAIL_FETCH_STREAM_HEADER | |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
375 MAIL_FETCH_STREAM_BODY, NULL); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
376 |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
377 if (mailbox_search_next(ctx->search_ctx, ctx->mail) <= 0) |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
378 ctx->stream = NULL; |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
379 else |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
380 ctx->stream = mail_get_stream(ctx->mail, NULL, NULL); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
381 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
382 if (ctx->stream == NULL) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
383 client_send_line(client, "-ERR Message not found."); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
384 fetch_deinit(ctx); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 return; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
386 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 |
2719
f8adc5cb2508
Renamed pop3_mails_keep_recent to pop3_no_flag_updates which includes
Timo Sirainen <tss@iki.fi>
parents:
2712
diff
changeset
|
388 if (body_lines == (uoff_t)-1 && !no_flag_updates) { |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
389 if ((mail_get_flags(ctx->mail) & MAIL_SEEN) == 0) { |
2928
3470bb04fb57
RETR: Don't bother adding \Seen flag to message if it's already there.
Timo Sirainen <tss@iki.fi>
parents:
2722
diff
changeset
|
390 /* mark the message seen with RETR command */ |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
391 (void)mail_update_flags(ctx->mail, |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
392 MODIFY_ADD, MAIL_SEEN); |
2928
3470bb04fb57
RETR: Don't bother adding \Seen flag to message if it's already there.
Timo Sirainen <tss@iki.fi>
parents:
2722
diff
changeset
|
393 } |
2527
792b3209f705
Make RETR mark the message seen.
Timo Sirainen <tss@iki.fi>
parents:
2520
diff
changeset
|
394 } |
792b3209f705
Make RETR mark the message seen.
Timo Sirainen <tss@iki.fi>
parents:
2520
diff
changeset
|
395 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
396 ctx->body_lines = body_lines; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
397 if (body_lines == (uoff_t)-1) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
398 client_send_line(client, "+OK %"PRIuUOFF_T" octets", |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
399 client->message_sizes[msgnum]); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
400 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
401 client_send_line(client, "+OK"); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
402 ctx->body_lines++; /* internally we count the empty line too */ |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
404 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
405 client->cmd = fetch_callback; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
406 client->cmd_context = ctx; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
407 fetch_callback(client); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
408 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
410 static int cmd_retr(struct client *client, const char *args) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 unsigned int msgnum; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
413 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
414 if (get_msgnum(client, args, &msgnum) == NULL) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
415 return FALSE; |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
416 |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
417 if (client->last_seen <= msgnum) |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
418 client->last_seen = msgnum+1; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
419 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
420 client->retr_count++; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
421 client->byte_counter = &client->retr_bytes; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
422 client->byte_counter_offset = client->output->offset; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
423 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
424 fetch(client, msgnum, (uoff_t)-1); |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
425 return TRUE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
426 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
427 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
428 static int cmd_rset(struct client *client, const char *args __attr_unused__) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
429 { |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
430 struct mail_search_context *search_ctx; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
431 struct mail *mail; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
432 struct mail_search_arg search_arg; |
3557
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
433 struct mail_search_seqset seqset; |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
434 |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
435 client->last_seen = 0; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
436 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 if (client->deleted) { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 client->deleted = FALSE; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 memset(client->deleted_bitmask, 0, MSGS_BITMASK_SIZE(client)); |
1994
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
440 client->deleted_count = 0; |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
441 client->deleted_size = 0; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
444 /* forget all our seen flag updates as well.. */ |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
445 mailbox_transaction_rollback(client->trans); |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
446 client->trans = mailbox_transaction_begin(client->mailbox, 0); |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
447 |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
448 if (enable_last_command) { |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
449 /* remove all \Seen flags */ |
3558 | 450 memset(&seqset, 0, sizeof(seqset)); |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
451 memset(&search_arg, 0, sizeof(search_arg)); |
3557
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
452 seqset.seq1 = 1; |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
453 seqset.seq2 = client->messages_count; |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
454 search_arg.type = SEARCH_SEQSET; |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
455 search_arg.value.seqset = &seqset; |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
456 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
457 search_ctx = mailbox_search_init(client->trans, NULL, |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
458 &search_arg, NULL); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
459 mail = mail_alloc(client->trans, 0, NULL); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
460 while (mailbox_search_next(search_ctx, mail) > 0) { |
3387
bfb2658a2616
RSET command wasn't working right
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
461 if (mail_update_flags(mail, MODIFY_REMOVE, |
bfb2658a2616
RSET command wasn't working right
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
462 MAIL_SEEN) < 0) |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
463 break; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
464 } |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
465 mail_free(mail); |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
466 (void)mailbox_search_deinit(search_ctx); |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
467 } |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
468 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 client_send_line(client, "+OK"); |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
470 return TRUE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
473 static int cmd_stat(struct client *client, const char *args __attr_unused__) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
474 { |
1044
50d258907c99
Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents:
1043
diff
changeset
|
475 client_send_line(client, "+OK %u %"PRIuUOFF_T, client-> |
1994
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
476 messages_count - client->deleted_count, |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
477 client->total_size - client->deleted_size); |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
478 return TRUE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
481 static int cmd_top(struct client *client, const char *args) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
482 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 unsigned int msgnum; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 uoff_t max_lines; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
486 args = get_msgnum(client, args, &msgnum); |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
487 if (args == NULL) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
488 return FALSE; |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
489 if (get_size(client, args, &max_lines) == NULL) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
490 return FALSE; |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
491 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
492 client->top_count++; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
493 client->byte_counter = &client->top_bytes; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
494 client->byte_counter_offset = client->output->offset; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
495 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
496 fetch(client, msgnum, max_lines); |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
497 return TRUE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
498 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
499 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
500 struct cmd_uidl_context { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
501 struct mail_search_context *search_ctx; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
502 struct mail *mail; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
503 unsigned int message; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
504 |
1845
bd8b6ed35327
Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
505 struct mail_search_arg search_arg; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
506 struct mail_search_seqset seqset; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
507 }; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
508 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
509 static int list_uids_iter(struct client *client, struct cmd_uidl_context *ctx) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
510 { |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
511 static struct var_expand_table static_tab[] = { |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
512 { 'v', NULL }, |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
513 { 'u', NULL }, |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
514 { 'm', NULL }, |
2996
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
515 { 'f', NULL }, |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
516 { '\0', NULL } |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
517 }; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
518 struct var_expand_table *tab; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
519 string_t *str; |
3567
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
520 const char *uidl; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
521 int ret, found = FALSE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
522 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
523 tab = t_malloc(sizeof(static_tab)); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
524 memcpy(tab, static_tab, sizeof(static_tab)); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
525 tab[0].value = t_strdup_printf("%u", client->uid_validity); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
526 |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
527 str = str_new(default_pool, 128); |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
528 while (mailbox_search_next(ctx->search_ctx, ctx->mail) > 0) { |
1994
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
529 if (client->deleted) { |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
530 uint32_t idx = ctx->mail->seq - 1; |
1994
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
531 if (client->deleted_bitmask[idx / CHAR_BIT] & |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
532 (1 << (idx % CHAR_BIT))) |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
533 continue; |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
534 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
535 found = TRUE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
536 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
537 t_push(); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
538 if ((uidl_keymask & UIDL_UID) != 0) |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
539 tab[1].value = dec2str(ctx->mail->uid); |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
540 if ((uidl_keymask & UIDL_MD5) != 0) { |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
541 tab[2].value = mail_get_special(ctx->mail, |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
542 MAIL_FETCH_HEADER_MD5); |
3357
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
543 if (tab[2].value == NULL) { |
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
544 /* broken */ |
3388
814ba0c6877f
If we couldn't get UIDL, also write error to log.
Timo Sirainen <tss@iki.fi>
parents:
3387
diff
changeset
|
545 i_error("UIDL: Header MD5 not found"); |
3357
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
546 t_pop(); |
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
547 break; |
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
548 } |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
549 } |
2996
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
550 if ((uidl_keymask & UIDL_FILE_NAME) != 0) { |
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
551 tab[3].value = |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
552 mail_get_special(ctx->mail, |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
553 MAIL_FETCH_UIDL_FILE_NAME); |
3357
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
554 if (tab[3].value == NULL) { |
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
555 /* broken */ |
3388
814ba0c6877f
If we couldn't get UIDL, also write error to log.
Timo Sirainen <tss@iki.fi>
parents:
3387
diff
changeset
|
556 i_error("UIDL: File name not found"); |
3357
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
557 t_pop(); |
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
558 break; |
2d8874b023ea
If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
559 } |
2996
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
560 } |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
561 |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
562 str_truncate(str, 0); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
563 str_printfa(str, ctx->message == 0 ? "%u " : "+OK %u ", |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
564 ctx->mail->seq); |
3567
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
565 |
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
566 uidl = !reuse_xuidl ? NULL : |
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
567 mail_get_first_header(ctx->mail, "X-UIDL"); |
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
568 if (uidl == NULL) |
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
569 var_expand(str, uidl_format, tab); |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
570 |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
571 ret = client_send_line(client, "%s", str_c(str)); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
572 t_pop(); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
573 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
574 if (ret < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
575 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
576 if (ret == 0 && ctx->message == 0) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
577 /* output is being buffered, continue when there's |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
578 more space */ |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
579 str_free(str); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
580 return 0; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
581 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
582 } |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
583 str_free(str); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
584 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
585 /* finished */ |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
586 mail_free(ctx->mail); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
587 (void)mailbox_search_deinit(ctx->search_ctx); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
588 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
589 client->cmd = NULL; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
590 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
591 if (ctx->message == 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
592 client_send_line(client, "."); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
593 i_free(ctx); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
594 return found; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
595 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
596 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
597 static void cmd_uidl_callback(struct client *client) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
598 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
599 struct cmd_uidl_context *ctx = client->cmd_context; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
600 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
601 (void)list_uids_iter(client, ctx); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
602 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
603 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
604 static struct cmd_uidl_context * |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
605 cmd_uidl_init(struct client *client, unsigned int message) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
606 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
607 struct cmd_uidl_context *ctx; |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
608 enum mail_fetch_field wanted_fields; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
609 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
610 ctx = i_new(struct cmd_uidl_context, 1); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
611 |
3557
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
612 if (message == 0) { |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
613 ctx->seqset.seq1 = 1; |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
614 ctx->seqset.seq2 = client->messages_count; |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
615 } else { |
2684 | 616 ctx->message = message; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
617 ctx->seqset.seq1 = ctx->seqset.seq2 = message; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
618 } |
3557
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
619 ctx->search_arg.type = SEARCH_SEQSET; |
ca22e27202b2
If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents:
3441
diff
changeset
|
620 ctx->search_arg.value.seqset = &ctx->seqset; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
621 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
622 wanted_fields = 0; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
623 if ((uidl_keymask & UIDL_MD5) != 0) |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
624 wanted_fields |= MAIL_FETCH_HEADER_MD5; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
625 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
626 ctx->search_ctx = mailbox_search_init(client->trans, NULL, |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
627 &ctx->search_arg, NULL); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
628 ctx->mail = mail_alloc(client->trans, wanted_fields, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
629 if (message == 0) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
630 client->cmd = cmd_uidl_callback; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
631 client->cmd_context = ctx; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
632 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
633 return ctx; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
634 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
635 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
636 static int cmd_uidl(struct client *client, const char *args) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
637 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
638 struct cmd_uidl_context *ctx; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
639 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
640 if (*args == '\0') { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
641 client_send_line(client, "+OK"); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
642 ctx = cmd_uidl_init(client, 0); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
643 list_uids_iter(client, ctx); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
644 } else { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
645 unsigned int msgnum; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
646 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
647 if (get_msgnum(client, args, &msgnum) == NULL) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
648 return FALSE; |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
649 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
650 ctx = cmd_uidl_init(client, msgnum+1); |
2684 | 651 if (!list_uids_iter(client, ctx)) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
652 client_send_line(client, "-ERR Message not found."); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
653 } |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
654 |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
655 return TRUE; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
656 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
657 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
658 int client_command_execute(struct client *client, |
3441
7888394f2985
Don't treat known commands with (somewhat) invalid parameters as "bad
Timo Sirainen <tss@iki.fi>
parents:
3388
diff
changeset
|
659 const char *name, const char *args) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
660 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
661 /* keep the command uppercased */ |
2058
0a1755f79392
cleanup: str_*case(t_strdup_noconst(str)) -> t_str_*case(str)
Timo Sirainen <tss@iki.fi>
parents:
2006
diff
changeset
|
662 name = t_str_ucase(name); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
663 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
664 while (*args == ' ') args++; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
665 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
666 switch (*name) { |
1059
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
667 case 'C': |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
668 if (strcmp(name, "CAPA") == 0) |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
669 return cmd_capa(client, args); |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
670 break; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
671 case 'D': |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
672 if (strcmp(name, "DELE") == 0) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
673 return cmd_dele(client, args); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
674 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
675 case 'L': |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
676 if (strcmp(name, "LIST") == 0) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
677 return cmd_list(client, args); |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
678 if (strcmp(name, "LAST") == 0 && enable_last_command) |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
679 return cmd_last(client, args); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
680 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
681 case 'N': |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
682 if (strcmp(name, "NOOP") == 0) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
683 return cmd_noop(client, args); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
684 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
685 case 'Q': |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
686 if (strcmp(name, "QUIT") == 0) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
687 return cmd_quit(client, args); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
688 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
689 case 'R': |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
690 if (strcmp(name, "RETR") == 0) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
691 return cmd_retr(client, args); |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
692 if (strcmp(name, "RSET") == 0) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
693 return cmd_rset(client, args); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
694 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
695 case 'S': |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
696 if (strcmp(name, "STAT") == 0) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
697 return cmd_stat(client, args); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
698 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
699 case 'T': |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
700 if (strcmp(name, "TOP") == 0) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
701 return cmd_top(client, args); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
702 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
703 case 'U': |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
704 if (strcmp(name, "UIDL") == 0) |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
705 return cmd_uidl(client, args); |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
706 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
707 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
708 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
709 client_send_line(client, "-ERR Unknown command: %s", name); |
3441
7888394f2985
Don't treat known commands with (somewhat) invalid parameters as "bad
Timo Sirainen <tss@iki.fi>
parents:
3388
diff
changeset
|
710 return -1; |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
711 } |