Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/pop3/commands.c @ 6429:65c69a53a7be HEAD
Replaced my Copyright notices. The year range always ends with 2007 now.
My name was replaced with "Dovecot authors". In many cases I didn't really
even own the copyright, so this is more correct.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 16 Sep 2007 14:34:22 +0300 |
parents | 6a64e64fa3a3 |
children | 1a3604c8ee05 |
rev | line source |
---|---|
6429
65c69a53a7be
Replaced my Copyright notices. The year range always ends with 2007 now.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
1 /* Copyright (c) 2002-2007 Dovecot authors, see the included COPYING file */ |
1043
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 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
90 static int cmd_capa(struct client *client, const char *args ATTR_UNUSED) |
1059
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 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
173 static int cmd_last(struct client *client, const char *args ATTR_UNUSED) |
2621
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 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
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; |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
192 |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
193 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
|
194 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
|
195 |
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
|
196 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
|
197 /* 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
|
198 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
|
199 } |
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 |
3558 | 201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 |
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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 1 << (idx % CHAR_BIT)) != 0) { |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
5135
diff
changeset
|
214 mail_expunge(mail); |
4566
aa9109a17db6
Show number of actually expunged messages in logout message, instead of
Timo Sirainen <tss@iki.fi>
parents:
4470
diff
changeset
|
215 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
|
216 } |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
217 } |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
218 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
|
219 |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
5135
diff
changeset
|
220 return mailbox_search_deinit(&ctx) == 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
|
221 } |
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
222 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
223 static int cmd_quit(struct client *client, const char *args ATTR_UNUSED) |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 { |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
225 if (client->deleted) { |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
226 if (!expunge_mails(client)) { |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
227 client_send_storage_error(client); |
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
|
228 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
|
229 "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
|
230 return 1; |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
231 } |
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 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 |
5089 | 234 if (mailbox_transaction_commit(&client->trans, |
235 MAILBOX_SYNC_FLAG_FULL_WRITE) < 0) { | |
236 client_send_storage_error(client); | |
237 client_disconnect(client, "Storage error during logout."); | |
238 return 1; | |
239 } | |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 |
1640
db14aa8e2b5c
API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents:
1507
diff
changeset
|
241 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
|
242 client_send_line(client, "+OK Logging out."); |
2711
d2e899bb6f5b
Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2694
diff
changeset
|
243 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
|
244 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
|
245 |
4096
904c53275e83
Log a line when IMAP client disconnects with a reason why it happened.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
246 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
|
247 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
|
248 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 |
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 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
|
257 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
|
258 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
259 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
|
260 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
|
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 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
263 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
|
264 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
265 (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
|
266 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
|
267 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
|
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 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
270 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
|
271 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
272 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
|
273 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
|
274 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
|
275 size_t i, size; |
2712
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
276 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
|
277 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 size = 4096; |
1051 | 282 |
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 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
|
284 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
|
285 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
|
286 !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
|
287 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
|
288 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
|
289 ctx->in_body = TRUE; |
1051 | 290 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
|
291 ctx->in_body = TRUE; |
1051 | 292 } |
293 | |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
294 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
|
295 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
|
296 (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
|
297 /* 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
|
298 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
|
299 break; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
300 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
301 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
302 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
|
303 if (--ctx->body_lines == 0) { |
1051 | 304 i++; |
305 break; | |
306 } | |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
307 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
308 } 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
|
309 ((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
|
310 (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
|
311 /* 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
|
312 add = '.'; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
313 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
|
314 } 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
|
315 (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
|
316 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
|
317 add = 0x80; |
2323 | 318 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
|
319 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
320 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
321 |
2520 | 322 if (i > 0) { |
323 if (o_stream_send(client->output, data, i) < 0) | |
324 break; | |
325 ctx->last = data[i-1]; | |
326 i_stream_skip(ctx->stream, i); | |
327 } | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
328 |
2712
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
329 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
|
330 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
|
331 break; |
2712
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
332 if (ret == 0) { |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
333 /* continue later */ |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
334 return; |
c710572d7075
Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents:
2711
diff
changeset
|
335 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
336 } |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
337 |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
338 if (add != '\0') { |
2494 | 339 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
|
340 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
341 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 } |
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 } |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
347 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
348 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
|
349 /* 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
|
350 (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
|
351 } |
1507
1fad8b3d7ef1
If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents:
1071
diff
changeset
|
352 |
2952 | 353 if (!ctx->in_body && (client_workarounds & WORKAROUND_OE_NS_EOH) != 0) { |
354 /* Add the missing end of headers line. */ | |
355 (void)o_stream_send(client->output, "\r\n", 2); | |
356 } | |
357 | |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
358 *client->byte_counter += |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
359 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
|
360 client->byte_counter = NULL; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
361 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
366 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
367 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
|
368 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
369 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
|
370 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
371 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
|
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 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
|
374 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
|
375 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
|
376 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
377 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
|
378 &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
|
379 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
|
380 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
|
381 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
382 if (mailbox_search_next(ctx->search_ctx, ctx->mail) <= 0 || |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
383 mail_get_stream(ctx->mail, NULL, NULL, &ctx->stream) < 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
|
384 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
|
385 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
|
386 return; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
388 |
2719
f8adc5cb2508
Renamed pop3_mails_keep_recent to pop3_no_flag_updates which includes
Timo Sirainen <tss@iki.fi>
parents:
2712
diff
changeset
|
389 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
|
390 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
|
391 /* 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
|
392 (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
|
393 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
|
394 } |
2527
792b3209f705
Make RETR mark the message seen.
Timo Sirainen <tss@iki.fi>
parents:
2520
diff
changeset
|
395 } |
792b3209f705
Make RETR mark the message seen.
Timo Sirainen <tss@iki.fi>
parents:
2520
diff
changeset
|
396 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
397 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
|
398 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
|
399 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
|
400 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
|
401 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
402 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
|
403 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
|
404 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
406 client->cmd = 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
|
407 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
|
408 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
|
409 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
411 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
|
412 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
413 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
|
414 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
415 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
|
416 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
|
417 |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
418 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
|
419 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
|
420 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
421 client->retr_count++; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
422 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
|
423 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
|
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 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
|
426 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
|
427 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
428 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
429 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
|
430 { |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
431 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
|
432 struct mail *mail; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
433 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
|
434 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
|
435 |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
436 client->last_seen = 0; |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
437 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 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
|
439 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
|
440 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
|
441 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
|
442 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
|
443 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
445 if (enable_last_command) { |
5135
1a7359d6a774
RSET: Don't rollback the transaction if LAST is enabled (there's no point,
Timo Sirainen <tss@iki.fi>
parents:
5125
diff
changeset
|
446 /* remove all \Seen flags (as specified by RFC 1460) */ |
3558 | 447 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
|
448 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
454 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
|
455 &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
|
456 mail = mail_alloc(client->trans, 0, NULL); |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
5135
diff
changeset
|
457 while (mailbox_search_next(search_ctx, mail) > 0) |
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
5135
diff
changeset
|
458 mail_update_flags(mail, MODIFY_REMOVE, MAIL_SEEN); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
459 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
|
460 (void)mailbox_search_deinit(&search_ctx); |
5135
1a7359d6a774
RSET: Don't rollback the transaction if LAST is enabled (there's no point,
Timo Sirainen <tss@iki.fi>
parents:
5125
diff
changeset
|
461 } else { |
1a7359d6a774
RSET: Don't rollback the transaction if LAST is enabled (there's no point,
Timo Sirainen <tss@iki.fi>
parents:
5125
diff
changeset
|
462 /* forget all our seen flag updates. |
1a7359d6a774
RSET: Don't rollback the transaction if LAST is enabled (there's no point,
Timo Sirainen <tss@iki.fi>
parents:
5125
diff
changeset
|
463 FIXME: is this needed? it loses data added to cache file */ |
1a7359d6a774
RSET: Don't rollback the transaction if LAST is enabled (there's no point,
Timo Sirainen <tss@iki.fi>
parents:
5125
diff
changeset
|
464 mailbox_transaction_rollback(&client->trans); |
1a7359d6a774
RSET: Don't rollback the transaction if LAST is enabled (there's no point,
Timo Sirainen <tss@iki.fi>
parents:
5125
diff
changeset
|
465 client->trans = mailbox_transaction_begin(client->mailbox, 0); |
2621
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
466 } |
c6cc163344c3
Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents:
2527
diff
changeset
|
467 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 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
|
469 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
|
470 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
472 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
|
473 { |
1044
50d258907c99
Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents:
1043
diff
changeset
|
474 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
|
475 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
|
476 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
|
477 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
|
478 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
480 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
|
481 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
482 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
|
483 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
|
484 |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
485 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
|
486 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
|
487 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
|
488 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
|
489 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
|
490 |
3384
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
491 client->top_count++; |
3b75956d20c4
Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents:
3357
diff
changeset
|
492 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
|
493 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
|
494 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
495 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
|
496 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
|
497 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
498 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
499 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
|
500 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
|
501 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
|
502 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
|
503 |
1845
bd8b6ed35327
Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
504 struct mail_search_arg search_arg; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
505 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
|
506 }; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
507 |
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 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
|
509 { |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
510 static struct var_expand_table static_tab[] = { |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
511 { 'v', NULL }, |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
512 { 'u', NULL }, |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
513 { 'm', NULL }, |
2996
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
514 { 'f', NULL }, |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
515 { '\0', NULL } |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
516 }; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
517 struct var_expand_table *tab; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
518 string_t *str; |
3567
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
519 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
|
520 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
|
521 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
|
522 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
523 tab = t_malloc(sizeof(static_tab)); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
524 memcpy(tab, static_tab, sizeof(static_tab)); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
525 tab[0].value = t_strdup_printf("%u", client->uid_validity); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
526 |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
527 str = str_new(default_pool, 128); |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
528 while (mailbox_search_next(ctx->search_ctx, ctx->mail) > 0) { |
1994
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
529 if (client->deleted) { |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
530 uint32_t idx = ctx->mail->seq - 1; |
1994
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
531 if (client->deleted_bitmask[idx / CHAR_BIT] & |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
532 (1 << (idx % CHAR_BIT))) |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
533 continue; |
77f3111f7976
Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents:
1950
diff
changeset
|
534 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
535 found = TRUE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
536 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
537 t_push(); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
538 if ((uidl_keymask & UIDL_UID) != 0) |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3112
diff
changeset
|
539 tab[1].value = dec2str(ctx->mail->uid); |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
540 if ((uidl_keymask & UIDL_MD5) != 0) { |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
541 if (mail_get_special(ctx->mail, MAIL_FETCH_HEADER_MD5, |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
542 &tab[2].value) < 0 || |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
543 *tab[2].value == '\0') { |
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
|
544 /* 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
|
545 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
|
546 } |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
547 } |
2996
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
548 if ((uidl_keymask & UIDL_FILE_NAME) != 0) { |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
549 if (mail_get_special(ctx->mail, |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
550 MAIL_FETCH_UIDL_FILE_NAME, |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
551 &tab[3].value) < 0 || |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
552 *tab[3].value == '\0') { |
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
|
553 /* 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
|
554 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
|
555 } |
2996
9219e788d774
Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2976
diff
changeset
|
556 } |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
557 |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
558 str_truncate(str, 0); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
559 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
|
560 ctx->mail->seq); |
3567
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
561 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
562 if (reuse_xuidl && |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
563 mail_get_first_header(ctx->mail, "X-UIDL", &uidl) > 0) |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
564 str_append(str, uidl); |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
565 else |
3567
58e3fa234ef4
Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents:
3558
diff
changeset
|
566 var_expand(str, uidl_format, tab); |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
567 ret = client_send_line(client, "%s", str_c(str)); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
568 t_pop(); |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
569 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
570 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
|
571 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
572 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
|
573 /* 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
|
574 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
|
575 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
|
576 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
|
577 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
578 } |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
579 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
|
580 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
581 /* finished */ |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
582 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
|
583 (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
|
584 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
585 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
|
586 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
587 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
|
588 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
|
589 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
|
590 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
|
591 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
592 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
593 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
|
594 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
595 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
|
596 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
597 (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
|
598 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
599 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
600 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
|
601 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
|
602 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
603 struct cmd_uidl_context *ctx; |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
604 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
|
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 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
|
607 |
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
|
608 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
|
609 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
|
610 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
|
611 } else { |
2684 | 612 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
|
613 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
|
614 } |
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
|
615 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
|
616 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
|
617 |
2976
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
618 wanted_fields = 0; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
619 if ((uidl_keymask & UIDL_MD5) != 0) |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
620 wanted_fields |= MAIL_FETCH_HEADER_MD5; |
96a4ab34c8f1
Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents:
2952
diff
changeset
|
621 |
2722
8c5bcd6585a4
Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents:
2719
diff
changeset
|
622 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
|
623 &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
|
624 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
|
625 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
|
626 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
|
627 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
|
628 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
629 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
|
630 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
631 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
632 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
|
633 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
634 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
|
635 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
636 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
|
637 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
|
638 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
|
639 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
|
640 } else { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
641 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
|
642 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
643 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
|
644 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
|
645 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2323
diff
changeset
|
646 ctx = cmd_uidl_init(client, msgnum+1); |
2684 | 647 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
|
648 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
|
649 } |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
650 |
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
|
651 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
|
652 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
653 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
654 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
|
655 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
|
656 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
657 /* 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
|
658 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
|
659 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
660 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
|
661 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
662 switch (*name) { |
1059
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
663 case 'C': |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
664 if (strcmp(name, "CAPA") == 0) |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
665 return cmd_capa(client, args); |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
666 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
|
667 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
|
668 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
|
669 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
|
670 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
671 case '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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
677 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
|
678 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
|
679 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
|
680 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
681 case '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
|
682 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
|
683 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
|
684 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
685 case '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
|
686 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
|
687 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
|
688 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
|
689 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
|
690 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
691 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
|
692 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
|
693 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
|
694 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
695 case '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
|
696 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
|
697 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
|
698 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
699 case '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
|
700 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
|
701 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
|
702 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
703 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
704 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
705 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
|
706 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
|
707 } |