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
2008-11-05 Sergey Poznyakoff <gray@gnu.org.ua>
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.
2008-10-28 Sergey Poznyakoff <gray@gnu.org.ua>
Make maidag hanlde mailer URLs.
......
......@@ -44,7 +44,17 @@ make_tmp (const char *from, mu_mailbox_t *mbox)
int
mda (mu_mailbox_t mbx, char *username)
{
deliver (mbx, username, NULL);
int status;
mu_message_t msg;
if ((status = mu_mailbox_get_message (mbx, 1, &msg)) != 0)
{
maidag_error (_("Cannot get message from the temporary mailbox: %s"),
mu_strerror (status));
return EX_TEMPFAIL;
}
deliver (msg, username, NULL);
if (multiple_delivery)
exit_code = EX_OK;
......@@ -143,7 +153,7 @@ attach_notify (mu_mailbox_t mbox)
}
int
deliver_to_user (mu_mailbox_t imbx, mu_mailbox_t mbox, mu_message_t msg,
deliver_to_user (mu_mailbox_t mbox, mu_message_t msg,
struct mu_auth_data *auth,
char **errp)
{
......@@ -187,7 +197,7 @@ deliver_to_user (mu_mailbox_t imbx, mu_mailbox_t mbox, mu_message_t msg,
if (auth)
{
mu_off_t n;
mu_off_t msg_size;
size_t msg_size;
mu_off_t mbsize;
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,
break;
default:
if ((status = mu_mailbox_get_size (imbx, &msg_size)))
if ((status = mu_message_size (msg, &msg_size)))
{
maidag_error (_("Cannot get message size (input message %s): %s"),
path, mu_strerror (status));
......@@ -292,11 +302,10 @@ is_mailer_url (mu_url_t url)
#define REMOTE_PREFIX_LEN (sizeof(REMOTE_PREFIX)-1)
int
deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp)
deliver_url (mu_url_t url, mu_message_t msg, const char *name, char **errp)
{
struct mu_auth_data *auth = NULL;
mu_mailbox_t mbox;
mu_message_t msg;
int status;
if (name)
......@@ -314,7 +323,7 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp)
if (current_uid)
auth->change_uid = 0;
if (!sieve_test (auth, imbx))
if (!sieve_test (auth, msg))
{
exit_code = EX_OK;
mu_auth_data_free (auth);
......@@ -322,14 +331,6 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp)
}
}
if ((status = mu_mailbox_get_message (imbx, 1, &msg)) != 0)
{
maidag_error (_("Cannot get message from the temporary mailbox: %s"),
mu_strerror (status));
mu_auth_data_free (auth);
return EX_TEMPFAIL;
}
if (!url)
{
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)
will be created */
if (switch_user_id (auth, 1))
return EX_TEMPFAIL;
status = deliver_to_user (imbx, mbox, msg, auth, errp);
status = deliver_to_user (mbox, msg, auth, errp);
if (switch_user_id (auth, 0))
return EX_TEMPFAIL;
......@@ -405,7 +406,7 @@ deliver_url (mu_url_t url, mu_mailbox_t imbx, const char *name, char **errp)
}
int
deliver (mu_mailbox_t imbx, char *dest_id, char **errp)
deliver (mu_message_t msg, char *dest_id, char **errp)
{
int status;
const char *name;
......@@ -455,6 +456,6 @@ deliver (mu_mailbox_t imbx, char *dest_id, char **errp)
name = dest_id;
dest_id = NULL;
}
return deliver_url (url, imbx, name, errp);
return deliver_url (url, msg, name, errp);
}
......
......@@ -348,8 +348,20 @@ dot_deliver (void *item, void *cbdata)
char *name = item;
FILE *out = cbdata;
char *errp = NULL;
mu_message_t msg;
int status;
if ((status = mu_mailbox_get_message (mbox, 1, &msg)) != 0)
{
mu_error (_("Cannot get message from the temporary mailbox: %s"),
mu_strerror (status));
lmtp_reply (out, "450", "4.1.0",
"%s: temporary failure, try again later",
name);
return 0;
}
switch (deliver (mbox, name, &errp))
switch (deliver (msg, name, &errp))
{
case 0:
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,
}
int
sieve_test (struct mu_auth_data *auth, mu_mailbox_t mbx)
sieve_test (struct mu_auth_data *auth, mu_message_t msg)
{
int rc = 1;
char *progfile;
......@@ -443,9 +443,7 @@ sieve_test (struct mu_auth_data *auth, mu_mailbox_t mbx)
if (rc == 0)
{
mu_attribute_t attr;
mu_message_t msg = NULL;
mu_mailbox_get_message (mbx, 1, &msg);
mu_message_get_attribute (msg, &attr);
mu_attribute_unset_deleted (attr);
if (switch_user_id (auth, 1) == 0)
......
......@@ -142,8 +142,8 @@ void notify_biff (mu_mailbox_t mbox, char *name, size_t size);
void guess_retval (int ec);
int mda (mu_mailbox_t mbx, char *username);
int deliver (mu_mailbox_t imbx, char *name, char **errp);
int sieve_test (struct mu_auth_data *auth, mu_mailbox_t mbx);
int deliver (mu_message_t msg, char *name, char **errp);
int sieve_test (struct mu_auth_data *auth, mu_message_t msg);
int check_quota (struct mu_auth_data *auth, mu_off_t size, mu_off_t *rest);
#ifdef WITH_GUILE
......
......@@ -88,6 +88,19 @@ mu_mailer_get_url_default (const char **url)
return 0;
}
static void
set_default_debug (mu_mailer_t mailer)
{
mu_log_level_t level = mu_global_debug_level ("mailer");
if (level)
{
mu_debug_t debug;
if (mu_mailer_get_debug (mailer, &debug))
return;
mu_debug_set_level (debug, level);
}
}
int
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)
mailer->url = url;
*pmailer = mailer;
set_default_debug (mailer);
return status;
}
}
......
......@@ -93,7 +93,7 @@ mu_mysql_connect (mu_sql_connection_t conn)
mysql_init (mp->mysql);
if (conn->server[0] == '/')
if (conn->server && conn->server[0] == '/')
{
host = "localhost";
socket_name = conn->server;
......