Commit 2ba12864 2ba128641bf07c14ac430d3d2fdebc1b73dd8838 by Sergey Poznyakoff

Simplify calls to final delivery functions.

* maidag/deliver.c (mda): Pass msg as a 1st argument to deliver.
(deliver_to_user): Remove 1st argument.
(deliver): Change type of the 1st argument to mu_message_t.
* maidag/lmtp.c (dot_deliver): Pass msg as a 1st argument to
deliver.
* maidag/maidag.c (sieve_test): Change type of the 2nd argument to
mu_message_t.
* maidag/maidag.h (sieve_test, deliver): Pass mu_message_t,
instead of mu_message_t.

* mailbox/mailer.c (mu_mailer_create_from_url): Set default debug
level.
* sql/mysql.c (mu_mysql_connect): Avoid coredumps if conn->server
is NULL.
1 parent 437bd788
1 2008-11-05 Sergey Poznyakoff <gray@gnu.org.ua>
2
3 Simplify calls to final delivery functions.
4
5 * maidag/deliver.c (mda): Pass msg as a 1st argument to deliver.
6 (deliver_to_user): Remove 1st argument.
7 (deliver): Change type of the 1st argument to mu_message_t.
8 * maidag/lmtp.c (dot_deliver): Pass msg as a 1st argument to
9 deliver.
10 * maidag/maidag.c (sieve_test): Change type of the 2nd argument to
11 mu_message_t.
12 * maidag/maidag.h (sieve_test, deliver): Pass mu_message_t,
13 instead of mu_message_t.
14
15 * mailbox/mailer.c (mu_mailer_create_from_url): Set default debug
16 level.
17 * sql/mysql.c (mu_mysql_connect): Avoid coredumps if conn->server
18 is NULL.
19
1 2008-10-28 Sergey Poznyakoff <gray@gnu.org.ua> 20 2008-10-28 Sergey Poznyakoff <gray@gnu.org.ua>
2 21
3 Make maidag hanlde mailer URLs. 22 Make maidag hanlde mailer URLs.
......
...@@ -44,7 +44,17 @@ make_tmp (const char *from, mu_mailbox_t *mbox) ...@@ -44,7 +44,17 @@ make_tmp (const char *from, mu_mailbox_t *mbox)
44 int 44 int
45 mda (mu_mailbox_t mbx, char *username) 45 mda (mu_mailbox_t mbx, char *username)
46 { 46 {
47 deliver (mbx, username, NULL); 47 int status;
48 mu_message_t msg;
49
50 if ((status = mu_mailbox_get_message (mbx, 1, &msg)) != 0)
51 {
52 maidag_error (_("Cannot get message from the temporary mailbox: %s"),
53 mu_strerror (status));
54 return EX_TEMPFAIL;
55 }
56
57 deliver (msg, username, NULL);
48 58
49 if (multiple_delivery) 59 if (multiple_delivery)
50 exit_code = EX_OK; 60 exit_code = EX_OK;
...@@ -143,7 +153,7 @@ attach_notify (mu_mailbox_t mbox) ...@@ -143,7 +153,7 @@ attach_notify (mu_mailbox_t mbox)
143 } 153 }
144 154
145 int 155 int
146 deliver_to_user (mu_mailbox_t imbx, mu_mailbox_t mbox, mu_message_t msg, 156 deliver_to_user (mu_mailbox_t mbox, mu_message_t msg,
147 struct mu_auth_data *auth, 157 struct mu_auth_data *auth,
148 char **errp) 158 char **errp)
149 { 159 {
...@@ -187,7 +197,7 @@ deliver_to_user (mu_mailbox_t imbx, mu_mailbox_t mbox, mu_message_t msg, ...@@ -187,7 +197,7 @@ deliver_to_user (mu_mailbox_t imbx, mu_mailbox_t mbox, mu_message_t msg,
187 if (auth) 197 if (auth)
188 { 198 {
189 mu_off_t n; 199 mu_off_t n;
190 mu_off_t msg_size; 200 size_t msg_size;
191 mu_off_t mbsize; 201 mu_off_t mbsize;
192 202
193 if ((status = mu_mailbox_get_size (mbox, &mbsize))) 203 if ((status = mu_mailbox_get_size (mbox, &mbsize)))
...@@ -216,7 +226,7 @@ deliver_to_user (mu_mailbox_t imbx, mu_mailbox_t mbox, mu_message_t msg, ...@@ -216,7 +226,7 @@ deliver_to_user (mu_mailbox_t imbx, mu_mailbox_t mbox, mu_message_t msg,
216 break; 226 break;
217 227
218 default: 228 default:
219 if ((status = mu_mailbox_get_size (imbx, &msg_size))) 229 if ((status = mu_message_size (msg, &msg_size)))
220 { 230 {
221 maidag_error (_("Cannot get message size (input message %s): %s"), 231 maidag_error (_("Cannot get message size (input message %s): %s"),
222 path, mu_strerror (status)); 232 path, mu_strerror (status));
...@@ -292,11 +302,10 @@ is_mailer_url (mu_url_t url) ...@@ -292,11 +302,10 @@ is_mailer_url (mu_url_t url)
292 #define REMOTE_PREFIX_LEN (sizeof(REMOTE_PREFIX)-1) 302 #define REMOTE_PREFIX_LEN (sizeof(REMOTE_PREFIX)-1)
293 303
294 int 304 int
295 deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp) 305 deliver_url (mu_url_t url, mu_message_t msg, const char *name, char **errp)
296 { 306 {
297 struct mu_auth_data *auth = NULL; 307 struct mu_auth_data *auth = NULL;
298 mu_mailbox_t mbox; 308 mu_mailbox_t mbox;
299 mu_message_t msg;
300 int status; 309 int status;
301 310
302 if (name) 311 if (name)
...@@ -314,7 +323,7 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp) ...@@ -314,7 +323,7 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp)
314 if (current_uid) 323 if (current_uid)
315 auth->change_uid = 0; 324 auth->change_uid = 0;
316 325
317 if (!sieve_test (auth, imbx)) 326 if (!sieve_test (auth, msg))
318 { 327 {
319 exit_code = EX_OK; 328 exit_code = EX_OK;
320 mu_auth_data_free (auth); 329 mu_auth_data_free (auth);
...@@ -322,14 +331,6 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp) ...@@ -322,14 +331,6 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp)
322 } 331 }
323 } 332 }
324 333
325 if ((status = mu_mailbox_get_message (imbx, 1, &msg)) != 0)
326 {
327 maidag_error (_("Cannot get message from the temporary mailbox: %s"),
328 mu_strerror (status));
329 mu_auth_data_free (auth);
330 return EX_TEMPFAIL;
331 }
332
333 if (!url) 334 if (!url)
334 { 335 {
335 status = mu_url_create (&url, auth->mailbox); 336 status = mu_url_create (&url, auth->mailbox);
...@@ -394,7 +395,7 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp) ...@@ -394,7 +395,7 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp)
394 will be created */ 395 will be created */
395 if (switch_user_id (auth, 1)) 396 if (switch_user_id (auth, 1))
396 return EX_TEMPFAIL; 397 return EX_TEMPFAIL;
397 status = deliver_to_user (imbx, mbox, msg, auth, errp); 398 status = deliver_to_user (mbox, msg, auth, errp);
398 if (switch_user_id (auth, 0)) 399 if (switch_user_id (auth, 0))
399 return EX_TEMPFAIL; 400 return EX_TEMPFAIL;
400 401
...@@ -405,7 +406,7 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp) ...@@ -405,7 +406,7 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp)
405 } 406 }
406 407
407 int 408 int
408 deliver (mu_mailbox_t imbx, char *dest_id, char **errp) 409 deliver (mu_message_t msg, char *dest_id, char **errp)
409 { 410 {
410 int status; 411 int status;
411 const char *name; 412 const char *name;
...@@ -455,6 +456,6 @@ deliver (mu_mailbox_t imbx, char *dest_id, char **errp) ...@@ -455,6 +456,6 @@ deliver (mu_mailbox_t imbx, char *dest_id, char **errp)
455 name = dest_id; 456 name = dest_id;
456 dest_id = NULL; 457 dest_id = NULL;
457 } 458 }
458 return deliver_url (url, imbx, name, errp); 459 return deliver_url (url, msg, name, errp);
459 } 460 }
460 461
......
...@@ -348,8 +348,20 @@ dot_deliver (void *item, void *cbdata) ...@@ -348,8 +348,20 @@ dot_deliver (void *item, void *cbdata)
348 char *name = item; 348 char *name = item;
349 FILE *out = cbdata; 349 FILE *out = cbdata;
350 char *errp = NULL; 350 char *errp = NULL;
351 mu_message_t msg;
352 int status;
351 353
352 switch (deliver (mbox, name, &errp)) 354 if ((status = mu_mailbox_get_message (mbox, 1, &msg)) != 0)
355 {
356 mu_error (_("Cannot get message from the temporary mailbox: %s"),
357 mu_strerror (status));
358 lmtp_reply (out, "450", "4.1.0",
359 "%s: temporary failure, try again later",
360 name);
361 return 0;
362 }
363
364 switch (deliver (msg, name, &errp))
353 { 365 {
354 case 0: 366 case 0:
355 lmtp_reply (out, "250", "2.0.0", "%s: delivered", name); 367 lmtp_reply (out, "250", "2.0.0", "%s: delivered", name);
......
...@@ -408,7 +408,7 @@ _sieve_parse_error (void *user_name, const char *filename, int lineno, ...@@ -408,7 +408,7 @@ _sieve_parse_error (void *user_name, const char *filename, int lineno,
408 } 408 }
409 409
410 int 410 int
411 sieve_test (struct mu_auth_data *auth, mu_mailbox_t mbx) 411 sieve_test (struct mu_auth_data *auth, mu_message_t msg)
412 { 412 {
413 int rc = 1; 413 int rc = 1;
414 char *progfile; 414 char *progfile;
...@@ -443,9 +443,7 @@ sieve_test (struct mu_auth_data *auth, mu_mailbox_t mbx) ...@@ -443,9 +443,7 @@ sieve_test (struct mu_auth_data *auth, mu_mailbox_t mbx)
443 if (rc == 0) 443 if (rc == 0)
444 { 444 {
445 mu_attribute_t attr; 445 mu_attribute_t attr;
446 mu_message_t msg = NULL; 446
447
448 mu_mailbox_get_message (mbx, 1, &msg);
449 mu_message_get_attribute (msg, &attr); 447 mu_message_get_attribute (msg, &attr);
450 mu_attribute_unset_deleted (attr); 448 mu_attribute_unset_deleted (attr);
451 if (switch_user_id (auth, 1) == 0) 449 if (switch_user_id (auth, 1) == 0)
......
...@@ -142,8 +142,8 @@ void notify_biff (mu_mailbox_t mbox, char *name, size_t size); ...@@ -142,8 +142,8 @@ void notify_biff (mu_mailbox_t mbox, char *name, size_t size);
142 void guess_retval (int ec); 142 void guess_retval (int ec);
143 143
144 int mda (mu_mailbox_t mbx, char *username); 144 int mda (mu_mailbox_t mbx, char *username);
145 int deliver (mu_mailbox_t imbx, char *name, char **errp); 145 int deliver (mu_message_t msg, char *name, char **errp);
146 int sieve_test (struct mu_auth_data *auth, mu_mailbox_t mbx); 146 int sieve_test (struct mu_auth_data *auth, mu_message_t msg);
147 int check_quota (struct mu_auth_data *auth, mu_off_t size, mu_off_t *rest); 147 int check_quota (struct mu_auth_data *auth, mu_off_t size, mu_off_t *rest);
148 148
149 #ifdef WITH_GUILE 149 #ifdef WITH_GUILE
......
...@@ -88,6 +88,19 @@ mu_mailer_get_url_default (const char **url) ...@@ -88,6 +88,19 @@ mu_mailer_get_url_default (const char **url)
88 return 0; 88 return 0;
89 } 89 }
90 90
91 static void
92 set_default_debug (mu_mailer_t mailer)
93 {
94 mu_log_level_t level = mu_global_debug_level ("mailer");
95 if (level)
96 {
97 mu_debug_t debug;
98 if (mu_mailer_get_debug (mailer, &debug))
99 return;
100 mu_debug_set_level (debug, level);
101 }
102 }
103
91 int 104 int
92 mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url) 105 mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url)
93 { 106 {
...@@ -134,6 +147,7 @@ mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url) ...@@ -134,6 +147,7 @@ mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url)
134 mailer->url = url; 147 mailer->url = url;
135 *pmailer = mailer; 148 *pmailer = mailer;
136 149
150 set_default_debug (mailer);
137 return status; 151 return status;
138 } 152 }
139 } 153 }
......
...@@ -93,7 +93,7 @@ mu_mysql_connect (mu_sql_connection_t conn) ...@@ -93,7 +93,7 @@ mu_mysql_connect (mu_sql_connection_t conn)
93 93
94 mysql_init (mp->mysql); 94 mysql_init (mp->mysql);
95 95
96 if (conn->server[0] == '/') 96 if (conn->server && conn->server[0] == '/')
97 { 97 {
98 host = "localhost"; 98 host = "localhost";
99 socket_name = conn->server; 99 socket_name = conn->server;
......