summaryrefslogtreecommitdiffabout
path: root/src/mail.c
authorSergey Poznyakoff <gray@gnu.org.ua>2007-08-25 13:29:33 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2007-08-25 13:29:33 (GMT)
commite4b5d37def5023905e98bc0b6c6f81c2d56ba362 (patch) (side-by-side diff)
tree76dbdd53079e4f05529c002284467820c8d5d0ef /src/mail.c
parent1107c4341552ecb568b43292fc219a73e0d49a0f (diff)
downloadwydawca-e4b5d37def5023905e98bc0b6c6f81c2d56ba362.tar.gz
wydawca-e4b5d37def5023905e98bc0b6c6f81c2d56ba362.tar.bz2
* configure.ac: Require mailutils for wydawca
* bootstrap: Require inttostr and strftime * wydawca/mail.h: New file * wydawca/mail.c: New file * wydawca/Makefile.am: Add mail.c and mail.h * wydawca/wydawca.c: Include mail.h (stat_mask_p, make_stat_expansion): New functions (logstats): Call mail_stats (main): Call initialize mailer subsystem * wydawca/sql.c, wydawca/sql.h: Keep usage reference count. Do not deinitialize unless it falls to 0. Do not initialize if it is > 0. * wydawca/verify.c (expand_param): Rewrite to allow long keywords All callers updated. * wydawca/wydawca.h (struct access_method): Keep reference count (struct directory_pair): verify_method and gpg_key_method are pointers to structs. (struct kw_expansion): kw is char* (count_collected_triplets): New function (method_new): New function * wydawca/config.c: reimplement verify-user and gpg-key New keywords mailer, admin-address, from-address, mail-admin-stat and admin-stat-message * wydawca/process.c: Close methods only when their reference count is 0. * wydawca/method.c: Likewise. (method_new): New function * wydawca/wydawca.rc: Update * wydawca/diskio.c: Minor changes * wydawca/triplet.c (count_collected_triplets): New function * jabberd/main.c: Minor change git-svn-id: file:///svnroot/wydawca/trunk@295 6bb4bd81-ecc2-4fd4-a2d4-9571d19c0d33
Diffstat (limited to 'src/mail.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/mail.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/mail.c b/src/mail.c
new file mode 100644
index 0000000..0f91ebd
--- a/dev/null
+++ b/src/mail.c
@@ -0,0 +1,133 @@
+/* wydawca - FTP release synchronization daemon
+ Copyright (C) 2007 Sergey Poznyakoff
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "wydawca.h"
+#include <mail.h>
+
+int mailer_opened;
+mu_mailer_t mailer;
+mu_address_t admin_address;
+mu_address_t from_address;
+unsigned long mail_admin_mask;
+char *admin_stat_message_template;
+
+void
+mail_init ()
+{
+ if (!mailer)
+ {
+ int rc;
+ if ((rc = mu_mailer_create (&mailer, NULL)))
+ {
+ const char *url = NULL;
+ mu_mailer_get_url_default (&url);
+ logmsg (LOG_ERR, "cannot create default mailer `%s': %s",
+ url, mu_strerror (rc));
+ }
+ }
+}
+
+void
+mail_send_message (mu_address_t rcpt, const char *text)
+{
+ int rc;
+ mu_message_t msg;
+ mu_stream_t stream = NULL;
+ mu_header_t hdr;
+ int mailer_flags = 0;
+ static char *x_mailer = "wydawca (" PACKAGE_STRING ")";
+
+ mu_message_create (&msg, NULL);
+
+ mu_message_get_stream (msg, &stream);
+ mu_stream_write (stream, text, strlen (text), 0, NULL);
+ mu_message_get_header (msg, &hdr);
+ mu_header_append (hdr, "X-Mailer", x_mailer);
+
+ if (debug_level > 1)
+ {
+ mu_debug_t debug;
+ mu_mailer_get_debug (mailer, &debug);
+ mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
+ if (debug_level > 2)
+ mailer_flags = MAILER_FLAG_DEBUG_DATA;
+ }
+
+ if (!mailer_opened)
+ {
+ if ((rc = mu_mailer_open (mailer, mailer_flags)))
+ {
+ const char *url = NULL;
+ mu_mailer_get_url_default (&url);
+ logmsg (LOG_CRIT, "opening mailer `%s' failed: %s",
+ url, mu_strerror (rc));
+ return;
+ }
+ mailer_opened = 1;
+ }
+
+ rc = mu_mailer_send_message (mailer, msg, from_address, rcpt);
+ if (rc)
+ logmsg (LOG_CRIT, "cannot send message: %s", mu_strerror (rc));
+
+ mu_message_destroy (&msg, mu_message_get_owner (msg));
+}
+
+void
+mail_stats ()
+{
+ struct kw_expansion exp[MAX_STAT + 1];
+ time_t t;
+ char *text;
+
+ if (!stat_mask_p (mail_admin_mask) || !mailer)
+ return;
+
+ if (debug_level)
+ {
+ size_t size;
+ char *buf;
+ mu_address_to_string (admin_address, NULL, 0, &size);
+ buf = xmalloc (size + 1);
+ mu_address_to_string (admin_address, buf, size + 1, NULL);
+ logmsg (LOG_DEBUG, "Sending stats to %s", buf);
+ free (buf);
+ }
+
+ if (dry_run_mode)
+ return;
+
+ time (&t);
+ exp[0].kw = "date";
+ exp[0].value = xstrdup (ctime (&t));
+ exp[0].value [strlen (exp[0].value) - 1] = 0;
+ make_stat_expansion (exp + 1);
+
+ text = expand_param (admin_stat_message_template,
+ exp, sizeof (exp) / sizeof (exp[0]));
+
+ mail_send_message (admin_address, text);
+
+ free (text);
+ free_kwexp (exp, sizeof (exp) / sizeof (exp[0]));
+}
+
+void
+mail_finish ()
+{
+ if (mailer_opened)
+ mu_mailer_close (mailer);
+}

Return to:

Send suggestions and report system problems to the System administrator.