annotate src/pop3/commands.c @ 3558:bfd47c33c46d HEAD

Fix
author Timo Sirainen <tss@iki.fi>
date Sat, 27 Aug 2005 17:42:38 +0300
parents ca22e27202b2
children 58e3fa234ef4
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".");
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
93 return TRUE;
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
94 }
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
95
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
96 static int cmd_dele(struct client *client, const char *args)
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 unsigned int msgnum;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 if (get_msgnum(client, args, &msgnum) == NULL)
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
101 return FALSE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 if (!client->deleted) {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 client->deleted_bitmask = i_malloc(MSGS_BITMASK_SIZE(client));
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 client->deleted = TRUE;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 client->deleted_bitmask[msgnum / CHAR_BIT] |= 1 << (msgnum % CHAR_BIT);
1994
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
109 client->deleted_count++;
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
110 client->deleted_size += client->message_sizes[msgnum];
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 client_send_line(client, "+OK Marked to be deleted.");
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
112 return TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
115 struct cmd_list_context {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
116 unsigned int msgnum;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
117 };
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
118
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
119 static void cmd_list_callback(struct client *client)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
120 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
121 struct cmd_list_context *ctx = client->cmd_context;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
122 int ret;
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++) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
125 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
126 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
127 (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
128 continue;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
129 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
130 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
131 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
132 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
133 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
134 break;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
135 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
136 return;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
137 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
138
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
139 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
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 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
142 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
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
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
145 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
146 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
147 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
148
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 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
150 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
151 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
152 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
153
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
154 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
155 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
156 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
157 } else {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 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
159
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
160 if (get_msgnum(client, args, &msgnum) == NULL)
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
161 return FALSE;
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
162
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
163 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
164 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
165 }
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
166
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
167 return TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
170 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
171 {
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
172 client_send_line(client, "+OK %u", client->last_seen);
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
173 return TRUE;
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
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
176 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
177 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 client_send_line(client, "+OK");
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
179 return TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
182 static int expunge_mails(struct client *client)
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
183 {
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
184 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
185 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
186 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
187 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
188 uint32_t idx;
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
189 int ret = TRUE;
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
190
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
191 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
192 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
193
3558
Timo Sirainen <tss@iki.fi>
parents: 3557
diff changeset
194 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
195 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
196 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
197 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
198 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
199 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
200
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
201 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
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 }
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
211 }
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
212 }
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
213 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
214
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
215 if (mailbox_search_deinit(ctx) < 0)
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
216 ret = FALSE;
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
217 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
218 }
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
219
2711
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
220 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
221 {
2711
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
222 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
223 if (!expunge_mails(client)) {
2711
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
224 client_send_storage_error(client);
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
225 client_disconnect(client, "Storage error during logout.");
2711
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
226 return TRUE;
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
227 }
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
228 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
230 mailbox_transaction_commit(client->trans, MAILBOX_SYNC_FLAG_FULL_WRITE);
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
231 client->trans = NULL;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
233 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
234 client_send_line(client, "+OK Logging out.");
2711
d2e899bb6f5b Delay writing seen flags to mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2694
diff changeset
235 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
236 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
237
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
238 client_disconnect(client, "Logout.");
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
239 return TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
241
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
242 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
243 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
244 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
245 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
246 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
247
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
248 struct 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
249 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
250
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
251 unsigned char last;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
252 int cr_skipped, in_body;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
253 };
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
254
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
255 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
256 {
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 (void)mailbox_search_deinit(ctx->search_ctx);
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
258 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
259 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
260 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
261
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
262 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
263 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
264 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
265 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
266 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
267 size_t i, size;
2712
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
268 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
269
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 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
271 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
272 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
273 size = 4096;
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
274
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
275 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
276 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
277 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
278 !ctx->in_body) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
279 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
280 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
281 ctx->in_body = TRUE;
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
282 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
283 ctx->in_body = TRUE;
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
284 }
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
285
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
286 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
287 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
288 (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
289 /* 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
290 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
291 break;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
292 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
293
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
294 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
295 if (--ctx->body_lines == 0) {
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
296 i++;
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
297 break;
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
298 }
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
299 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
300 } 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
301 ((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
302 (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
303 /* 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
304 add = '.';
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
305 break;
2316
1c1ed4494aa4 Split client_workarounds to imap_ and pop3_ ones. Added outlook-no-nuls POP3
Timo Sirainen <tss@iki.fi>
parents: 2238
diff changeset
306 } 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
307 (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
308 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
309 add = 0x80;
2323
ec1dac19cb06 outlook-no-nuls workaround fix
Timo Sirainen <tss@iki.fi>
parents: 2316
diff changeset
310 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
311 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
312 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
313
2520
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
314 if (i > 0) {
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
315 if (o_stream_send(client->output, data, i) < 0)
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
316 break;
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
317 ctx->last = data[i-1];
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
318 i_stream_skip(ctx->stream, i);
255cea3e2331 fixed potential crash
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
319 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
320
2712
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
321 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
322 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
323 break;
2712
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
324 if (ret == 0) {
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
325 /* continue later */
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
326 return;
c710572d7075 Buffer more in memory before sending RETR replies.
Timo Sirainen <tss@iki.fi>
parents: 2711
diff changeset
327 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
328 }
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
329
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
330 if (add != '\0') {
2494
a2e2c76021b9 Fixes for nonblocking changes.
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
331 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
332 break;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
333
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
334 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
335 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
336 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
337 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
338 }
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
339
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
340 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
341 /* 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
342 (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
343 }
1507
1fad8b3d7ef1 If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents: 1071
diff changeset
344
2952
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2928
diff changeset
345 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
346 /* Add the missing end of headers line. */
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2928
diff changeset
347 (void)o_stream_send(client->output, "\r\n", 2);
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2928
diff changeset
348 }
546214c0e6e9 Added oe-ns-eoh workaround.
Timo Sirainen <tss@iki.fi>
parents: 2928
diff changeset
349
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
350 *client->byte_counter +=
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
351 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
352 client->byte_counter = NULL;
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
353
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
354 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
355 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
356 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
357 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
358
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
359 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
360 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
361 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
362
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
363 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
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 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
366 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
367 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
368
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
369 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
370 &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
371 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
372 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
373
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 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
375 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
376 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
377 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
378
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
379 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
380 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
381 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
382 return;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
384
2719
f8adc5cb2508 Renamed pop3_mails_keep_recent to pop3_no_flag_updates which includes
Timo Sirainen <tss@iki.fi>
parents: 2712
diff changeset
385 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
386 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
387 /* 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
388 (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
389 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
390 }
2527
792b3209f705 Make RETR mark the message seen.
Timo Sirainen <tss@iki.fi>
parents: 2520
diff changeset
391 }
792b3209f705 Make RETR mark the message seen.
Timo Sirainen <tss@iki.fi>
parents: 2520
diff changeset
392
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
393 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
394 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
395 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
396 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
397 } else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
398 client_send_line(client, "+OK");
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
399 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
400 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
401
2421
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->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
403 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
404 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
405 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
406
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
407 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
408 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409 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
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 if (get_msgnum(client, args, &msgnum) == NULL)
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
412 return FALSE;
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
413
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
414 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
415 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
416
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
417 client->retr_count++;
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
418 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
419 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
420
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
421 fetch(client, msgnum, (uoff_t)-1);
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
422 return TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
425 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
426 {
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
427 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
428 struct mail *mail;
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
429 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
430 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
431
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
432 client->last_seen = 0;
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
433
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434 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
435 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
436 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
437 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
438 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
439 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
441 /* forget all our seen flag updates as well.. */
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
442 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
443 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
444
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
445 if (enable_last_command) {
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
446 /* remove all \Seen flags */
3558
Timo Sirainen <tss@iki.fi>
parents: 3557
diff changeset
447 memset(&seqset, 0, sizeof(seqset));
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
448 memset(&search_arg, 0, sizeof(search_arg));
3557
ca22e27202b2 If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
449 seqset.seq1 = 1;
ca22e27202b2 If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
450 seqset.seq2 = client->messages_count;
ca22e27202b2 If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
451 search_arg.type = SEARCH_SEQSET;
ca22e27202b2 If more mail comes after we have synced ourself initially, don't access/show
Timo Sirainen <tss@iki.fi>
parents: 3441
diff changeset
452 search_arg.value.seqset = &seqset;
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
453
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
454 search_ctx = mailbox_search_init(client->trans, NULL,
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
455 &search_arg, NULL);
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
456 mail = mail_alloc(client->trans, 0, NULL);
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
457 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
458 if (mail_update_flags(mail, MODIFY_REMOVE,
bfb2658a2616 RSET command wasn't working right
Timo Sirainen <tss@iki.fi>
parents: 3384
diff changeset
459 MAIL_SEEN) < 0)
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
460 break;
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
461 }
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
462 mail_free(mail);
2621
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
463 (void)mailbox_search_deinit(search_ctx);
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
464 }
c6cc163344c3 Added pop3_enable_last setting to enable deprecated LAST command.
Timo Sirainen <tss@iki.fi>
parents: 2527
diff changeset
465
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 client_send_line(client, "+OK");
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
467 return TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
470 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
471 {
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
472 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
473 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
474 client->total_size - client->deleted_size);
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
475 return TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
476 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
478 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
479 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480 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
481 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
482
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
483 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
484 if (args == NULL)
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
485 return FALSE;
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
486 if (get_size(client, args, &max_lines) == NULL)
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
487 return FALSE;
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
488
3384
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
489 client->top_count++;
3b75956d20c4 Added configurable logging for login process. Added configurable pop3 logout
Timo Sirainen <tss@iki.fi>
parents: 3357
diff changeset
490 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
491 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
492
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
493 fetch(client, msgnum, max_lines);
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
494 return TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
495 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
496
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
497 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
498 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
499 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
500 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
501
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
502 struct mail_search_arg search_arg;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
503 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
504 };
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
505
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
506 static int list_uids_iter(struct client *client, struct cmd_uidl_context *ctx)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
507 {
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
508 static struct var_expand_table static_tab[] = {
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
509 { 'v', NULL },
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
510 { 'u', NULL },
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
511 { 'm', NULL },
2996
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
512 { 'f', NULL },
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
513 { '\0', NULL }
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
514 };
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
515 struct var_expand_table *tab;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
516 string_t *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
517 int ret, found = FALSE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
518
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
519 tab = t_malloc(sizeof(static_tab));
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
520 memcpy(tab, static_tab, sizeof(static_tab));
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
521 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
522
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
523 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
524 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
525 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
526 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
527 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
528 (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
529 continue;
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
530 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
531 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
532
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
533 t_push();
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
534 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
535 tab[1].value = dec2str(ctx->mail->uid);
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
536 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
537 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
538 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
539 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
540 /* broken */
3388
814ba0c6877f If we couldn't get UIDL, also write error to log.
Timo Sirainen <tss@iki.fi>
parents: 3387
diff changeset
541 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
542 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
543 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
544 }
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
545 }
2996
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
546 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
547 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
548 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
549 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
550 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
551 /* broken */
3388
814ba0c6877f If we couldn't get UIDL, also write error to log.
Timo Sirainen <tss@iki.fi>
parents: 3387
diff changeset
552 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
553 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
554 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
555 }
2996
9219e788d774 Added %f pop3_uidl_format for maildir. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents: 2976
diff changeset
556 }
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
557
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
558 str_truncate(str, 0);
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
559 str_printfa(str, ctx->message == 0 ? "%u " : "+OK %u ",
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
560 ctx->mail->seq);
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
561 var_expand(str, uidl_format, tab);
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
562
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
563 ret = client_send_line(client, "%s", str_c(str));
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
564 t_pop();
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
565
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
566 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
567 break;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
568 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
569 /* 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
570 more space */
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
571 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
572 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
573 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
574 }
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
575 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
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 /* finished */
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3112
diff changeset
578 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
579 (void)mailbox_search_deinit(ctx->search_ctx);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
580
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
581 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
582
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
583 if (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
584 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
585 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
586 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
587 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
588
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
589 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
590 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
591 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
592
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
593 (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
594 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
595
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
596 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
597 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
598 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
599 struct cmd_uidl_context *ctx;
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
600 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
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 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
603
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
604 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
605 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
606 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
607 } else {
2684
7979984b6276 "UIDL <message>" was broken.
Timo Sirainen <tss@iki.fi>
parents: 2621
diff changeset
608 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
609 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
610 }
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
611 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
612 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
613
2976
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
614 wanted_fields = 0;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
615 if ((uidl_keymask & UIDL_MD5) != 0)
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
616 wanted_fields |= MAIL_FETCH_HEADER_MD5;
96a4ab34c8f1 Added pop3_uidl_format setting.
Timo Sirainen <tss@iki.fi>
parents: 2952
diff changeset
617
2722
8c5bcd6585a4 Use only a single transaction for the whole duration of pop3 session. Avoids
Timo Sirainen <tss@iki.fi>
parents: 2719
diff changeset
618 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
619 &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
620 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
621 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
622 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
623 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
624 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
625 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
626 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
627
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
628 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
629 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
630 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
631
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
632 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
633 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
634 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
635 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
636 } else {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
637 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
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 if (get_msgnum(client, args, &msgnum) == NULL)
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
640 return FALSE;
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
641
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2323
diff changeset
642 ctx = cmd_uidl_init(client, msgnum+1);
2684
7979984b6276 "UIDL <message>" was broken.
Timo Sirainen <tss@iki.fi>
parents: 2621
diff changeset
643 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
644 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
645 }
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
646
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
647 return TRUE;
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
648 }
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 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
651 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
652 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
653 /* 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
654 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
655
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
656 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
657
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
658 switch (*name) {
1059
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
659 case 'C':
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
660 if (strcmp(name, "CAPA") == 0)
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
661 return cmd_capa(client, args);
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
662 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
663 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
664 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
665 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
666 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
667 case '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
668 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
669 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
670 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
671 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
672 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
673 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
674 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
675 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
676 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
677 case '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
678 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
679 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
680 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
681 case '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
682 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
683 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
684 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
685 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
686 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
687 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
688 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
689 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
690 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
691 case '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
692 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
693 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
694 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
695 case '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
696 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
697 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
698 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
699 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
700
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
701 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
702 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
703 }