annotate src/pop3/commands.c @ 3879:928229f8b3e6 HEAD

deinit, unref, destroy, close, free, etc. functions now take a pointer to their data pointer, and set it to NULL. This makes double-frees less likely to cause security holes.
author Timo Sirainen <tss@iki.fi>
date Sat, 14 Jan 2006 20:47:20 +0200
parents 55df57c028d4
children 904c53275e83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2002 Timo Sirainen */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
4 #include "istream.h"
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
5 #include "ostream.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "str.h"
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
7 #include "var-expand.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "message-size.h"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "mail-storage.h"
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
10 #include "mail-search.h"
1059
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
11 #include "capability.h"
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "commands.h"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #define MSGS_BITMASK_SIZE(client) \
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 ((client->messages_count + (CHAR_BIT-1)) / CHAR_BIT)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 static const char *get_msgnum(struct client *client, const char *args,
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 unsigned int *msgnum)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 unsigned int num, last_num;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 num = 0;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 while (*args != '\0' && *args != ' ') {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 if (*args < '0' || *args > '9') {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 client_send_line(client,
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 "-ERR Invalid message number: %s", args);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 return NULL;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 last_num = num;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 num = num*10 + (*args - '0');
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 if (num < last_num) {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 client_send_line(client,
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 "-ERR Message number too large: %s", args);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 return NULL;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 args++;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
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
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
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
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
45 num--;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 if (client->deleted) {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 if (client->deleted_bitmask[num / CHAR_BIT] &
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 (1 << (num % CHAR_BIT))) {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 client_send_line(client, "-ERR Message is deleted.");
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 return NULL;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 while (*args == ' ') args++;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 *msgnum = num;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 return args;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 static const char *get_size(struct client *client, const char *args,
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 uoff_t *size)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 uoff_t num, last_num;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 num = 0;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 while (*args != '\0' && *args != ' ') {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 if (*args < '0' || *args > '9') {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 client_send_line(client, "-ERR Invalid size: %s",
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 args);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 return NULL;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 last_num = num;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 num = num*10 + (*args - '0');
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 if (num < last_num) {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 client_send_line(client, "-ERR Size too large: %s",
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 args);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 return NULL;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 args++;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 while (*args == ' ') args++;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 *size = num;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 return args;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89
1059
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
90 static int cmd_capa(struct client *client, const char *args __attr_unused__)
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
91 {
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
92 client_send_line(client, "+OK\r\n"POP3_CAPABILITY_REPLY".");
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3733
diff changeset
93 return 1;
1059
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
94 }
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
95
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
96 static int cmd_dele(struct client *client, const char *args)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 unsigned int msgnum;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 if (get_msgnum(client, args, &msgnum) == NULL)
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3733
diff changeset
101 return 0;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 if (!client->deleted) {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 client->deleted_bitmask = i_malloc(MSGS_BITMASK_SIZE(client));
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 client->deleted = TRUE;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 client->deleted_bitmask[msgnum / CHAR_BIT] |= 1 << (msgnum % CHAR_BIT);
1994
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
109 client->deleted_count++;
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
110 client->deleted_size += client->message_sizes[msgnum];
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 client_send_line(client, "+OK Marked to be deleted.");
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3733
diff changeset
112 return 1;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
115 struct cmd_list_context {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
116 unsigned int msgnum;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
117 };
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
118
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
119 static void cmd_list_callback(struct client *client)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
120 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
121 struct cmd_list_context *ctx = client->cmd_context;
3663
6d485bf73429 Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
122 int ret = 1;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
123
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
124 for (; ctx->msgnum != client->messages_count; ctx->msgnum++) {
3663
6d485bf73429 Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
125 if (ret == 0) {
6d485bf73429 Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
126 /* buffer full */
6d485bf73429 Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
127 return;
6d485bf73429 Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
128 }
6d485bf73429 Don't send duplicate lines in LIST command when buffer is full.
Timo Sirainen <tss@iki.fi>
parents: 3567
diff changeset
129
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
130 if (client->deleted) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
131 if (client->deleted_bitmask[ctx->msgnum / CHAR_BIT] &
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
132 (1 << (ctx->msgnum % CHAR_BIT)))
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
133 continue;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
134 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
135 ret = client_send_line(client, "%u %"PRIuUOFF_T,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
136 ctx->msgnum+1,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
137 client->message_sizes[ctx->msgnum]);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
138 if (ret < 0)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
139 break;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
140 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
141
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
142 client_send_line(client, ".");
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
143
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
144 i_free(ctx);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
145 client->cmd = NULL;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
146 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
147
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
148 static int cmd_list(struct client *client, const char *args)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
150 struct cmd_list_context *ctx;
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
151
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 if (*args == '\0') {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
153 ctx = i_new(struct cmd_list_context, 1);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 client_send_line(client, "+OK %u messages:",
1994
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
155 client->messages_count - client->deleted_count);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
156
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
157 client->cmd = cmd_list_callback;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
158 client->cmd_context = ctx;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
159 cmd_list_callback(client);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 } else {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 unsigned int msgnum;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
163 if (get_msgnum(client, args, &msgnum) == NULL)
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3733
diff changeset
164 return 0;
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
165
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
166 client_send_line(client, "+OK %u %"PRIuUOFF_T, msgnum+1,
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
167 client->message_sizes[msgnum]);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 }
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
169
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3733
diff changeset
170 return 1;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
173 static int cmd_last(struct client *client, const char *args __attr_unused__)
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
174 {
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
175 client_send_line(client, "+OK %u", client->last_seen);
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3733
diff changeset
176 return 1;
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
177 }
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
178
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
179 static int cmd_noop(struct client *client, const char *args __attr_unused__)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 client_send_line(client, "+OK");
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3733
diff changeset
182 return 1;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3733
diff changeset
185 static bool expunge_mails(struct client *client)
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
186 {
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
187 struct mail_search_arg search_arg;
3557
ca22e27202b2 If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
188 struct mail_search_seqset seqset;
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
189 struct mail_search_context *ctx;
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
190 struct mail *mail;
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
191 uint32_t idx;
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3733
diff changeset
192 bool ret = TRUE;
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
193
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
194 if (client->deleted_bitmask == NULL)
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
195 return TRUE;
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
196
3558
Timo Sirainen <tss@iki.fi>
parents: 3557
diff changeset
197 memset(&seqset, 0, sizeof(seqset));
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
198 memset(&search_arg, 0, sizeof(search_arg));
3557
ca22e27202b2 If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
199 seqset.seq1 = 1;
ca22e27202b2 If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
200 seqset.seq2 = client->messages_count;
ca22e27202b2 If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
201 search_arg.type = SEARCH_SEQSET;
ca22e27202b2 If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
202 search_arg.value.seqset = &seqset;
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
203
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
204 ctx = mailbox_search_init(client->trans, NULL, &search_arg, NULL);
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
205 mail = mail_alloc(client->trans, 0, NULL);
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
206 while (mailbox_search_next(ctx, mail) > 0) {
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
207 idx = mail->seq - 1;
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
208 if ((client->deleted_bitmask[idx / CHAR_BIT] &
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
209 1 << (idx % CHAR_BIT)) != 0) {
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
210 if (mail_expunge(mail) < 0) {
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
211 ret = FALSE;
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
212 break;
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
213 }
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
214 }
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
215 }
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
216 mail_free(&mail);
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
217
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
218 if (mailbox_search_deinit(&ctx) < 0)
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
219 ret = FALSE;
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
220 return ret;
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
221 }
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
222
2711
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
223 static int cmd_quit(struct client *client, const char *args __attr_unused__)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224 {
2711
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
225 if (client->deleted) {
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
226 if (!expunge_mails(client)) {
2711
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
227 client_send_storage_error(client);
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
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
234 mailbox_transaction_commit(&client->trans,
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
235 MAILBOX_SYNC_FLAG_FULL_WRITE);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
237 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
238 client_send_line(client, "+OK Logging out.");
2711
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
239 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
240 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
241
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
242 client_disconnect(client, "Logout.");
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
243 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
244 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
246 struct 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
247 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
248 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
249 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
250 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
251
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
252 struct mail_search_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
253 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
254
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
255 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
256 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
257 };
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
258
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
259 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
260 {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
261 (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
262 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
263 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
264 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
265
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
266 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
267 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
268 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
269 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
270 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
271 size_t i, size;
2712
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
272 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
273
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 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
275 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
276 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
277 size = 4096;
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
278
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
279 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
280 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
281 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
282 !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
283 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
284 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
285 ctx->in_body = TRUE;
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
286 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
287 ctx->in_body = TRUE;
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
288 }
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
289
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
290 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
291 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
292 (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
293 /* 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
294 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
295 break;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
296 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
297
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
298 if (ctx->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
299 if (--ctx->body_lines == 0) {
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
300 i++;
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
301 break;
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
302 }
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
303 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
304 } 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
305 ((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
306 (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
307 /* 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
308 add = '.';
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
309 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
310 } 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
311 (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
312 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
313 add = 0x80;
2323
ec1dac19cb06 outlook-no-nuls workaround fix
Timo Sirainen <tss@iki.fi>
parents: 2316
diff changeset
314 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
315 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
316 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
317
2520
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
318 if (i > 0) {
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
319 if (o_stream_send(client->output, data, i) < 0)
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
320 break;
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
321 ctx->last = data[i-1];
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
322 i_stream_skip(ctx->stream, i);
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
323 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
324
2712
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
325 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
326 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
327 break;
2712
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
328 if (ret == 0) {
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
329 /* continue later */
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
330 return;
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
331 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
332 }
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
333
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
334 if (add != '\0') {
2494
a2e2c76021b9 Fixes for nonblocking changes.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
335 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
336 break;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
337
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
338 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
339 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
340 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
341 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
342 }
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
343
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
344 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
345 /* 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
346 (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
347 }
1507
1fad8b3d7ef1 If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents: 1071
diff changeset
348
2952
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2928
diff changeset
349 if (!ctx->in_body && (client_workarounds & WORKAROUND_OE_NS_EOH) != 0) {
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2928
diff changeset
350 /* Add the missing end of headers line. */
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2928
diff changeset
351 (void)o_stream_send(client->output, "\r\n", 2);
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2928
diff changeset
352 }
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2928
diff changeset
353
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
354 *client->byte_counter +=
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
355 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
356 client->byte_counter = NULL;
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
357
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
358 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
359 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
360 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
361 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
362
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
363 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
364 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
365 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
366
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
367 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
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 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
370 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
371 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
372
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
373 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
374 &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
375 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
376 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
377
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 if (mailbox_search_next(ctx->search_ctx, ctx->mail) <= 0)
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
379 ctx->stream = NULL;
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
380 else
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
381 ctx->stream = mail_get_stream(ctx->mail, NULL, NULL);
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
382
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
383 if (ctx->stream == NULL) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
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
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
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
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
445 /* forget all our seen flag updates as well.. */
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
446 mailbox_transaction_rollback(&client->trans);
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
447 client->trans = mailbox_transaction_begin(client->mailbox, 0);
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
448
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
449 if (enable_last_command) {
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
450 /* remove all \Seen flags */
3558
Timo Sirainen <tss@iki.fi>
parents: 3557
diff changeset
451 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
452 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
453 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
454 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
455 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
456 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
457
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
458 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
459 &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
460 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
461 while (mailbox_search_next(search_ctx, mail) > 0) {
3387
bfb2658a2616 RSET command wasn't working right
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
462 if (mail_update_flags(mail, MODIFY_REMOVE,
bfb2658a2616 RSET command wasn't working right
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
463 MAIL_SEEN) < 0)
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
464 break;
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
465 }
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
466 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
467 (void)mailbox_search_deinit(&search_ctx);
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
468 }
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
469
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 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
471 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
472 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
474 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
475 {
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
476 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
477 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
478 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
479 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
480 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
482 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
483 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
484 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
485 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
486
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
487 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
488 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
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 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
491 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
492
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
493 client->top_count++;
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
494 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
495 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
496
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
497 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
498 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
499 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
500
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
501 struct 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
502 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
503 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
504 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
505
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
506 struct mail_search_arg search_arg;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
507 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
508 };
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
509
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
510 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
511 {
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
512 static struct var_expand_table static_tab[] = {
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
513 { 'v', NULL },
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
514 { 'u', NULL },
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
515 { 'm', NULL },
2996
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
516 { 'f', NULL },
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
517 { '\0', NULL }
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
518 };
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
519 struct var_expand_table *tab;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
520 string_t *str;
3567
58e3fa234ef4 Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents: 3558
diff changeset
521 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
522 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
523 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
524
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
525 tab = t_malloc(sizeof(static_tab));
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
526 memcpy(tab, static_tab, sizeof(static_tab));
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
527 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
528
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
529 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
530 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
531 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
532 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
533 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
534 (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
535 continue;
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
536 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
537 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
538
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
539 t_push();
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
540 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
541 tab[1].value = dec2str(ctx->mail->uid);
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
542 if ((uidl_keymask & UIDL_MD5) != 0) {
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
543 tab[2].value = mail_get_special(ctx->mail,
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
544 MAIL_FETCH_HEADER_MD5);
3357
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
545 if (tab[2].value == NULL) {
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
546 /* broken */
3388
814ba0c6877f If we couldn't get UIDL, also write error to log.
Timo Sirainen <tss@iki.fi>
parents: 3387
diff changeset
547 i_error("UIDL: Header MD5 not found");
3357
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
548 t_pop();
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
549 break;
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
550 }
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
551 }
2996
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
552 if ((uidl_keymask & UIDL_FILE_NAME) != 0) {
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
553 tab[3].value =
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
554 mail_get_special(ctx->mail,
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
555 MAIL_FETCH_UIDL_FILE_NAME);
3357
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
556 if (tab[3].value == NULL) {
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
557 /* broken */
3388
814ba0c6877f If we couldn't get UIDL, also write error to log.
Timo Sirainen <tss@iki.fi>
parents: 3387
diff changeset
558 i_error("UIDL: File name not found");
3357
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
559 t_pop();
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
560 break;
2d8874b023ea If we couldn't fetch header MD5/filename for UIDL, abort instead of giving
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
561 }
2996
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
562 }
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
563
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
564 str_truncate(str, 0);
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
565 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
566 ctx->mail->seq);
3567
58e3fa234ef4 Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents: 3558
diff changeset
567
58e3fa234ef4 Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents: 3558
diff changeset
568 uidl = !reuse_xuidl ? NULL :
58e3fa234ef4 Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents: 3558
diff changeset
569 mail_get_first_header(ctx->mail, "X-UIDL");
58e3fa234ef4 Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents: 3558
diff changeset
570 if (uidl == NULL)
58e3fa234ef4 Added pop3_reuse_xuidl setting. Patch by Chris Wakelin
Timo Sirainen <tss@iki.fi>
parents: 3558
diff changeset
571 var_expand(str, uidl_format, tab);
3733
74b27d1e17a4 Make pop3_reuse_xuidl setting actually work. Patch by grant beattie.
Timo Sirainen <tss@iki.fi>
parents: 3663
diff changeset
572 else
74b27d1e17a4 Make pop3_reuse_xuidl setting actually work. Patch by grant beattie.
Timo Sirainen <tss@iki.fi>
parents: 3663
diff changeset
573 str_append(str, uidl);
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
574 ret = client_send_line(client, "%s", str_c(str));
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
575 t_pop();
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
576
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
577 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
578 break;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
579 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
580 /* 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
581 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
582 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
583 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
584 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
585 }
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
586 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
587
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
588 /* finished */
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
589 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
590 (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
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 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
593
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
594 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
595 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
596 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
597 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
598 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
599
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 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
601 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
602 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
603
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
604 (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
605 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
606
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
607 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
608 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
609 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
610 struct cmd_uidl_context *ctx;
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
611 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
612
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 = 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
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 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
616 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
617 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
618 } else {
2684
7979984b6276 "UIDL <message>" was broken.
Timo Sirainen <tss@iki.fi>
parents: 2621
diff changeset
619 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
620 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
621 }
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
622 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
623 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
624
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
625 wanted_fields = 0;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
626 if ((uidl_keymask & UIDL_MD5) != 0)
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
627 wanted_fields |= MAIL_FETCH_HEADER_MD5;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
628
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
629 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
630 &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
631 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
632 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
633 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
634 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
635 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
636 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
637 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
638
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
639 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
640 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
641 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
642
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
643 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
644 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
645 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
646 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
647 } else {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
648 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
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 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
651 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
652
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
653 ctx = cmd_uidl_init(client, msgnum+1);
2684
7979984b6276 "UIDL <message>" was broken.
Timo Sirainen <tss@iki.fi>
parents: 2621
diff changeset
654 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
655 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
656 }
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
657
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
658 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
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
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
661 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
662 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
663 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
664 /* 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
665 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
666
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
667 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
668
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
669 switch (*name) {
1059
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
670 case 'C':
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
671 if (strcmp(name, "CAPA") == 0)
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
672 return cmd_capa(client, args);
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
673 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
674 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
675 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
676 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
677 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
678 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
679 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
680 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
681 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
682 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
683 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
684 case '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
685 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
686 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
687 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
688 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
689 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
690 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
691 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
692 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
693 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
694 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
695 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
696 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
697 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
698 case '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
699 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
700 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
701 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
702 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
703 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
704 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
705 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
706 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
707 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
708 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
709 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
710 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
711
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
712 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
713 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
714 }