Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/pop3/commands.c @ 5125:0b7be87efd7c HEAD
If UIDL command can't get the UID, die instead of not returning anything and
still replying "OK".
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 14 Feb 2007 20:26:32 +0200 |
parents | 18559c7e3a15 |
children | 1a7359d6a774 |
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"."); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
93 return 1; |
1059
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) |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
101 return 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
|
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."); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
112 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
|
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) |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
164 return 0; |
1056
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 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
170 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
|
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); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
176 return 1; |
2621
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"); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
182 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
|
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 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
185 static bool expunge_mails(struct client *client) |
2722
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; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
192 bool 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 |
4470
c22b5134455a
Don't try to expunge messages if the mailbox is read-only. It'll just cause
Timo Sirainen <tss@iki.fi>
parents:
4096
diff
changeset
|
197 if (mailbox_is_readonly(client->mailbox)) { |
c22b5134455a
Don't try to expunge messages if the mailbox is read-only. It'll just cause
Timo Sirainen <tss@iki.fi>
parents:
4096
diff
changeset
|
198 /* silently ignore */ |
c22b5134455a
Don't try to expunge messages if the mailbox is read-only. It'll just cause
Timo Sirainen <tss@iki.fi>
parents:
4096
diff
changeset
|
199 return TRUE; |
c22b5134455a
Don't try to expunge messages if the mailbox is read-only. It'll just cause
Timo Sirainen <tss@iki.fi>
parents:
4096
diff
changeset
|
200 } |
c22b5134455a
Don't try to expunge messages if the mailbox is read-only. It'll just cause
Timo Sirainen <tss@iki.fi>
parents:
4096
diff
changeset
|
201 |
3558 | 202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 |
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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 } |
4566
aa9109a17db6
Show number of actually expunged messages in logout message, instead of
Timo Sirainen <tss@iki.fi>
parents:
4470
diff
changeset
|
219 client->expunged_count++; |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
220 } |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
221 } |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
222 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
|
223 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
224 if (mailbox_search_deinit(&ctx) < 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
|
225 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
|
226 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
|
227 } |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
228 |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
229 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
|
230 { |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
231 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
|
232 if (!expunge_mails(client)) { |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
233 client_send_storage_error(client); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
234 client_disconnect(client, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
235 "Storage error during logout."); |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
236 return 1; |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
237 } |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
238 } |
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 |
5089 | 240 if (mailbox_transaction_commit(&client->trans, |
241 MAILBOX_SYNC_FLAG_FULL_WRITE) < 0) { | |
242 client_send_storage_error(client); | |
243 client_disconnect(client, "Storage error during logout."); | |
244 return 1; | |
245 } | |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 |
1640
db14aa8e2b5c
API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents:
1507
diff
changeset
|
247 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
|
248 client_send_line(client, "+OK Logging out."); |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
249 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
|
250 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
|
251 |
4096
904c53275e83
Log a line when IMAP client disconnects with a reason why it happened.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
252 client_disconnect(client, "Logged out"); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
253 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
|
254 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
262 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
|
263 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
|
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 unsigned char last; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
266 bool cr_skipped, in_body; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
267 }; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
268 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
269 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
|
270 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
271 (void)mailbox_search_deinit(&ctx->search_ctx); |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
272 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
|
273 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
|
274 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
275 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
276 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
|
277 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 size_t i, size; |
2712
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
282 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
|
283 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
284 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
|
285 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
|
286 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
|
287 size = 4096; |
1051 | 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 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
|
290 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
|
291 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
|
292 !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
|
293 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
|
294 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
|
295 ctx->in_body = TRUE; |
1051 | 296 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
|
297 ctx->in_body = TRUE; |
1051 | 298 } |
299 | |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
300 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
|
301 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
|
302 (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
|
303 /* 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
|
304 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
|
305 break; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
306 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
307 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
308 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
|
309 if (--ctx->body_lines == 0) { |
1051 | 310 i++; |
311 break; | |
312 } | |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
313 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
314 } 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
|
315 ((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
|
316 (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
|
317 /* 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
|
318 add = '.'; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
319 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
|
320 } 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
|
321 (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
|
322 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
|
323 add = 0x80; |
2323 | 324 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
|
325 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
326 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
327 |
2520 | 328 if (i > 0) { |
329 if (o_stream_send(client->output, data, i) < 0) | |
330 break; | |
331 ctx->last = data[i-1]; | |
332 i_stream_skip(ctx->stream, i); | |
333 } | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
334 |
2712
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
335 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
|
336 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
|
337 break; |
2712
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
338 if (ret == 0) { |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
339 /* continue later */ |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
340 return; |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
341 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
342 } |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
343 |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
344 if (add != '\0') { |
2494 | 345 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
|
346 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
347 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
352 } |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
353 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
354 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
|
355 /* 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
|
356 (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
|
357 } |
1507
1fad8b3d7ef1
If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents:
1071
diff
changeset
|
358 |
2952 | 359 if (!ctx->in_body && (client_workarounds & WORKAROUND_OE_NS_EOH) != 0) { |
360 /* Add the missing end of headers line. */ | |
361 (void)o_stream_send(client->output, "\r\n", 2); | |
362 } | |
363 | |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
364 *client->byte_counter += |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
365 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
|
366 client->byte_counter = NULL; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
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 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
|
369 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
|
370 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
|
371 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
372 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
373 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
|
374 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
375 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
|
376 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
377 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
|
378 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
383 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
|
384 &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
|
385 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
|
386 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
|
387 |
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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 return; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 |
2719
f8adc5cb2508
Renamed pop3_mails_keep_recent to pop3_no_flag_updates which includes
Timo Sirainen <tss@iki.fi>
parents:
2712
diff
changeset
|
399 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
|
400 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
|
401 /* 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
|
402 (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
|
403 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
|
404 } |
2527
792b3209f705
Make RETR mark the message seen.
Timo Sirainen <tss@iki.fi>
parents:
2520
diff
changeset
|
405 } |
792b3209f705
Make RETR mark the message seen.
Timo Sirainen <tss@iki.fi>
parents:
2520
diff
changeset
|
406 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 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
|
411 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
412 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
|
413 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
|
414 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
415 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
416 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
|
417 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
|
418 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
|
419 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
420 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
421 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
|
422 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
423 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
|
424 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
425 if (get_msgnum(client, args, &msgnum) == NULL) |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
426 return 0; |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
427 |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
428 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
|
429 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
|
430 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
431 client->retr_count++; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
432 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
|
433 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
|
434 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
435 fetch(client, msgnum, (uoff_t)-1); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
436 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
|
437 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
439 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
|
440 { |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
441 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
|
442 struct mail *mail; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
443 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
|
444 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
|
445 |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
446 client->last_seen = 0; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
447 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
454 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
455 /* forget all our seen flag updates as well.. */ |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
456 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
|
457 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
|
458 |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
459 if (enable_last_command) { |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
460 /* remove all \Seen flags */ |
3558 | 461 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
|
462 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
|
463 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
|
464 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
|
465 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
|
466 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
|
467 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
468 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
|
469 &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
|
470 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
|
471 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
|
472 if (mail_update_flags(mail, MODIFY_REMOVE, |
bfb2658a2616
RSET command wasn't working right
Timo Sirainen <tss@iki.fi>
parents:
3384
diff
changeset
|
473 MAIL_SEEN) < 0) |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
474 break; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
475 } |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
476 mail_free(&mail); |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
477 (void)mailbox_search_deinit(&search_ctx); |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
478 } |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
479 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 client_send_line(client, "+OK"); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
481 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
|
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 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
484 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
|
485 { |
1044
50d258907c99
Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents:
1043
diff
changeset
|
486 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
|
487 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
|
488 client->total_size - client->deleted_size); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
489 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
|
490 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
491 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
492 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
|
493 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
494 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
|
495 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
|
496 |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
497 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
|
498 if (args == NULL) |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
499 return 0; |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
500 if (get_size(client, args, &max_lines) == NULL) |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
501 return 0; |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
502 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
503 client->top_count++; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
504 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
|
505 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
|
506 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
507 fetch(client, msgnum, max_lines); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
508 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
|
509 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
511 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
|
512 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
|
513 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
|
514 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
|
515 |
1845
bd8b6ed35327
Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
516 struct mail_search_arg search_arg; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
517 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
|
518 }; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
519 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
520 static bool list_uids_iter(struct client *client, struct cmd_uidl_context *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
|
521 { |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
522 static struct var_expand_table static_tab[] = { |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
523 { 'v', NULL }, |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
524 { 'u', NULL }, |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
525 { 'm', NULL }, |
2996
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
526 { 'f', NULL }, |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
527 { '\0', NULL } |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
528 }; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
529 struct var_expand_table *tab; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
530 string_t *str; |
3567
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
531 const char *uidl; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
532 int ret; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
533 bool 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
|
534 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
535 tab = t_malloc(sizeof(static_tab)); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
536 memcpy(tab, static_tab, sizeof(static_tab)); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
537 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
|
538 |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
539 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
|
540 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
|
541 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
|
542 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
|
543 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
|
544 (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
|
545 continue; |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
546 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
547 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
|
548 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
549 t_push(); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
550 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
|
551 tab[1].value = dec2str(ctx->mail->uid); |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
552 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
|
553 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
|
554 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
|
555 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
|
556 /* broken */ |
5125
0b7be87efd7c
If UIDL command can't get the UID, die instead of not returning anything and
Timo Sirainen <tss@iki.fi>
parents:
5089
diff
changeset
|
557 i_fatal("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
|
558 } |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
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 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
|
561 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
|
562 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
|
563 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
|
564 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
|
565 /* broken */ |
5125
0b7be87efd7c
If UIDL command can't get the UID, die instead of not returning anything and
Timo Sirainen <tss@iki.fi>
parents:
5089
diff
changeset
|
566 i_fatal("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
|
567 } |
2996
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
568 } |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
569 |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
570 str_truncate(str, 0); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
571 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
|
572 ctx->mail->seq); |
3567
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
573 |
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
574 uidl = !reuse_xuidl ? NULL : |
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
575 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
|
576 if (uidl == NULL) |
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
577 var_expand(str, uidl_format, tab); |
3733
74b27d1e17a4
Make pop3_reuse_xuidl setting actually work. Patch by grant beattie.
Timo Sirainen <tss@iki.fi>
parents:
3663
diff
changeset
|
578 else |
74b27d1e17a4
Make pop3_reuse_xuidl setting actually work. Patch by grant beattie.
Timo Sirainen <tss@iki.fi>
parents:
3663
diff
changeset
|
579 str_append(str, uidl); |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
580 ret = client_send_line(client, "%s", str_c(str)); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
581 t_pop(); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
582 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
583 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
|
584 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
585 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
|
586 /* 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
|
587 more space */ |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
588 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
|
589 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
|
590 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
591 } |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
592 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
|
593 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
594 /* finished */ |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
595 mail_free(&ctx->mail); |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
596 (void)mailbox_search_deinit(&ctx->search_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
|
597 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
598 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
|
599 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
600 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
|
601 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
|
602 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
|
603 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
|
604 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
605 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
606 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
|
607 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
608 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
|
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 (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
|
611 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
612 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
613 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
|
614 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
|
615 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
616 struct cmd_uidl_context *ctx; |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
617 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
|
618 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
619 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
|
620 |
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
|
621 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
|
622 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
|
623 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
|
624 } else { |
2684 | 625 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
|
626 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
|
627 } |
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
|
628 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
|
629 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
|
630 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
631 wanted_fields = 0; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
632 if ((uidl_keymask & UIDL_MD5) != 0) |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
633 wanted_fields |= MAIL_FETCH_HEADER_MD5; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
634 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
635 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
|
636 &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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
642 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
|
643 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
644 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
645 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
|
646 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
647 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
|
648 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
649 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
|
650 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
|
651 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
|
652 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
|
653 } else { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
654 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
|
655 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
656 if (get_msgnum(client, args, &msgnum) == NULL) |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
657 return 0; |
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 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
659 ctx = cmd_uidl_init(client, msgnum+1); |
2684 | 660 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
|
661 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
|
662 } |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
663 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3733
diff
changeset
|
664 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
|
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 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
667 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
|
668 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
|
669 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
670 /* 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
|
671 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
|
672 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
673 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
|
674 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
675 switch (*name) { |
1059
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
676 case 'C': |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
677 if (strcmp(name, "CAPA") == 0) |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
678 return cmd_capa(client, args); |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
679 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
|
680 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
|
681 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
|
682 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
|
683 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
684 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
|
685 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
|
686 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
|
687 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
|
688 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
|
689 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
690 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
|
691 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
|
692 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
|
693 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
694 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
|
695 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
|
696 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
|
697 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
698 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
|
699 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
|
700 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
|
701 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
|
702 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
|
703 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
704 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
|
705 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
|
706 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
|
707 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
708 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
|
709 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
|
710 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
|
711 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
712 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
|
713 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
|
714 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
|
715 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
716 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
717 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
718 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
|
719 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
|
720 } |