pop3d: cleanup
* pop3d/pop3d.h: Include filter.h. (istream, ostream): New externs. * pop3d/extra.c (pop3d_setio): Set a crlf filter on the output stream. This allows to forget about \r in the rest of the code. * pop3d/retr.c (pop3d_retr): Use mu_stream_copy instead of copying streams manually. * pop3d/top.c (pop3d_top): Rewrite using streamrefs and mu_stream_copy. * all sources: Use \n instead of \r\n in output strings.
Showing
16 changed files
with
79 additions
and
124 deletions
... | @@ -35,30 +35,30 @@ pop3d_capa (char *arg) | ... | @@ -35,30 +35,30 @@ pop3d_capa (char *arg) |
35 | if (state != initial_state && state != TRANSACTION) | 35 | if (state != initial_state && state != TRANSACTION) |
36 | return ERR_WRONG_STATE; | 36 | return ERR_WRONG_STATE; |
37 | 37 | ||
38 | pop3d_outf ("+OK Capability list follows\r\n"); | 38 | pop3d_outf ("+OK Capability list follows\n"); |
39 | pop3d_outf ("TOP\r\n"); | 39 | pop3d_outf ("TOP\n"); |
40 | pop3d_outf ("USER\r\n"); | 40 | pop3d_outf ("USER\n"); |
41 | pop3d_outf ("UIDL\r\n"); | 41 | pop3d_outf ("UIDL\n"); |
42 | pop3d_outf ("RESP-CODES\r\n"); | 42 | pop3d_outf ("RESP-CODES\n"); |
43 | pop3d_outf ("PIPELINING\r\n"); | 43 | pop3d_outf ("PIPELINING\n"); |
44 | 44 | ||
45 | #ifdef WITH_TLS | 45 | #ifdef WITH_TLS |
46 | if (tls_available && tls_done == 0) | 46 | if (tls_available && tls_done == 0) |
47 | pop3d_outf ("STLS\r\n"); | 47 | pop3d_outf ("STLS\n"); |
48 | #endif /* WITH_TLS */ | 48 | #endif /* WITH_TLS */ |
49 | 49 | ||
50 | login_delay_capa (); | 50 | login_delay_capa (); |
51 | /* This can be implemented by setting an header field on the message. */ | 51 | /* This can be implemented by setting an header field on the message. */ |
52 | if (expire == EXPIRE_NEVER) | 52 | if (expire == EXPIRE_NEVER) |
53 | pop3d_outf ("EXPIRE NEVER\r\n"); | 53 | pop3d_outf ("EXPIRE NEVER\n"); |
54 | else | 54 | else |
55 | pop3d_outf ("EXPIRE %s\r\n", mu_umaxtostr (0, expire)); | 55 | pop3d_outf ("EXPIRE %s\n", mu_umaxtostr (0, expire)); |
56 | 56 | ||
57 | if (state == INITIAL) | 57 | if (state == INITIAL) |
58 | pop3d_outf ("XTLSREQUIRED\r\n"); | 58 | pop3d_outf ("XTLSREQUIRED\n"); |
59 | 59 | ||
60 | if (state == TRANSACTION) /* let's not advertise to just anyone */ | 60 | if (state == TRANSACTION) /* let's not advertise to just anyone */ |
61 | pop3d_outf ("IMPLEMENTATION %s\r\n", PACKAGE_STRING); | 61 | pop3d_outf ("IMPLEMENTATION %s\n", PACKAGE_STRING); |
62 | pop3d_outf (".\r\n"); | 62 | pop3d_outf (".\n"); |
63 | return OK; | 63 | return OK; |
64 | } | 64 | } | ... | ... |
... | @@ -39,6 +39,6 @@ pop3d_dele (char *arg) | ... | @@ -39,6 +39,6 @@ pop3d_dele (char *arg) |
39 | 39 | ||
40 | mu_message_get_attribute (msg, &attr); | 40 | mu_message_get_attribute (msg, &attr); |
41 | pop3d_mark_deleted (attr); | 41 | pop3d_mark_deleted (attr); |
42 | pop3d_outf ("+OK Message %s marked\r\n", mu_umaxtostr (0, num)); | 42 | pop3d_outf ("+OK Message %s marked\n", mu_umaxtostr (0, num)); |
43 | return OK; | 43 | return OK; |
44 | } | 44 | } | ... | ... |
... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
20 | #include "pop3d.h" | 20 | #include "pop3d.h" |
21 | #include "mailutils/libargp.h" | 21 | #include "mailutils/libargp.h" |
22 | 22 | ||
23 | static mu_stream_t istream, ostream; | 23 | mu_stream_t istream, ostream; |
24 | 24 | ||
25 | void | 25 | void |
26 | pop3d_parse_command (char *cmd, char **pcmd, char **parg) | 26 | pop3d_parse_command (char *cmd, char **pcmd, char **parg) |
... | @@ -61,7 +61,7 @@ pop3d_abquit (int reason) | ... | @@ -61,7 +61,7 @@ pop3d_abquit (int reason) |
61 | { | 61 | { |
62 | case ERR_NO_MEM: | 62 | case ERR_NO_MEM: |
63 | code = EX_SOFTWARE; | 63 | code = EX_SOFTWARE; |
64 | pop3d_outf ("-ERR %s\r\n", pop3d_error_string (reason)); | 64 | pop3d_outf ("-ERR %s\n", pop3d_error_string (reason)); |
65 | mu_diag_output (MU_DIAG_ERROR, _("not enough memory")); | 65 | mu_diag_output (MU_DIAG_ERROR, _("not enough memory")); |
66 | break; | 66 | break; |
67 | 67 | ||
... | @@ -77,7 +77,7 @@ pop3d_abquit (int reason) | ... | @@ -77,7 +77,7 @@ pop3d_abquit (int reason) |
77 | 77 | ||
78 | case ERR_TIMEOUT: | 78 | case ERR_TIMEOUT: |
79 | code = EX_TEMPFAIL; | 79 | code = EX_TEMPFAIL; |
80 | pop3d_outf ("-ERR %s\r\n", pop3d_error_string (reason)); | 80 | pop3d_outf ("-ERR %s\n", pop3d_error_string (reason)); |
81 | if (state == TRANSACTION) | 81 | if (state == TRANSACTION) |
82 | mu_diag_output (MU_DIAG_INFO, _("session timed out for user: %s"), | 82 | mu_diag_output (MU_DIAG_INFO, _("session timed out for user: %s"), |
83 | username); | 83 | username); |
... | @@ -111,12 +111,12 @@ pop3d_abquit (int reason) | ... | @@ -111,12 +111,12 @@ pop3d_abquit (int reason) |
111 | _("mailbox was updated by other party: %s"), | 111 | _("mailbox was updated by other party: %s"), |
112 | username); | 112 | username); |
113 | pop3d_outf | 113 | pop3d_outf |
114 | ("-ERR [OUT-SYNC] Mailbox updated by other party or corrupt\r\n"); | 114 | ("-ERR [OUT-SYNC] Mailbox updated by other party or corrupt\n"); |
115 | break; | 115 | break; |
116 | 116 | ||
117 | default: | 117 | default: |
118 | code = EX_SOFTWARE; | 118 | code = EX_SOFTWARE; |
119 | pop3d_outf ("-ERR Quitting: %s\r\n", pop3d_error_string (reason)); | 119 | pop3d_outf ("-ERR Quitting: %s\n", pop3d_error_string (reason)); |
120 | mu_diag_output (MU_DIAG_ERROR, _("quitting (numeric reason %d)"), | 120 | mu_diag_output (MU_DIAG_ERROR, _("quitting (numeric reason %d)"), |
121 | reason); | 121 | reason); |
122 | break; | 122 | break; |
... | @@ -129,6 +129,8 @@ pop3d_abquit (int reason) | ... | @@ -129,6 +129,8 @@ pop3d_abquit (int reason) |
129 | void | 129 | void |
130 | pop3d_setio (FILE *in, FILE *out) | 130 | pop3d_setio (FILE *in, FILE *out) |
131 | { | 131 | { |
132 | mu_stream_t str; | ||
133 | |||
132 | if (!in) | 134 | if (!in) |
133 | pop3d_abquit (ERR_NO_IFILE); | 135 | pop3d_abquit (ERR_NO_IFILE); |
134 | if (!out) | 136 | if (!out) |
... | @@ -136,9 +138,13 @@ pop3d_setio (FILE *in, FILE *out) | ... | @@ -136,9 +138,13 @@ pop3d_setio (FILE *in, FILE *out) |
136 | 138 | ||
137 | if (mu_stdio_stream_create (&istream, fileno (in), MU_STREAM_NO_CLOSE)) | 139 | if (mu_stdio_stream_create (&istream, fileno (in), MU_STREAM_NO_CLOSE)) |
138 | pop3d_abquit (ERR_NO_IFILE); | 140 | pop3d_abquit (ERR_NO_IFILE); |
139 | if (mu_stdio_stream_create (&ostream, fileno (out), MU_STREAM_NO_CLOSE)) | ||
140 | pop3d_abquit (ERR_NO_OFILE); | ||
141 | mu_stream_set_buffer (istream, mu_buffer_line, 1024); | 141 | mu_stream_set_buffer (istream, mu_buffer_line, 1024); |
142 | |||
143 | if (mu_stdio_stream_create (&str, fileno (out), MU_STREAM_NO_CLOSE)) | ||
144 | pop3d_abquit (ERR_NO_OFILE); | ||
145 | if (mu_filter_create (&ostream, str, "rfc822", MU_FILTER_ENCODE, | ||
146 | MU_STREAM_WRITE|MU_STREAM_NO_CLOSE)) | ||
147 | pop3d_abquit (ERR_NO_IFILE); | ||
142 | mu_stream_set_buffer (ostream, mu_buffer_line, 1024); | 148 | mu_stream_set_buffer (ostream, mu_buffer_line, 1024); |
143 | } | 149 | } |
144 | 150 | ... | ... |
... | @@ -37,7 +37,7 @@ pop3d_list (char *arg) | ... | @@ -37,7 +37,7 @@ pop3d_list (char *arg) |
37 | if (strlen (arg) == 0) | 37 | if (strlen (arg) == 0) |
38 | { | 38 | { |
39 | size_t total = 0; | 39 | size_t total = 0; |
40 | pop3d_outf ("+OK\r\n"); | 40 | pop3d_outf ("+OK\n"); |
41 | mu_mailbox_messages_count (mbox, &total); | 41 | mu_mailbox_messages_count (mbox, &total); |
42 | for (mesgno = 1; mesgno <= total; mesgno++) | 42 | for (mesgno = 1; mesgno <= total; mesgno++) |
43 | { | 43 | { |
... | @@ -47,12 +47,12 @@ pop3d_list (char *arg) | ... | @@ -47,12 +47,12 @@ pop3d_list (char *arg) |
47 | { | 47 | { |
48 | mu_message_size (msg, &size); | 48 | mu_message_size (msg, &size); |
49 | mu_message_lines (msg, &lines); | 49 | mu_message_lines (msg, &lines); |
50 | pop3d_outf ("%s %s\r\n", | 50 | pop3d_outf ("%s %s\n", |
51 | mu_umaxtostr (0, mesgno), | 51 | mu_umaxtostr (0, mesgno), |
52 | mu_umaxtostr (1, size + lines)); | 52 | mu_umaxtostr (1, size + lines)); |
53 | } | 53 | } |
54 | } | 54 | } |
55 | pop3d_outf (".\r\n"); | 55 | pop3d_outf (".\n"); |
56 | } | 56 | } |
57 | else | 57 | else |
58 | { | 58 | { |
... | @@ -64,7 +64,7 @@ pop3d_list (char *arg) | ... | @@ -64,7 +64,7 @@ pop3d_list (char *arg) |
64 | return ERR_MESG_DELE; | 64 | return ERR_MESG_DELE; |
65 | mu_message_size (msg, &size); | 65 | mu_message_size (msg, &size); |
66 | mu_message_lines (msg, &lines); | 66 | mu_message_lines (msg, &lines); |
67 | pop3d_outf ("+OK %s %s\r\n", | 67 | pop3d_outf ("+OK %s %s\n", |
68 | mu_umaxtostr (0, mesgno), | 68 | mu_umaxtostr (0, mesgno), |
69 | mu_umaxtostr (1, size + lines)); | 69 | mu_umaxtostr (1, size + lines)); |
70 | } | 70 | } | ... | ... |
... | @@ -126,7 +126,7 @@ login_delay_capa () | ... | @@ -126,7 +126,7 @@ login_delay_capa () |
126 | 126 | ||
127 | if (login_delay && open_stat_db (&db, MU_STREAM_RDWR) == 0) | 127 | if (login_delay && open_stat_db (&db, MU_STREAM_RDWR) == 0) |
128 | { | 128 | { |
129 | pop3d_outf ("LOGIN-DELAY %s\r\n", mu_umaxtostr (0, login_delay)); | 129 | pop3d_outf ("LOGIN-DELAY %s\n", mu_umaxtostr (0, login_delay)); |
130 | mu_dbm_close (db); | 130 | mu_dbm_close (db); |
131 | } | 131 | } |
132 | } | 132 | } | ... | ... |
... | @@ -26,6 +26,6 @@ pop3d_noop (char *arg) | ... | @@ -26,6 +26,6 @@ pop3d_noop (char *arg) |
26 | return ERR_BAD_ARGS; | 26 | return ERR_BAD_ARGS; |
27 | if (state != TRANSACTION) | 27 | if (state != TRANSACTION) |
28 | return ERR_WRONG_STATE; | 28 | return ERR_WRONG_STATE; |
29 | pop3d_outf ("+OK\r\n"); | 29 | pop3d_outf ("+OK\n"); |
30 | return OK; | 30 | return OK; |
31 | } | 31 | } | ... | ... |
... | @@ -248,7 +248,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) | ... | @@ -248,7 +248,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) |
248 | } | 248 | } |
249 | 249 | ||
250 | /* Lets boogie. */ | 250 | /* Lets boogie. */ |
251 | pop3d_outf ("+OK POP3 Ready %s\r\n", md5shared); | 251 | pop3d_outf ("+OK POP3 Ready %s\n", md5shared); |
252 | 252 | ||
253 | while (state != UPDATE && state != ABORT) | 253 | while (state != UPDATE && state != ABORT) |
254 | { | 254 | { |
... | @@ -291,7 +291,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) | ... | @@ -291,7 +291,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) |
291 | status = ERR_BAD_CMD; | 291 | status = ERR_BAD_CMD; |
292 | 292 | ||
293 | if (status != OK) | 293 | if (status != OK) |
294 | pop3d_outf ("-ERR %s\r\n", pop3d_error_string (status)); | 294 | pop3d_outf ("-ERR %s\n", pop3d_error_string (status)); |
295 | } | 295 | } |
296 | 296 | ||
297 | pop3d_bye (); | 297 | pop3d_bye (); | ... | ... |
... | @@ -125,6 +125,7 @@ extern int expire_on_exit; | ... | @@ -125,6 +125,7 @@ extern int expire_on_exit; |
125 | #include <mailutils/md5.h> | 125 | #include <mailutils/md5.h> |
126 | #include <mailutils/acl.h> | 126 | #include <mailutils/acl.h> |
127 | #include <mailutils/server.h> | 127 | #include <mailutils/server.h> |
128 | #include <mailutils/filter.h> | ||
128 | 129 | ||
129 | /* For Berkley DB2 APOP password file */ | 130 | /* For Berkley DB2 APOP password file */ |
130 | #ifdef HAVE_DB_H | 131 | #ifdef HAVE_DB_H |
... | @@ -188,6 +189,7 @@ struct pop3d_command | ... | @@ -188,6 +189,7 @@ struct pop3d_command |
188 | pop3d_command_handler_t handler; | 189 | pop3d_command_handler_t handler; |
189 | }; | 190 | }; |
190 | 191 | ||
192 | extern mu_stream_t istream, ostream; | ||
191 | extern mu_pop_server_t pop3srv; | 193 | extern mu_pop_server_t pop3srv; |
192 | extern mu_mailbox_t mbox; | 194 | extern mu_mailbox_t mbox; |
193 | extern int state; | 195 | extern int state; | ... | ... |
... | @@ -22,12 +22,10 @@ | ... | @@ -22,12 +22,10 @@ |
22 | int | 22 | int |
23 | pop3d_retr (char *arg) | 23 | pop3d_retr (char *arg) |
24 | { | 24 | { |
25 | size_t mesgno, n; | 25 | size_t mesgno; |
26 | char buf[BUFFERSIZE]; | ||
27 | mu_message_t msg = NULL; | 26 | mu_message_t msg = NULL; |
28 | mu_attribute_t attr = NULL; | 27 | mu_attribute_t attr = NULL; |
29 | mu_stream_t stream = NULL; | 28 | mu_stream_t stream; |
30 | int prev_nl; | ||
31 | 29 | ||
32 | if ((strlen (arg) == 0) || (strchr (arg, ' ') != NULL)) | 30 | if ((strlen (arg) == 0) || (strchr (arg, ' ') != NULL)) |
33 | return ERR_BAD_ARGS; | 31 | return ERR_BAD_ARGS; |
... | @@ -44,42 +42,19 @@ pop3d_retr (char *arg) | ... | @@ -44,42 +42,19 @@ pop3d_retr (char *arg) |
44 | if (pop3d_is_deleted (attr)) | 42 | if (pop3d_is_deleted (attr)) |
45 | return ERR_MESG_DELE; | 43 | return ERR_MESG_DELE; |
46 | 44 | ||
47 | /* FIXME: Use crlf filter + mu_stream_copy instead of the loop below */ | 45 | if (mu_message_get_streamref (msg, &stream)) |
48 | if (mu_message_get_stream (msg, &stream) | ||
49 | || mu_stream_seek (stream, 0, MU_SEEK_SET, NULL)) | ||
50 | return ERR_UNKNOWN; | 46 | return ERR_UNKNOWN; |
51 | 47 | ||
52 | pop3d_outf ("+OK\r\n"); | 48 | pop3d_outf ("+OK\n"); |
53 | 49 | mu_stream_copy (ostream, stream, 0); | |
54 | prev_nl = 1; | 50 | mu_stream_destroy (&stream); |
55 | while (mu_stream_readline (stream, buf, sizeof(buf), &n) == 0 | ||
56 | && n > 0) | ||
57 | { | ||
58 | if (prev_nl && buf[0] == '.') | ||
59 | pop3d_outf ("."); | ||
60 | |||
61 | if (buf[n - 1] == '\n') | ||
62 | { | ||
63 | buf[n - 1] = '\0'; | ||
64 | pop3d_outf ("%s\r\n", buf); | ||
65 | prev_nl = 1; | ||
66 | } | ||
67 | else | ||
68 | { | ||
69 | pop3d_outf ("%s", buf); | ||
70 | prev_nl = 0; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | if (!prev_nl) | ||
75 | pop3d_outf ("\r\n"); | ||
76 | 51 | ||
77 | if (!mu_attribute_is_read (attr)) | 52 | if (!mu_attribute_is_read (attr)) |
78 | mu_attribute_set_read (attr); | 53 | mu_attribute_set_read (attr); |
79 | 54 | ||
80 | pop3d_mark_retr (attr); | 55 | pop3d_mark_retr (attr); |
81 | 56 | ||
82 | pop3d_outf (".\r\n"); | 57 | pop3d_outf (".\n"); |
83 | 58 | ||
84 | return OK; | 59 | return OK; |
85 | } | 60 | } | ... | ... |
... | @@ -41,6 +41,6 @@ pop3d_rset (char *arg) | ... | @@ -41,6 +41,6 @@ pop3d_rset (char *arg) |
41 | mu_message_get_attribute (msg, &attr); | 41 | mu_message_get_attribute (msg, &attr); |
42 | pop3d_unset_deleted (attr); | 42 | pop3d_unset_deleted (attr); |
43 | } | 43 | } |
44 | pop3d_outf ("+OK\r\n"); | 44 | pop3d_outf ("+OK\n"); |
45 | return OK; | 45 | return OK; |
46 | } | 46 | } | ... | ... |
... | @@ -57,7 +57,7 @@ pop3d_stat (char *arg) | ... | @@ -57,7 +57,7 @@ pop3d_stat (char *arg) |
57 | num++; | 57 | num++; |
58 | } | 58 | } |
59 | } | 59 | } |
60 | pop3d_outf ("+OK %s %s\r\n", mu_umaxtostr (0, num), mu_umaxtostr (1, tsize)); | 60 | pop3d_outf ("+OK %s %s\n", mu_umaxtostr (0, num), mu_umaxtostr (1, tsize)); |
61 | 61 | ||
62 | return OK; | 62 | return OK; |
63 | } | 63 | } | ... | ... |
... | @@ -32,7 +32,7 @@ pop3d_stls (char *arg) | ... | @@ -32,7 +32,7 @@ pop3d_stls (char *arg) |
32 | if (tls_done) | 32 | if (tls_done) |
33 | return ERR_TLS_ACTIVE; | 33 | return ERR_TLS_ACTIVE; |
34 | 34 | ||
35 | pop3d_outf ("+OK Begin TLS negotiation\r\n"); | 35 | pop3d_outf ("+OK Begin TLS negotiation\n"); |
36 | pop3d_flush_output (); | 36 | pop3d_flush_output (); |
37 | 37 | ||
38 | tls_done = pop3d_init_tls_server (); | 38 | tls_done = pop3d_init_tls_server (); | ... | ... |
... | @@ -23,15 +23,13 @@ int | ... | @@ -23,15 +23,13 @@ int |
23 | pop3d_top (char *arg) | 23 | pop3d_top (char *arg) |
24 | { | 24 | { |
25 | size_t mesgno; | 25 | size_t mesgno; |
26 | int lines; | 26 | unsigned long lines; |
27 | mu_message_t msg; | 27 | mu_message_t msg; |
28 | mu_attribute_t attr; | 28 | mu_attribute_t attr; |
29 | mu_header_t hdr; | 29 | mu_header_t hdr; |
30 | mu_body_t body; | 30 | mu_body_t body; |
31 | mu_stream_t stream; | 31 | mu_stream_t stream; |
32 | char *mesgc, *linesc; | 32 | char *mesgc, *linesc, *p; |
33 | char buf[BUFFERSIZE]; | ||
34 | size_t n; | ||
35 | 33 | ||
36 | if (strlen (arg) == 0) | 34 | if (strlen (arg) == 0) |
37 | return ERR_BAD_ARGS; | 35 | return ERR_BAD_ARGS; |
... | @@ -40,11 +38,14 @@ pop3d_top (char *arg) | ... | @@ -40,11 +38,14 @@ pop3d_top (char *arg) |
40 | return ERR_WRONG_STATE; | 38 | return ERR_WRONG_STATE; |
41 | 39 | ||
42 | pop3d_parse_command (arg, &mesgc, &linesc); | 40 | pop3d_parse_command (arg, &mesgc, &linesc); |
41 | if (linesc[0] == 0) | ||
42 | return ERR_BAD_ARGS; | ||
43 | 43 | ||
44 | mesgno = strtoul (mesgc, NULL, 10); | 44 | mesgno = strtoul (mesgc, &p, 10); |
45 | lines = *linesc ? strtol (linesc, NULL, 10) : -1; | 45 | if (*p) |
46 | 46 | return ERR_BAD_ARGS; | |
47 | if (lines < 0) | 47 | lines = strtoul (linesc, &p, 10); |
48 | if (*p) | ||
48 | return ERR_BAD_ARGS; | 49 | return ERR_BAD_ARGS; |
49 | 50 | ||
50 | if (mu_mailbox_get_message (mbox, mesgno, &msg) != 0) | 51 | if (mu_mailbox_get_message (mbox, mesgno, &msg) != 0) |
... | @@ -55,63 +56,34 @@ pop3d_top (char *arg) | ... | @@ -55,63 +56,34 @@ pop3d_top (char *arg) |
55 | return ERR_MESG_DELE; | 56 | return ERR_MESG_DELE; |
56 | pop3d_mark_retr (attr); | 57 | pop3d_mark_retr (attr); |
57 | 58 | ||
58 | pop3d_outf ("+OK\r\n"); | ||
59 | |||
60 | /* Header. */ | 59 | /* Header. */ |
61 | mu_message_get_header (msg, &hdr); | 60 | mu_message_get_header (msg, &hdr); |
62 | /* FIXME: Use crlf filter + mu_stream_copy instead of the below loop */ | 61 | if (mu_header_get_streamref (hdr, &stream)) |
63 | if (mu_header_get_stream (hdr, &stream) | ||
64 | || mu_stream_seek (stream, 0, MU_SEEK_SET, NULL)) | ||
65 | return ERR_UNKNOWN; | 62 | return ERR_UNKNOWN; |
66 | n = 0; | 63 | pop3d_outf ("+OK\n"); |
67 | while (mu_stream_readline (stream, buf, sizeof(buf), &n) == 0 | ||
68 | && n > 0) | ||
69 | { | ||
70 | /* Nuke the trainline newline. */ | ||
71 | if (buf[n - 1] == '\n') | ||
72 | { | ||
73 | buf[n - 1] = '\0'; | ||
74 | pop3d_outf ("%s\r\n", buf); | ||
75 | } | ||
76 | else | ||
77 | pop3d_outf ("%s", buf); | ||
78 | } | ||
79 | 64 | ||
80 | /* Lines of body. */ | 65 | mu_stream_copy (ostream, stream, 0); |
81 | if (lines) | 66 | pop3d_outf ("\n"); |
82 | { | 67 | mu_stream_destroy (&stream); |
83 | int prev_nl = 1; | ||
84 | 68 | ||
85 | mu_message_get_body (msg, &body); | 69 | mu_message_get_body (msg, &body); |
86 | /* FIXME: Use the crlf filter + mu_stream_copy */ | 70 | if (mu_body_get_streamref (body, &stream) == 0) |
87 | if (mu_body_get_stream (body, &stream) | ||
88 | || mu_stream_seek (stream, 0, MU_SEEK_SET, NULL)) | ||
89 | return ERR_UNKNOWN; | ||
90 | n = 0; | ||
91 | while (mu_stream_readline (stream, buf, sizeof(buf), &n) == 0 | ||
92 | && n > 0 && lines > 0) | ||
93 | { | ||
94 | if (prev_nl && buf[0] == '.') | ||
95 | pop3d_outf ("."); | ||
96 | |||
97 | if (buf[n - 1] == '\n') | ||
98 | { | 71 | { |
99 | buf[n - 1] = '\0'; | 72 | char *buf = NULL; |
100 | pop3d_outf ("%s\r\n", buf); | 73 | size_t size = 0, n; |
101 | prev_nl = 1; | 74 | while (lines > 0 && |
102 | lines--; | 75 | mu_stream_getline (stream, &buf, &size, &n) == 0 && |
103 | } | 76 | n > 0) |
104 | else | ||
105 | { | 77 | { |
106 | pop3d_outf ("%s", buf); | 78 | if (buf[0] == '.') |
107 | prev_nl = 0; | 79 | pop3d_outf ("."); |
108 | } | 80 | pop3d_outf ("%s\n", buf); |
109 | } | 81 | } |
110 | if (!prev_nl) | 82 | mu_stream_destroy (&stream); |
111 | pop3d_outf ("\r\n"); | 83 | free (buf); |
112 | } | 84 | } |
113 | 85 | ||
114 | pop3d_outf (".\r\n"); | 86 | pop3d_outf (".\n"); |
115 | 87 | ||
116 | return OK; | 88 | return OK; |
117 | } | 89 | } | ... | ... |
... | @@ -34,7 +34,7 @@ pop3d_uidl (char *arg) | ... | @@ -34,7 +34,7 @@ pop3d_uidl (char *arg) |
34 | if (strlen (arg) == 0) | 34 | if (strlen (arg) == 0) |
35 | { | 35 | { |
36 | size_t total = 0; | 36 | size_t total = 0; |
37 | pop3d_outf ("+OK\r\n"); | 37 | pop3d_outf ("+OK\n"); |
38 | mu_mailbox_messages_count (mbox, &total); | 38 | mu_mailbox_messages_count (mbox, &total); |
39 | for (mesgno = 1; mesgno <= total; mesgno++) | 39 | for (mesgno = 1; mesgno <= total; mesgno++) |
40 | { | 40 | { |
... | @@ -43,10 +43,10 @@ pop3d_uidl (char *arg) | ... | @@ -43,10 +43,10 @@ pop3d_uidl (char *arg) |
43 | if (!pop3d_is_deleted (attr)) | 43 | if (!pop3d_is_deleted (attr)) |
44 | { | 44 | { |
45 | mu_message_get_uidl (msg, uidl, sizeof (uidl), NULL); | 45 | mu_message_get_uidl (msg, uidl, sizeof (uidl), NULL); |
46 | pop3d_outf ("%s %s\r\n", mu_umaxtostr (0, mesgno), uidl); | 46 | pop3d_outf ("%s %s\n", mu_umaxtostr (0, mesgno), uidl); |
47 | } | 47 | } |
48 | } | 48 | } |
49 | pop3d_outf (".\r\n"); | 49 | pop3d_outf (".\n"); |
50 | } | 50 | } |
51 | else | 51 | else |
52 | { | 52 | { |
... | @@ -57,7 +57,7 @@ pop3d_uidl (char *arg) | ... | @@ -57,7 +57,7 @@ pop3d_uidl (char *arg) |
57 | if (pop3d_is_deleted (attr)) | 57 | if (pop3d_is_deleted (attr)) |
58 | return ERR_MESG_DELE; | 58 | return ERR_MESG_DELE; |
59 | mu_message_get_uidl (msg, uidl, sizeof (uidl), NULL); | 59 | mu_message_get_uidl (msg, uidl, sizeof (uidl), NULL); |
60 | pop3d_outf ("+OK %s %s\r\n", mu_umaxtostr (0, mesgno), uidl); | 60 | pop3d_outf ("+OK %s %s\n", mu_umaxtostr (0, mesgno), uidl); |
61 | } | 61 | } |
62 | 62 | ||
63 | return OK; | 63 | return OK; | ... | ... |
... | @@ -63,7 +63,7 @@ pop3d_begin_session () | ... | @@ -63,7 +63,7 @@ pop3d_begin_session () |
63 | pop3d_abquit (ERR_NO_MEM); | 63 | pop3d_abquit (ERR_NO_MEM); |
64 | state = TRANSACTION; | 64 | state = TRANSACTION; |
65 | 65 | ||
66 | pop3d_outf ("+OK opened mailbox for %s\r\n", username); | 66 | pop3d_outf ("+OK opened mailbox for %s\n", username); |
67 | 67 | ||
68 | if (undelete_on_startup) | 68 | if (undelete_on_startup) |
69 | pop3d_undelete_all (); | 69 | pop3d_undelete_all (); |
... | @@ -98,7 +98,7 @@ pop3d_user (char *arg) | ... | @@ -98,7 +98,7 @@ pop3d_user (char *arg) |
98 | if ((strlen (arg) == 0) || (strchr (arg, ' ') != NULL)) | 98 | if ((strlen (arg) == 0) || (strchr (arg, ' ') != NULL)) |
99 | return ERR_BAD_ARGS; | 99 | return ERR_BAD_ARGS; |
100 | 100 | ||
101 | pop3d_outf ("+OK\r\n"); | 101 | pop3d_outf ("+OK\n"); |
102 | pop3d_flush_output (); | 102 | pop3d_flush_output (); |
103 | 103 | ||
104 | buf = pop3d_readline (buffer, sizeof (buffer)); | 104 | buf = pop3d_readline (buffer, sizeof (buffer)); | ... | ... |
-
Please register or sign in to post a comment