diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-02-06 11:59:20 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-02-06 11:59:20 +0200 |
commit | 8b573cdca1f2d71184531a2bbeb1263b116d1dac (patch) | |
tree | 02e327b33a55b4a6f924f775b533e8cf545c152c /maidag | |
parent | 94c35a24f30d8c61c1306f59979ae13ffb80fdb3 (diff) | |
download | mailutils-8b573cdca1f2d71184531a2bbeb1263b116d1dac.tar.gz mailutils-8b573cdca1f2d71184531a2bbeb1263b116d1dac.tar.bz2 |
Move biff notification to the library. Implement it in inc and movemail.
* include/mailutils/mailbox.h (mu_mailbox_set_notify)
(mu_mailbox_unset_notify): New protos.
* include/mailutils/sys/mailbox.h (_mu_mailbox) <notify_user>
<notify_fd,notify_sa>: New members.
* libmailutils/mailbox/Makefile.am (libmailbox_la_SOURCES): Add
biffnotify.c
* libmailutils/mailbox/biffnotify.c: New file.
* libmailutils/mailbox/mailbox.c (_mailbox_create_from_record): Initialize
notify_fd.
(mu_mailbox_destroy): Free notify_sa.
(mu_mailbox_close): Close notify_fd.
(mu_mailbox_flush): Rewrite to handle append-only mailboxes effectively.
* libmailutils/server/msrv.c (server_cfg_param): Fix docstring.
* libmailutils/stream/file_stream.c (fd_open): Open fd read-write if
both MU_STREAM_APPEND and MU_STREAM_READ are requested.
* libproto/mbox/mbox.c (mbox_expunge0): Rescan the mailbox if
messages_count == 0. Special handling for append-only mailboxes.
* maidag/deliver.c: Use library notification mechanism.
* mh/inc.c: New option --notify.
* movemail/movemail.c: Likewise.
Diffstat (limited to 'maidag')
-rw-r--r-- | maidag/deliver.c | 71 |
1 files changed, 5 insertions, 66 deletions
diff --git a/maidag/deliver.c b/maidag/deliver.c index d48b7e21c..6fdc90695 100644 --- a/maidag/deliver.c +++ b/maidag/deliver.c @@ -128,69 +128,6 @@ maidag_stdio_delivery (maidag_delivery_fn delivery_fun, int argc, char **argv) return exit_code; } -static int biff_fd = -1; -static struct sockaddr_in biff_in; -static const char *biff_user_name; - -static int -notify_action (mu_observer_t obs, size_t type, void *data, void *action_data) -{ - if (type == MU_EVT_MAILBOX_MESSAGE_APPEND && biff_user_name) - { - mu_message_qid_t qid = data; - mu_mailbox_t mbox = mu_observer_get_owner (obs); - mu_url_t url; - char *buf; - - mu_mailbox_get_url (mbox, &url); - mu_asprintf (&buf, "%s@%s:%s", biff_user_name, - qid, mu_url_to_string (url)); - if (buf) - { - sendto (biff_fd, buf, strlen (buf), 0, - (struct sockaddr *)&biff_in, sizeof biff_in); - free (buf); - } - } - return 0; -} - -static void -attach_notify (mu_mailbox_t mbox) -{ - struct servent *sp; - mu_observer_t observer; - mu_observable_t observable; - - if (biff_fd == -1) - { - if ((sp = getservbyname ("biff", "udp")) == NULL) - { - biff_fd = -2; - return; - } - biff_in.sin_family = AF_INET; - biff_in.sin_addr.s_addr = htonl (INADDR_LOOPBACK); - biff_in.sin_port = sp->s_port; - - biff_fd = socket (PF_INET, SOCK_DGRAM, 0); - if (biff_fd < 0) - { - biff_fd = -2; - return; - } - } - - if (biff_fd) - { - mu_observer_create (&observer, mbox); - mu_observer_set_action (observer, notify_action, mbox); - mu_mailbox_get_observable (mbox, &observable); - mu_observable_attach (observable, MU_EVT_MAILBOX_MESSAGE_APPEND, - observer); - } -} - int deliver_to_mailbox (mu_mailbox_t mbox, mu_message_t msg, struct mu_auth_data *auth, @@ -213,8 +150,6 @@ deliver_to_mailbox (mu_mailbox_t mbox, mu_message_t msg, return EX_TEMPFAIL; } - attach_notify (mbox); - /* FIXME: This is superfluous, as mu_mailbox_append_message takes care of locking anyway. But I leave it here for the time being. */ mu_mailbox_get_locker (mbox, &lock); @@ -403,7 +338,11 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp) return EX_TEMPFAIL; } - biff_user_name = name; + status = mu_mailbox_set_notify (mbox, name); + if (status) + mu_error (_("failed to set notification on %s: %s"), + mu_url_to_string (url), + mu_strerror (status)); /* Actually open the mailbox. Switch to the user's euid to make sure the maildrop file will have right privileges, in case it |