annotate src/pop3/commands.c @ 2006:e97b7b1b2a1e HEAD

Message deletion deleted wrong messages
author Timo Sirainen <tss@iki.fi>
date Mon, 10 May 2004 22:00:36 +0300
parents 77f3111f7976
children 0a1755f79392
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"
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #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
8 #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
9 #include "mail-search.h"
1059
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
10 #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
11 #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
12
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #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
14 ((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
15
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 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
17 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
18 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 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
20
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 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
22 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
23 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
24 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
25 "-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
26 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
27 }
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 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
30 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
31 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
32 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
33 "-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
34 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
35 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 args++;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
39 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
40 client_send_line(client,
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
41 "-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
42 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
43 }
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
44 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
45
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 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
47 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
48 (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
49 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
50 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
51 }
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 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
55
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 *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
57 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
58 }
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 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
61 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
62 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 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
64
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 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
66 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
67 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
68 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
69 args);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 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
71 }
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 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
74 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
75 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
76 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
77 args);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 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
79 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 args++;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 }
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 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
84
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 *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
86 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
87 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88
1059
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
89 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
90 {
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
91 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
92 return TRUE;
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
93 }
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
94
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
95 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
96 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 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
98
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 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
100 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
101
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 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
103 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
104 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
105 }
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 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
108 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
109 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
110 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
111 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
112 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
114 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
115 {
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
116 unsigned int i;
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
117
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 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
119 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
120 client->messages_count - client->deleted_count);
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
121 for (i = 0; i < client->messages_count; i++) {
1994
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
122 if (client->deleted) {
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
123 if (client->deleted_bitmask[i / CHAR_BIT] &
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
124 (1 << (i % CHAR_BIT)))
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
125 continue;
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
126 }
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
127 client_send_line(client, "%u %"PRIuUOFF_T,
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
128 i+1, client->message_sizes[i]);
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
129 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 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
131 } else {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 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
133
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
134 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
135 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
136
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
137 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
138 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
139 }
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
140
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
141 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
142 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
144 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
145 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 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
147 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
148 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
150 static int expunge_mails(struct client *client, struct mailbox *box)
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 {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
152 struct mail_search_arg search_arg;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
153 struct mailbox_transaction_context *t;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
154 struct mail_search_context *ctx;
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
155 struct mail *mail;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
156 uint32_t i;
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
157 int failed = 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
158
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
159 memset(&search_arg, 0, sizeof(search_arg));
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
160 search_arg.type = SEARCH_ALL;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
161
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
162 t = mailbox_transaction_begin(box, FALSE);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
163 ctx = mailbox_search_init(t, NULL, &search_arg, NULL,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
164 MAIL_FETCH_SIZE, NULL);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
165 if (ctx == NULL) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
166 mailbox_transaction_rollback(t);
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
167 return FALSE;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
168 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
170 while ((mail = mailbox_search_next(ctx)) != NULL) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
171 i = mail->seq-1;
2006
e97b7b1b2a1e Message deletion deleted wrong messages
Timo Sirainen <tss@iki.fi>
parents: 1994
diff changeset
172 if ((client->deleted_bitmask[i / CHAR_BIT] &
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
173 (1 << (i % CHAR_BIT))) != 0) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
174 if (mail->expunge(mail) < 0) {
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
175 failed = TRUE;
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
176 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
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 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
181 if (mailbox_search_deinit(ctx) < 0)
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
182 return FALSE;
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
183
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
184 mailbox_transaction_commit(t);
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
185 return !failed;
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
186 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
188 static int cmd_quit(struct client *client, const char *args __attr_unused__)
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
189 {
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
190 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
191 client_send_line(client, "+OK Logging out.");
1640
db14aa8e2b5c API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents: 1507
diff changeset
192 else if (expunge_mails(client, client->mailbox))
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 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
194 else
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 client_send_storage_error(client);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 client_disconnect(client);
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
198 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
199 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
201 static void stream_send_escaped(struct ostream *output, struct istream *input,
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
202 uoff_t body_lines)
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
203 {
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
204 const unsigned char *data;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
205 unsigned char last, add;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
206 size_t i, size;
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
207 int cr_skipped, in_header;
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
208
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
209 if (body_lines != (uoff_t)-1)
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
210 body_lines++; /* internally we count the empty line too */
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
211
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
212 cr_skipped = FALSE; in_header = TRUE; last = '\0';
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
213 while ((body_lines > 0 || in_header) &&
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
214 i_stream_read_data(input, &data, &size, 0) > 0) {
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
215 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
216 for (i = 0; i < size; i++) {
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
217 if (in_header && (data[i] == '\r' || data[i] == '\n')) {
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
218 if (i == 0 && (last == '\0' || last == '\n'))
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
219 in_header = FALSE;
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
220 else if (i > 0 && data[i-1] == '\n')
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
221 in_header = FALSE;
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
222 }
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
223
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
224 if (data[i] == '\n') {
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
225 if ((i == 0 && last != '\r') ||
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
226 (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
227 /* 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
228 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
229 break;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
230 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
231
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
232 if (!in_header) {
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
233 if (--body_lines == 0) {
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
234 i++;
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
235 break;
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
236 }
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
237 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
238 } else if (data[i] == '.' &&
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
239 ((i == 0 && last == '\n') ||
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
240 (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
241 /* 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
242 add = '.';
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
243 i++;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
244 break;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
245 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
246 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
247
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
248 if (o_stream_send(output, data, i) < 0)
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
249 return;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
250
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
251 if (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
252 if (o_stream_send(output, &add, 1) < 0)
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
253 return;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
254 last = add;
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
255 } else {
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
256 last = data[i-1];
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
257 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
258
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
259 i_stream_skip(input, i);
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
260 }
1507
1fad8b3d7ef1 If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents: 1071
diff changeset
261
1fad8b3d7ef1 If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents: 1071
diff changeset
262 if (last != '\n') {
1fad8b3d7ef1 If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents: 1071
diff changeset
263 /* didn't end with CRLF */
1fad8b3d7ef1 If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents: 1071
diff changeset
264 (void)o_stream_send(output, "\r\n", 2);
1fad8b3d7ef1 If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents: 1071
diff changeset
265 }
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
266 }
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
267
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
268 static void fetch(struct client *client, unsigned int msgnum,
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
269 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
270 {
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
271 struct mail_search_arg search_arg;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
272 struct mail_search_seqset seqset;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
273 struct mailbox_transaction_context *t;
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
274 struct mail_search_context *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
275 struct mail *mail;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 struct istream *stream;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277
1950
c4d246aad338 crashfix
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
278 memset(&seqset, 0, sizeof(seqset));
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
279 seqset.seq1 = seqset.seq2 = msgnum+1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
280
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
281 memset(&search_arg, 0, sizeof(search_arg));
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
282 search_arg.type = SEARCH_SEQSET;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
283 search_arg.value.seqset = &seqset;
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
284
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
285 t = mailbox_transaction_begin(client->mailbox, FALSE);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
286 ctx = mailbox_search_init(t, NULL, &search_arg, NULL,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
287 MAIL_FETCH_STREAM_HEADER |
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
288 MAIL_FETCH_STREAM_BODY, 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
289 if (ctx == NULL) {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
290 mailbox_transaction_rollback(t);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 client_send_storage_error(client);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292 return;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
294
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
295 mail = mailbox_search_next(ctx);
1071
d71e0aa00d75 Don't crash if we couldn't open message.
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
296 stream = mail == NULL ? NULL : mail->get_stream(mail, NULL, NULL);
d71e0aa00d75 Don't crash if we couldn't open message.
Timo Sirainen <tss@iki.fi>
parents: 1059
diff changeset
297 if (stream == 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
298 client_send_line(client, "-ERR Message not found.");
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299 else {
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
300 if (body_lines == (uoff_t)-1) {
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
301 client_send_line(client, "+OK %"PRIuUOFF_T" octets",
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
302 client->message_sizes[msgnum]);
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
303 } else {
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
304 client_send_line(client, "+OK");
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
305 }
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306
1051
5c76c96f745f bugfixes
Timo Sirainen <tss@iki.fi>
parents: 1045
diff changeset
307 stream_send_escaped(client->output, stream, body_lines);
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
308 client_send_line(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
309 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
311 (void)mailbox_search_deinit(ctx);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
312 (void)mailbox_transaction_commit(t);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
315 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
316 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317 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
318
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
319 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
320 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
321
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
322 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
323 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
324 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
326 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
327 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
328 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
329 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
330 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
331 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
332 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
333 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 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
336 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
337 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
339 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
340 {
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
341 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
342 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
343 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
344 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
345 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
347 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
348 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
349 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
350 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
351
1045
be7710b9a819 Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents: 1044
diff changeset
352 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
353 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
354 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
355 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
356 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
357
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
358 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
359 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
360 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
362 static void list_uids(struct client *client, unsigned int message)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
363 {
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
364 struct mail_search_arg search_arg;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
365 struct mail_search_seqset seqset;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
366 struct mailbox_transaction_context *t;
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
367 struct mail_search_context *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
368 struct mail *mail;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
369 int found = FALSE;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 if (client->messages_count == 0 && message == 0)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 return;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
374 memset(&search_arg, 0, sizeof(search_arg));
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
375 if (message == 0)
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
376 search_arg.type = SEARCH_ALL;
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
377 else {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
378 seqset.seq1 = seqset.seq2 = message;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
379 search_arg.type = SEARCH_SEQSET;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
380 search_arg.value.seqset = &seqset;
1845
bd8b6ed35327 Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
381 }
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
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
383 t = mailbox_transaction_begin(client->mailbox, FALSE);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
384 ctx = mailbox_search_init(t, NULL, &search_arg, NULL, 0, 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
385 if (ctx == NULL) {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
386 mailbox_transaction_rollback(t);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 client_send_storage_error(client);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388 return;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
391 while ((mail = mailbox_search_next(ctx)) != NULL) {
1994
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
392 if (client->deleted) {
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
393 uint32_t idx = mail->seq - 1;
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
394 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
395 (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
396 continue;
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
397 }
77f3111f7976 Fixes to commands after mails have been deleted. Patch by Nic Bellamy.
Timo Sirainen <tss@iki.fi>
parents: 1950
diff changeset
398
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399 client_send_line(client, message == 0 ?
1044
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
400 "%u %u.%u" : "+OK %u %u.%u",
50d258907c99 Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents: 1043
diff changeset
401 mail->seq, client->uidvalidity, mail->uid);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402 found = TRUE;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
403 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
405 (void)mailbox_search_deinit(ctx);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
406 (void)mailbox_transaction_commit(t);
1043
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
407
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
408 if (!found && message != 0)
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409 client_send_line(client, "-ERR Message not found.");
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
412 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
413 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414 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
415 client_send_line(client, "+OK");
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416 list_uids(client, 0);
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417 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
418 } else {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
419 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
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 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
422 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
423
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
424 list_uids(client, msgnum+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
425 }
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
426
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
427 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
428 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
429
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
430 int client_command_execute(struct client *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
431 const char *name, 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
432 {
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 /* keep the command uppercased */
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434 name = str_ucase(t_strdup_noconst(name));
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 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
437
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 switch (*name) {
1059
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
439 case 'C':
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
440 if (strcmp(name, "CAPA") == 0)
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
441 return cmd_capa(client, args);
d805c2f1d6a9 Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents: 1056
diff changeset
442 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
443 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
444 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
445 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
446 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447 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
448 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
449 return cmd_list(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
450 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451 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
452 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
453 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
454 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 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
456 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
457 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
458 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459 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
460 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
461 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
462 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
463 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
464 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 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
466 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
467 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
468 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469 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
470 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
471 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
472 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 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
474 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
475 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
476 break;
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477 }
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478
cacabd33c68a Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 client_send_line(client, "-ERR Unknown command: %s", name);
1056
a9b499b2611e Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents: 1051
diff changeset
480 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
481 }