Hi all, when Balsa sends a message to a local or remote SMTP server, a feedback is given only on failure. However, sometimes it is necessary to trace sent messages on the SMTP server.
As to simplify this, I propose to add syslog logging for SMTP operations. The attached patch will basically send a message to the facility LOG_MAIL with priority LOG_INFO for messages accepted by the SMTP server, and LOG_NOTICE for rejected ones, respectively. The message includes the user name, the PID, the server, the message ID and the final server reply, e.g.: Jul 30 13:59:20 deneb balsa: [4116:albrecht] SMTP=localhost:25 [email protected] Result='2.0.0 Ok: queued as 682BD1FF079' Note that syslog() is a standard API defined by IEEE 1003.1, and should thus work on every compliant system. Of course, it is up the system admin to configure the syslog backend properly. Opinions? Best, Albrecht. --- Patch details: - libbalsa/send.c: new function balsa_send_message_syslog(), changed API of net_client_smtp_send_msg() - libnetclient/net-client-smtp.[ch]: extend API of net_client_smtp_send_msg() for optionally passing the final SMTP server reply
diff --git a/libbalsa/send.c b/libbalsa/send.c
index a3e96a8ef..dd63de210 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -29,6 +29,7 @@
#include <math.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include "libbalsa.h"
#include "libbalsa_private.h"
@@ -1008,6 +1009,26 @@ balsa_send_message_error(MessageQueueItem *mqi,
error->message);
}
+static void
+balsa_send_message_syslog(const gchar *smtp_server,
+ const MessageQueueItem *mqi,
+ gboolean result,
+ const gchar *server_response,
+ const GError *server_error)
+{
+ GString *syslog_msg;
+
+ syslog_msg = g_string_new(NULL);
+ g_string_append_printf(syslog_msg, "[%d:%s] SMTP=%s Message-ID=%s", (int) getpid(), g_get_user_name(), smtp_server,
+ libbalsa_message_get_message_id(mqi->orig));
+ if (result) {
+ syslog(LOG_MAIL | LOG_INFO, "%s Result='%s'", syslog_msg->str, server_response);
+ } else {
+ syslog(LOG_MAIL | LOG_NOTICE, "%s Error='%s'", syslog_msg->str,
+ (server_error != NULL) ? server_error->message : "unknown");
+ }
+}
+
static gpointer
balsa_send_message_real(SendMessageInfo *info)
{
@@ -1036,6 +1057,7 @@ balsa_send_message_real(SendMessageInfo *info)
for (this_msg = info->items; this_msg != NULL; this_msg = this_msg->next) {
MessageQueueItem *mqi = (MessageQueueItem *) this_msg->data;
gboolean send_res;
+ gchar *server_reply = NULL;
LibBalsaMailbox *mailbox;
mailbox = mqi->orig != NULL ? libbalsa_message_get_mailbox(mqi->orig) : NULL;
@@ -1043,7 +1065,9 @@ balsa_send_message_real(SendMessageInfo *info)
info->curr_msg++;
g_debug("%s: %u/%u mqi = %p", __func__, info->msg_count, info->curr_msg, mqi);
/* send the message */
- send_res = net_client_smtp_send_msg(info->session, mqi->smtp_msg, &error);
+ send_res = net_client_smtp_send_msg(info->session, mqi->smtp_msg, &server_reply, &error);
+ balsa_send_message_syslog(net_client_get_host(NET_CLIENT(info->session)), mqi, send_res, server_reply, error);
+ g_free(server_reply);
g_mutex_lock(&send_messages_lock);
if (mailbox != NULL) {
diff --git a/libnetclient/net-client-smtp.c b/libnetclient/net-client-smtp.c
index f532222e3..0c81dcc47 100644
--- a/libnetclient/net-client-smtp.c
+++ b/libnetclient/net-client-smtp.c
@@ -197,7 +197,7 @@ net_client_smtp_can_dsn(NetClientSmtp *client)
gboolean
-net_client_smtp_send_msg(NetClientSmtp *client, const NetClientSmtpMessage *message, GError **error)
+net_client_smtp_send_msg(NetClientSmtp *client, const NetClientSmtpMessage *message, gchar **server_stat, GError **error)
{
NetClient *netclient;
gboolean result;
@@ -267,7 +267,7 @@ net_client_smtp_send_msg(NetClientSmtp *client, const NetClientSmtpMessage *mess
if (result) {
(void) net_client_set_timeout(netclient, 10U * 60U); /* RFC 5321, Sect 4.5.3.2.6.: 10 minutes timeout */
- result = net_client_smtp_read_reply(client, -1, NULL, error);
+ result = net_client_smtp_read_reply(client, -1, server_stat, error);
client->data_state = FALSE;
}
diff --git a/libnetclient/net-client-smtp.h b/libnetclient/net-client-smtp.h
index 65b62c3b4..70ecef1e5 100644
--- a/libnetclient/net-client-smtp.h
+++ b/libnetclient/net-client-smtp.h
@@ -161,12 +161,13 @@ gboolean net_client_smtp_can_dsn(NetClientSmtp *client);
*
* @param client connected SMTP network client object
* @param message message data
+ * @param server_stat filled with the final server response on success, may be NULL
* @param error filled with error information if the connection fails
* @return TRUE on success or FALSE if sending the message failed
*
* Send the passed SMTP message to the connected SMTP server.
*/
-gboolean net_client_smtp_send_msg(NetClientSmtp *client, const NetClientSmtpMessage *message, GError **error);
+gboolean net_client_smtp_send_msg(NetClientSmtp *client, const NetClientSmtpMessage *message, gchar **server_stat, GError **error);
/** @brief Create a SMTP message
pgp40UjHiNtV3.pgp
Description: PGP signature
_______________________________________________ balsa-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/balsa-list
