Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/pop3/commands.c @ 1950:c4d246aad338 HEAD
crashfix
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 02 May 2004 02:15:51 +0300 |
parents | 79790750c349 |
children | 77f3111f7976 |
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 | 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 | 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 | 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); |
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_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
|
109 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
|
110 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 |
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 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
|
113 { |
1044
50d258907c99
Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents:
1043
diff
changeset
|
114 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
|
115 |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 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
|
117 client_send_line(client, "+OK %u messages:", |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 client->messages_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
|
119 for (i = 0; i < client->messages_count; i++) { |
50d258907c99
Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents:
1043
diff
changeset
|
120 client_send_line(client, "%u %"PRIuUOFF_T, |
1051 | 121 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
|
122 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 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
|
124 } else { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 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
|
126 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
127 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
|
128 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
|
129 |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
130 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
|
131 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
|
132 } |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
133 |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
134 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
|
135 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
137 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
|
138 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 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
|
140 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
|
141 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 |
1640
db14aa8e2b5c
API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents:
1507
diff
changeset
|
143 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
|
144 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
145 struct mail_search_arg search_arg; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
146 struct mailbox_transaction_context *t; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
147 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
|
148 struct mail *mail; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
149 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
|
150 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
|
151 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
152 memset(&search_arg, 0, sizeof(search_arg)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
153 search_arg.type = SEARCH_ALL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
154 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
155 t = mailbox_transaction_begin(box, FALSE); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
156 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
|
157 MAIL_FETCH_SIZE, NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
158 if (ctx == NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
159 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
|
160 return FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
161 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
163 while ((mail = mailbox_search_next(ctx)) != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
164 i = mail->seq-1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
165 if ((client->deleted_bitmask[i >> CHAR_BIT] & |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
166 (1 << (i % CHAR_BIT))) != 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
167 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
|
168 failed = TRUE; |
db14aa8e2b5c
API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents:
1507
diff
changeset
|
169 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
|
170 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
174 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
|
175 return FALSE; |
db14aa8e2b5c
API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents:
1507
diff
changeset
|
176 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
177 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
|
178 return !failed; |
db14aa8e2b5c
API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents:
1507
diff
changeset
|
179 } |
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 |
1640
db14aa8e2b5c
API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents:
1507
diff
changeset
|
181 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
|
182 { |
db14aa8e2b5c
API change for expunging messages. Not exactly what I wanted, but good
Timo Sirainen <tss@iki.fi>
parents:
1507
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 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
|
187 else |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 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
|
189 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 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
|
191 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
|
192 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
194 static void stream_send_escaped(struct ostream *output, struct istream *input, |
1051 | 195 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
|
196 { |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
197 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
|
198 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
|
199 size_t i, size; |
1051 | 200 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
|
201 |
1051 | 202 if (body_lines != (uoff_t)-1) |
203 body_lines++; /* internally we count the empty line too */ | |
204 | |
205 cr_skipped = FALSE; in_header = TRUE; last = '\0'; | |
206 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
|
207 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
|
208 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
|
209 for (i = 0; i < size; i++) { |
1051 | 210 if (in_header && (data[i] == '\r' || data[i] == '\n')) { |
211 if (i == 0 && (last == '\0' || last == '\n')) | |
212 in_header = FALSE; | |
213 else if (i > 0 && data[i-1] == '\n') | |
214 in_header = FALSE; | |
215 } | |
216 | |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
217 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
|
218 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
|
219 (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
|
220 /* 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
|
221 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
|
222 break; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
223 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
224 |
1051 | 225 if (!in_header) { |
226 if (--body_lines == 0) { | |
227 i++; | |
228 break; | |
229 } | |
1045
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 } 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
|
232 ((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
|
233 (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
|
234 /* 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
|
235 add = '.'; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
236 i++; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
237 break; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
238 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
239 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
240 |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
241 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
|
242 return; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
243 |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
244 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
|
245 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
|
246 return; |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
247 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
|
248 } else { |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
249 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
|
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 |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
252 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
|
253 } |
1507
1fad8b3d7ef1
If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents:
1071
diff
changeset
|
254 |
1fad8b3d7ef1
If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents:
1071
diff
changeset
|
255 if (last != '\n') { |
1fad8b3d7ef1
If mail didn't end with linefeed, we sent it wrong.
Timo Sirainen <tss@iki.fi>
parents:
1071
diff
changeset
|
256 /* 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
|
257 (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
|
258 } |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
259 } |
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
260 |
1051 | 261 static void fetch(struct client *client, unsigned int msgnum, |
262 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
|
263 { |
1845
bd8b6ed35327
Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
264 struct mail_search_arg search_arg; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
265 struct mail_search_seqset seqset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
266 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
|
267 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
|
268 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
|
269 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
|
270 |
1950 | 271 memset(&seqset, 0, sizeof(seqset)); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
272 seqset.seq1 = seqset.seq2 = msgnum+1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
273 |
1845
bd8b6ed35327
Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
274 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
|
275 search_arg.type = SEARCH_SEQSET; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
276 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
|
277 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
278 t = mailbox_transaction_begin(client->mailbox, FALSE); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
279 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
|
280 MAIL_FETCH_STREAM_HEADER | |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
281 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
|
282 if (ctx == NULL) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
283 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
|
284 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
|
285 return; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
288 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
|
289 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
|
290 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
|
291 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
|
292 else { |
1051 | 293 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
|
294 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
|
295 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
|
296 } else { |
50d258907c99
Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents:
1043
diff
changeset
|
297 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
|
298 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 |
1051 | 300 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
|
301 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
|
302 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
304 (void)mailbox_search_deinit(ctx); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
305 (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
|
306 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
308 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
|
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 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
|
311 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
312 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
|
313 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
|
314 |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
315 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
|
316 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
|
317 } |
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 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
|
320 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 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
|
322 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
|
323 memset(client->deleted_bitmask, 0, 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
|
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 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 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
|
327 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
|
328 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
329 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
330 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
|
331 { |
1044
50d258907c99
Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents:
1043
diff
changeset
|
332 client_send_line(client, "+OK %u %"PRIuUOFF_T, client-> |
50d258907c99
Read the sizes of all messages to memory at startup. More failsafe and
Timo Sirainen <tss@iki.fi>
parents:
1043
diff
changeset
|
333 messages_count, client->total_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
|
334 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
|
335 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
337 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
|
338 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 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
|
340 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
|
341 |
1045
be7710b9a819
Fixes, seems to be working now. Only thing left is the pop3-login..
Timo Sirainen <tss@iki.fi>
parents:
1044
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
348 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
|
349 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
|
350 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
352 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
|
353 { |
1845
bd8b6ed35327
Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
354 struct mail_search_arg search_arg; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
355 struct mail_search_seqset seqset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 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
|
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 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
|
362 return; |
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 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
|
365 if (message == 0) |
bd8b6ed35327
Removed fetch_init/fetch_next from mail-storage. search_* makes it
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
366 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
|
367 else { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
368 seqset.seq1 = seqset.seq2 = message; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
369 search_arg.type = SEARCH_SEQSET; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
370 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
|
371 } |
1043
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
372 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
373 t = mailbox_transaction_begin(client->mailbox, FALSE); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
374 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
|
375 if (ctx == NULL) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
376 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
|
377 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
|
378 return; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
381 while ((mail = mailbox_search_next(ctx)) != 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
|
382 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
|
383 "%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
|
384 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
|
385 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
|
386 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
388 (void)mailbox_search_deinit(ctx); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
389 (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
|
390 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 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
|
392 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
|
393 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
395 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
|
396 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 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
|
398 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
|
399 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
|
400 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
|
401 } else { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 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
|
403 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
404 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
|
405 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
|
406 |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
407 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
|
408 } |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
409 |
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
410 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
|
411 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 |
1056
a9b499b2611e
Disconnect after too many bad commands. We also crashed if there were no
Timo Sirainen <tss@iki.fi>
parents:
1051
diff
changeset
|
413 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
|
414 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
|
415 { |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
416 /* 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
|
417 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
|
418 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
419 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
|
420 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
421 switch (*name) { |
1059
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
422 case 'C': |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
423 if (strcmp(name, "CAPA") == 0) |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
424 return cmd_capa(client, args); |
d805c2f1d6a9
Support for CAPA command (rfc2449).
Timo Sirainen <tss@iki.fi>
parents:
1056
diff
changeset
|
425 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
|
426 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
|
427 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
|
428 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
|
429 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 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
|
431 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
|
432 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
|
433 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 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
|
435 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
|
436 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
|
437 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 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
|
439 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
|
440 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
|
441 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 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
|
453 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
|
454 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
|
455 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
456 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
|
457 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
|
458 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
|
459 break; |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
460 } |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
461 |
cacabd33c68a
Initial code for POP3 server. RETR isn't working right yet, there's some
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 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
|
463 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
|
464 } |