commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-136-gdb1ee5e


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-136-gdb1ee5e
Date: Fri, 08 Oct 2010 13:04:36 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=db1ee5e0af1f25405ffb35876149eb25cf7763f2

The branch, master has been updated
       via  db1ee5e0af1f25405ffb35876149eb25cf7763f2 (commit)
       via  0bf8123e1c49fc4ac4383ff95e26f486d6b8948b (commit)
       via  20bcdece82079305c006b956f1340391b64ee498 (commit)
       via  c9ecb01d64d9355b72545fbd40edfc0a1aeb302e (commit)
       via  51d1695e96b9a286bcffd0eb0a674ea9ee034f23 (commit)
      from  043344271a4bb538d5a044c6757ea8617bb506ad (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit db1ee5e0af1f25405ffb35876149eb25cf7763f2
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Oct 8 15:20:54 2010 +0300

    maidag: improve forwarding capability, add a testcase for it.
    
    * maidag/forward.c (check_forward_permissions): Keep track of the
    processed files.  Refuse to process a file twice.
    (process_forward): Rewrite using streams instead of FILE.
    (maidag_forward): Accept absolute file names (mainly for testing).
    * maidag/maidag.c (forward_checks): New keyword "owner".
    (cb2_forward_file_checks): New keyword "none".
    (main): Require at least one recipient in MDA mode.
    * maidag/maidag.h (FWD_OWNER): New mask.
    * maidag/tests/forward.at: New file.
    * maidag/tests/Makefile.am (TESTSUITE_AT): Add forward.at
    * maidag/tests/testsuite.at: Include forward.at.

commit 0bf8123e1c49fc4ac4383ff95e26f486d6b8948b
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Oct 8 15:19:41 2010 +0300

    Improve mta simulator output.
    
    * examples/mta.c (mta_send): A line number refers to the start
    of each line, not end of it.
    * mail/testsuite/mail/send.exp: Reflect this change.
    * sieve/tests/redirect.at: Likewise.
    * sieve/tests/reject.at: Likewise.

commit 20bcdece82079305c006b956f1340391b64ee498
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Oct 8 10:35:31 2010 +0300

    maidag: optimize mda mode.
    
    * maidag/deliver.c (make_tmp): Return mu_message_t.
    Use mu_stream_to_message function.
    (mda): Remove.
    (maidag_stdio_delivery): Inline mda.
    * maidag/maidag.h (mda): Remove.

commit c9ecb01d64d9355b72545fbd40edfc0a1aeb302e
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Oct 8 10:29:23 2010 +0300

    maidag: remove `default' mode (superseded by --mda).

commit 51d1695e96b9a286bcffd0eb0a674ea9ee034f23
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Oct 8 10:17:11 2010 +0300

    Maidag cleanup
    
    * maidag/maidag.c (mda_mode,lmtp_mode,url_option): Remove.
    (maidag_mode): New variable.
    (parse_opt): The --lmtp, --url and --mda options set the delivery-mode
    configuration statement.
    (cb_delivery_mode): New callback.
    (maidag_cfg_param) <delivery-mode>: New statement.
    (main): Redo delivery mode selection.
    * maidag/maidag.h (maidag_mode): New enum.
    (maidag_mode): New extern.
    (mda_mode,lmtp_mode,url_option): Remove.
    (maidag_delivery_fn): New typedef.
    (maidag_stdio_delivery,mda): Change signature.
    (deliver_to_url, deliver_to_user): New prototypes.
    
    * maidag/deliver.c (mda): Take delivery function as a parameter.
    (maidag_stdio_delivery): Likewise.
    (deliver_to_user): Rename to deliver_to_mailbox.
    (deliver_url): Rename to do_delivery.
    (deliver): Rename to deliver_to_url.
    (deliver_to_user): New function.
    * maidag/forward.c (process_forward): Use deliver_to_user.
    * maidag/lmtp.c (dot_deliver): Likewise.

-----------------------------------------------------------------------

Summary of changes:
 examples/mta.c               |   16 ++++-
 maidag/deliver.c             |  129 +++++++++++++++---------------------------
 maidag/forward.c             |  110 +++++++++++++++++++++++++++++-------
 maidag/lmtp.c                |    2 +-
 maidag/maidag.c              |  100 ++++++++++++++++++--------------
 maidag/maidag.h              |   32 +++++++----
 maidag/tests/Makefile.am     |    1 +
 maidag/tests/testsuite.at    |    1 +
 mail/testsuite/mail/send.exp |    1 -
 sieve/tests/redirect.at      |    3 -
 sieve/tests/reject.at        |    3 -
 11 files changed, 227 insertions(+), 171 deletions(-)

diff --git a/examples/mta.c b/examples/mta.c
index 4d27774..8fb265c 100644
--- a/examples/mta.c
+++ b/examples/mta.c
@@ -326,7 +326,8 @@ mta_send (mu_message_t msg)
   mu_stream_t stream = NULL;
   size_t line;
   char *value;
-
+  int newline = 0;
+  
   value = from_address ();
   if (value)
     {
@@ -340,7 +341,7 @@ mta_send (mu_message_t msg)
 
   mu_message_get_streamref (msg, &stream);
   line = 0;
-  fprintf (diag, "%4lu: ", (unsigned long) line);
+  newline = 1;
   while (mu_stream_read (stream, buffer, sizeof buffer - 1, &n) == 0
         && n != 0)
     {
@@ -348,16 +349,23 @@ mta_send (mu_message_t msg)
 
       for (i = 0; i < n; i++)
        {
+         if (newline)
+           {
+             fprintf (diag, "%4lu: ", (unsigned long) line);
+             newline = 0;
+           }
          fputc (buffer[i], diag);
          if (buffer[i] == '\n')
            {
              line++;
-             fprintf (diag, "%4lu: ", (unsigned long) line);
+             newline = 1;
            }
        }
     }
   mu_stream_destroy (&stream);
-  fprintf (diag, "\nEND OF MESSAGE\n");
+  if (!newline)
+    fprintf (diag, "\n(no newline at EOF)\n");
+  fprintf (diag, "END OF MESSAGE\n");
   fflush (diag);
   return 0;
 }
diff --git a/maidag/deliver.c b/maidag/deliver.c
index cd211d8..7bdf29a 100644
--- a/maidag/deliver.c
+++ b/maidag/deliver.c
@@ -19,14 +19,14 @@
 
 #include "maidag.h"
 
-static mu_mailbox_t
+static mu_message_t
 make_tmp (const char *from)
 {
   int rc;
   mu_stream_t in, out;
   char *buf = NULL;
   size_t size = 0, n;
-  mu_mailbox_t mbox;
+  mu_message_t mesg;
   
   rc = mu_stdio_stream_create (&in, MU_STDIN_FD, MU_STREAM_READ);
   if (rc)
@@ -90,9 +90,6 @@ make_tmp (const char *from)
   free (buf);
   
   rc = mu_stream_copy (out, in, 0, NULL);
-  if (rc == 0)
-    /* Write out message delimiter */
-    mu_stream_write (out, "\n", 1, NULL);
   mu_stream_destroy (&in);
   if (rc)
     {
@@ -101,63 +98,32 @@ make_tmp (const char *from)
       exit (EX_TEMPFAIL);
     }
 
-  mu_stream_flush (out);
-  if ((rc = mu_mailbox_create (&mbox, "mbox:/dev/null")) 
-      || (rc = mu_mailbox_open (mbox, MU_STREAM_READ))
-      || (rc = mu_mailbox_set_stream (mbox, out)))
-    {
-      maidag_error (_("error opening temporary file: %s"), 
-                    mu_strerror (rc));
-      mu_stream_destroy (&out);
-      exit (EX_TEMPFAIL);
-    }
-
-  rc = mu_mailbox_messages_count (mbox, &n);
+  rc = mu_stream_to_message (out, &mesg);
+  mu_stream_destroy (&out);
   if (rc)
     {
-      errno = rc;
       maidag_error (_("error creating temporary message: %s"),
                    mu_strerror (rc));
-      mu_stream_destroy (&out);
       exit (EX_TEMPFAIL);
     }
 
-  /* FIXME: mu_stream_unref (out); But mu_mailbox_set_stream
-     steals the reference */
-  return mbox;
+  return mesg;
 }
 
 int
-mda (mu_mailbox_t mbx, char *username)
+maidag_stdio_delivery (maidag_delivery_fn delivery_fun, int argc, char **argv)
 {
-  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;
-
-  return exit_code;
-}
-
-int
-maidag_stdio_delivery (int argc, char **argv)
-{
-  mu_mailbox_t mbox = make_tmp (sender_address);
+  mu_message_t mesg = make_tmp (sender_address);
   
   if (multiple_delivery)
     multiple_delivery = argc > 1;
 
   for (; *argv; argv++)
-    mda (mbox, *argv);
+    {
+      delivery_fun (mesg, *argv, NULL);
+      if (multiple_delivery)
+       exit_code = EX_OK;
+    }
   return exit_code;
 }
 
@@ -224,9 +190,9 @@ attach_notify (mu_mailbox_t mbox)
 }  
 
 int
-deliver_to_user (mu_mailbox_t mbox, mu_message_t msg,
-                struct mu_auth_data *auth,
-                char **errp)
+deliver_to_mailbox (mu_mailbox_t mbox, mu_message_t msg,
+                   struct mu_auth_data *auth,
+                   char **errp)
 {
   int status;
   char *path;
@@ -349,8 +315,8 @@ deliver_to_user (mu_mailbox_t mbox, mu_message_t msg,
   return failed ? exit_code : 0;
 }
 
-int
-deliver_url (mu_url_t url, mu_message_t msg, const char *name, char **errp)
+static int
+do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp)
 {
   struct mu_auth_data *auth = NULL;
   mu_mailbox_t mbox;
@@ -437,7 +403,7 @@ deliver_url (mu_url_t url, mu_message_t msg, const char 
*name, char **errp)
      will be created */
   if (switch_user_id (auth, 1))
     return EX_TEMPFAIL;
-  status = deliver_to_user (mbox, msg, auth, errp);
+  status = deliver_to_mailbox (mbox, msg, auth, errp);
   if (switch_user_id (auth, 0))
     return EX_TEMPFAIL;
 
@@ -448,45 +414,42 @@ deliver_url (mu_url_t url, mu_message_t msg, const char 
*name, char **errp)
 }
 
 int
-deliver (mu_message_t msg, char *dest_id, char **errp)
+deliver_to_url (mu_message_t msg, char *dest_id, char **errp)
 {
   int status;
   const char *name;
   mu_url_t url = NULL;
   
-  if (url_option)
+  status = mu_url_create (&url, dest_id);
+  if (status)
     {
-      status = mu_url_create (&url, dest_id);
-      if (status)
-       {
-         maidag_error (_("%s: cannot create url: %s"), dest_id,
-                       mu_strerror (status));
-         return EX_NOUSER;
-       }
-      status = mu_url_parse (url);
-      if (status)
-       {
-         maidag_error (_("%s: cannot parse url: %s"), dest_id,
-                       mu_strerror (status));
-         mu_url_destroy (&url);
-         return EX_NOUSER;
-       }
-      status = mu_url_sget_user (url, &name);
-      if (status == MU_ERR_NOENT)
-       name = NULL;
-      else if (status)
-       {
-         maidag_error (_("%s: cannot get user name from url: %s"),
-                       dest_id, mu_strerror (status));
-         mu_url_destroy (&url);
-         return EX_NOUSER;
-       }
+      maidag_error (_("%s: cannot create url: %s"), dest_id,
+                   mu_strerror (status));
+      return EX_NOUSER;
+    }
+  status = mu_url_parse (url);
+  if (status)
+    {
+      maidag_error (_("%s: cannot parse url: %s"), dest_id,
+                   mu_strerror (status));
+      mu_url_destroy (&url);
+      return EX_NOUSER;
     }
-  else
+  status = mu_url_sget_user (url, &name);
+  if (status == MU_ERR_NOENT)
+    name = NULL;
+  else if (status)
     {
-      name = dest_id;
-      dest_id = NULL;
+      maidag_error (_("%s: cannot get user name from url: %s"),
+                   dest_id, mu_strerror (status));
+      mu_url_destroy (&url);
+      return EX_NOUSER;
     }
-  return deliver_url (url, msg, name, errp);
+  return do_delivery (url, msg, name, errp);
 }
   
+int
+deliver_to_user (mu_message_t msg, char *dest_id, char **errp)
+{
+  return do_delivery (NULL, msg, dest_id, errp);
+}
diff --git a/maidag/forward.c b/maidag/forward.c
index ccba0db..3924eef 100644
--- a/maidag/forward.c
+++ b/maidag/forward.c
@@ -74,6 +74,52 @@ static struct perm_checker perm_check_tab[] = {
   { 0 }
 };
 
+static mu_list_t idlist;
+
+struct file_id
+{
+  dev_t dev;
+  ino_t inode;
+};
+
+static int
+file_id_cmp (const void *item, const void *data)
+{
+  const struct file_id *a = item;
+  const struct file_id *b = data;
+
+  if (a->dev != b->dev)
+    return 1;
+  if (a->inode != b->inode)
+    return 1;
+  return 0;
+}
+
+static int
+file_id_lookup (dev_t dev, ino_t ino)
+{
+  struct file_id id;
+
+  id.dev = dev;
+  id.inode = ino;
+  return mu_list_locate (idlist, &id, NULL);
+}
+
+static int
+file_id_remember (dev_t dev, ino_t ino)
+{
+  struct file_id *id = malloc (sizeof (*id));
+  if (!id)
+    {
+      mu_error ("%s", mu_strerror (errno));
+      return 1;
+    }
+  id->dev = dev;
+  id->inode = ino;
+  return mu_list_append (idlist, id);
+}
+
+
 /* Check if the forwrd file FILENAME has right permissions and file mode.
    DIRST describes the directory holding the file, AUTH gives current user
    authority. */
@@ -86,8 +132,22 @@ check_forward_permissions (const char *filename, struct 
stat *dirst,
   if (stat (filename, &st) == 0)
     {
       int i;
+
+      if (!idlist)
+       {
+         mu_list_create (&idlist);
+         mu_list_set_comparator (idlist, file_id_cmp);
+       }
+      else if (file_id_lookup (st.st_dev, st.st_ino) == 0)
+       {
+         mu_diag_output (MU_DIAG_NOTICE,
+                         _("skipping forward file %s: already processed"),
+                         filename);
+         return 1;
+       }
       
-      if (auth->uid != st.st_uid)
+      if ((forward_file_checks & FWD_OWNER) &&
+         auth->uid != st.st_uid)
        {
          mu_error (_("%s not owned by %s"), filename, auth->name);
          return 1;
@@ -99,6 +159,7 @@ check_forward_permissions (const char *filename, struct stat 
*dirst,
            mu_error ("%s: %s", filename, gettext (perm_check_tab[i].descr));
            return 1;
          }
+      file_id_remember (st.st_dev, st.st_ino);
       return 0;
     }
   else if (errno != ENOENT)
@@ -203,22 +264,23 @@ create_from_address (mu_message_t msg, mu_address_t 
*pfrom)
 enum maidag_forward_result
 process_forward (mu_message_t msg, char *filename, const char *myname)
 {
-  FILE *fp;
-  size_t size = 0;
+  int rc;
+  mu_stream_t file;
+  size_t size = 0, n;
   char *buf = NULL;
   enum maidag_forward_result result = maidag_forward_ok;
   mu_mailer_t mailer = NULL;
   mu_address_t from = NULL;
-  
-  fp = fopen (filename, "r");
-  if (!fp)
+
+  rc = mu_file_stream_create (&file, filename, MU_STREAM_READ);
+  if (rc)
     {
       mu_error (_("%s: cannot open forward file: %s"),
-               filename, mu_strerror (errno));
+               filename, mu_strerror (rc));
       return maidag_forward_error;
     }
 
-  while (getline (&buf, &size, fp) > 0)
+  while (mu_stream_getline (file, &buf, &size, &n) == 0 && n > 0)
     {
       char *p;
 
@@ -243,7 +305,7 @@ process_forward (mu_message_t msg, char *filename, const 
char *myname)
                  if (result == maidag_forward_ok)
                    result = maidag_forward_metoo;
                }
-             else if (deliver (msg, p, NULL))
+             else if (deliver_to_user (msg, p, NULL))
                result = maidag_forward_error;
            }
        }
@@ -256,7 +318,7 @@ process_forward (mu_message_t msg, char *filename, const 
char *myname)
       mu_mailer_destroy (&mailer);
     }
   free (buf);
-  fclose (fp);
+  mu_stream_destroy (&file);
   return result;
 }
 
@@ -268,19 +330,25 @@ maidag_forward (mu_message_t msg, struct mu_auth_data 
*auth, char *fwfile)
   struct stat st;
   char *filename;
   enum maidag_forward_result result = maidag_forward_none;
-  
-  if (stat (auth->dir, &st))
+
+  if (fwfile[0] != '/')
     {
-      if (errno == ENOENT)
-       /* FIXME: a warning, maybe? */;
-      else if (!S_ISDIR (st.st_mode))
-       mu_error (_("%s: not a directory"), auth->dir);
-      else
-       mu_error (_("%s: cannot stat directory: %s"),
-                 auth->dir, mu_strerror (errno));
-      return maidag_forward_none;
+      if (stat (auth->dir, &st))
+       {
+         if (errno == ENOENT)
+           /* FIXME: a warning, maybe? */;
+         else if (!S_ISDIR (st.st_mode))
+           mu_error (_("%s: not a directory"), auth->dir);
+         else
+           mu_error (_("%s: cannot stat directory: %s"),
+                     auth->dir, mu_strerror (errno));
+         return maidag_forward_none;
+       }
+      asprintf (&filename, "%s/%s", auth->dir, fwfile);
     }
-  asprintf (&filename, "%s/%s", auth->dir, fwfile);
+  else
+    filename = strdup (fwfile);
+  
   if (!filename)
     {
       mu_error ("%s", mu_strerror (errno));
diff --git a/maidag/lmtp.c b/maidag/lmtp.c
index eca152d..0595f30 100644
--- a/maidag/lmtp.c
+++ b/maidag/lmtp.c
@@ -317,7 +317,7 @@ dot_deliver (void *item, void *cbdata)
   mu_stream_t iostr = cbdata;
   char *errp = NULL;
   
-  switch (deliver (mesg, name, &errp))
+  switch (deliver_to_user (mesg, name, &errp))
     {
     case 0:
       lmtp_reply (iostr, "250", "2.0.0", "%s: delivered", name);
diff --git a/maidag/maidag.c b/maidag/maidag.c
index e1bebc0..af9abf8 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -18,8 +18,7 @@
 
 #include "maidag.h"
 
-int mda_mode;              /* Force local MDA mode even if not started as
-                             root */ 
+enum maidag_mode maidag_mode = mode_mda;
 int multiple_delivery;     /* Don't return errors when delivering to multiple
                              recipients */
 int ex_quota_tempfail;     /* Return temporary failure if mailbox quota is
@@ -51,8 +50,6 @@ char *message_id_header;   /* Use the value of this header as 
message
 
 /* For LMTP mode */
 mu_m_server_t server;
-int lmtp_mode;
-int url_option;
 char *lmtp_url_string;
 int reuse_lmtp_address = 1;
 int maidag_transcript;
@@ -216,13 +213,13 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
 
     case LMTP_OPTION:
-      mu_argp_node_list_new (lst, "lmtp", "yes");
+      mu_argp_node_list_new (lst, "delivery-mode", "lmtp");
       if (arg)
        mu_argp_node_list_new (lst, "listen", arg);
       break;
 
     case MDA_OPTION:
-      mda_mode = 1;
+      mu_argp_node_list_new (lst, "delivery-mode", "mda");
       break;
       
     case TRANSCRIPT_OPTION:
@@ -267,7 +264,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
 
     case URL_OPTION:
-      url_option = 1;
+      mu_argp_node_list_new (lst, "delivery-mode", "url");
       break;
       
     case ARGP_KEY_INIT:
@@ -324,6 +321,7 @@ cb_group (mu_debug_t debug, void *data, mu_config_value_t 
*arg)
 
 static struct mu_kwd forward_checks[] = {
   { "all", FWD_ALL },
+  { "owner", FWD_OWNER },
   { "groupwritablefile", FWD_IWGRP },
   { "file_iwgrp", FWD_IWGRP },
   { "worldwritablefile", FWD_IWOTH },
@@ -343,6 +341,12 @@ cb2_forward_file_checks (mu_debug_t debug, const char 
*name, void *data)
   int negate = 0;
   const char *str;
   int val;
+
+  if (strcmp (name, "none") == 0)
+    {
+      forward_file_checks = 0;
+      return 0;
+    }
   
   if (strlen (name) > 2 && mu_c_strncasecmp (name, "no", 2) == 0)
     {
@@ -418,8 +422,34 @@ struct mu_cfg_param filter_cfg_param[] = {
     N_("Set script pattern.") },
   { NULL }
 };
-    
+
+static int
+cb_delivery_mode (mu_debug_t debug, void *data, mu_config_value_t *val)
+{
+  static mu_kwd_t mode_tab[] = {
+    { "mda", mode_mda },
+    { "url", mode_url },
+    { "lmtp", mode_lmtp },
+    { NULL }
+  };
+  int n;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
+    return 1;
+
+  if (mu_kwd_xlat_name (mode_tab, val->v.string, &n) == 0)
+    maidag_mode = n;
+  else
+    mu_cfg_format_error (debug, MU_DEBUG_ERROR,
+                        _("%s is unknonw"),
+                        val->v.string);
+  return 0;
+}
+
 struct mu_cfg_param maidag_cfg_param[] = {
+  { "delivery-mode", mu_cfg_callback, NULL, 0, cb_delivery_mode,
+    N_("Set delivery mode"),
+    N_("mode: {mda | url | lmtp}") },
   { "exit-multiple-delivery-success", mu_cfg_bool, &multiple_delivery, 0, NULL,
     N_("In case of multiple delivery, exit with code 0 if at least one "
        "delivery succeeded.") },
@@ -456,8 +486,6 @@ struct mu_cfg_param maidag_cfg_param[] = {
     N_("Configure safety checks for the forward file."),
     N_("arg: list") },
 /* LMTP support */
-  { "lmtp", mu_cfg_bool, &lmtp_mode, 0, NULL,
-    N_("Run in LMTP mode.") },
   { "group", mu_cfg_callback, &lmtp_groups, 0, cb_group,
     N_("In LMTP mode, retain these supplementary groups."),
     N_("groups: list of string") },
@@ -501,7 +529,8 @@ main (int argc, char *argv[])
 {
   int arg_index;
   mu_debug_t debug;
-
+  maidag_delivery_fn delivery_fun = NULL;
+  
   /* Preparative work: close inherited fds, force a reasonable umask
      and prepare a logging. */
   close_fds ();
@@ -551,11 +580,9 @@ main (int argc, char *argv[])
     exit (EX_CONFIG);
 
   current_uid = getuid ();
-  if (!lmtp_mode && current_uid == 0)
-    mda_mode = 1; 
   
   if (log_to_stderr == -1)
-    log_to_stderr = url_option || (!lmtp_mode && !mda_mode);
+    log_to_stderr = maidag_mode == mode_url;
   
   mu_diag_get_debug (&debug);
   if (!log_to_stderr)
@@ -573,46 +600,31 @@ main (int argc, char *argv[])
   argc -= arg_index;
   argv += arg_index;
 
-  if (lmtp_mode && !url_option)
+  switch (maidag_mode)
     {
+    case mode_lmtp:
       if (argc)
        {
          mu_error (_("too many arguments"));
          return EX_USAGE;
        }
       return maidag_lmtp_server ();
-    }
-  else 
-    {
-      if (!mda_mode)
+
+    case mode_url:
+      /* FIXME: Verify if the urls are deliverable? */
+      delivery_fun = deliver_to_url;
+      break;
+      
+    case mode_mda:
+      if (argc == 0)
        {
-         if (url_option)
-           {
-             /* FIXME: Verify if the urls are deliverable? */
-           }
-         else
-           {
-             static char *s_argv[2];
-             struct mu_auth_data *auth = mu_get_auth_by_uid (current_uid);
-             
-             if (!auth)
-               {
-                 mu_error (_("cannot get username"));
-                 return EX_UNAVAILABLE;
-               }
-             
-             if (argc > 0 && strcmp (auth->name, argv[0]))
-               {
-                 mu_error (_("recipients given when running as non-root"));
-                 return EX_USAGE;
-               }
-             s_argv[0] = auth->name;
-             argv = s_argv;
-             argc = 1;
-           }
+         mu_error (_("recipients not given"));
+         return EX_USAGE;
        }
-      return maidag_stdio_delivery (argc, argv);
+      delivery_fun = deliver_to_user;
+      break;
     }
+  return maidag_stdio_delivery (delivery_fun, argc, argv);
 }
   
 
diff --git a/maidag/maidag.h b/maidag/maidag.h
index aa2195f..012230d 100644
--- a/maidag/maidag.h
+++ b/maidag/maidag.h
@@ -111,13 +111,22 @@ extern int debug_level;
 #define EX_QUOTA() (ex_quota_tempfail ? EX_TEMPFAIL : EX_UNAVAILABLE)
 
 /* .forward file checks */
-#define FWD_IWGRP     0x0001 /* group writable forward file */
-#define FWD_IWOTH     0x0002 /* world writable forward file */
-#define FWD_LINK      0x0004 /* linked forward file in writable dir */
-#define FWD_DIR_IWGRP 0x0008 /* forward file in group writable directory */
-#define FWD_DIR_IWOTH 0x0010 /* forward file in world writable directory */
-#define FWD_ALL (FWD_IWGRP|FWD_IWOTH|FWD_LINK|FWD_DIR_IWOTH|FWD_DIR_IWGRP)
+#define FWD_OWNER     0x0001 /* file ownership */
+#define FWD_IWGRP     0x0002 /* group writable forward file */
+#define FWD_IWOTH     0x0004 /* world writable forward file */
+#define FWD_LINK      0x0008 /* linked forward file in writable dir */
+#define FWD_DIR_IWGRP 0x0010 /* forward file in group writable directory */
+#define FWD_DIR_IWOTH 0x0020 /* forward file in world writable directory */
+#define FWD_ALL 
(FWD_OWNER|FWD_IWGRP|FWD_IWOTH|FWD_LINK|FWD_DIR_IWOTH|FWD_DIR_IWGRP)
+
+enum maidag_mode
+  {
+    mode_mda,
+    mode_url,
+    mode_lmtp
+  };
 
+extern enum maidag_mode maidag_mode;
 extern int exit_code;
 extern int log_to_stderr;
 extern int multiple_delivery;
@@ -136,8 +145,6 @@ extern int sieve_debug_flags;
 extern int sieve_enable_log;  
 
 extern mu_m_server_t server;
-extern int lmtp_mode;
-extern int url_option;
 extern char *lmtp_url_string;
 extern int reuse_lmtp_address;
 extern mu_list_t lmtp_groups;
@@ -147,7 +154,12 @@ extern int maidag_transcript;
 void close_fds (void);
 int switch_user_id (struct mu_auth_data *auth, int user);
 
-int maidag_stdio_delivery (int argc, char **argv);
+typedef int (*maidag_delivery_fn) (mu_message_t, char *, char **);
+
+int deliver_to_url (mu_message_t msg, char *dest_id, char **errp);
+int deliver_to_user (mu_message_t msg, char *dest_id, char **errp);
+
+int maidag_stdio_delivery (maidag_delivery_fn fun, int argc, char **argv);
 int maidag_lmtp_server (void);
 int lmtp_connection (int fd, struct sockaddr *sa, int salen, void *data,
                     mu_ip_server_t srv, time_t timeout, int transcript);
@@ -156,8 +168,6 @@ void maidag_error (const char *fmt, ...) MU_PRINTFLIKE(1, 
2);
 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_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);
 
diff --git a/maidag/tests/Makefile.am b/maidag/tests/Makefile.am
index 65abc82..eec3015 100644
--- a/maidag/tests/Makefile.am
+++ b/maidag/tests/Makefile.am
@@ -39,6 +39,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
 ## ------------ ##
 
 TESTSUITE_AT = \
+ forward.at\
  lmtp.at\
  mda.at\
  testsuite.at\
diff --git a/maidag/tests/testsuite.at b/maidag/tests/testsuite.at
index b56d63d..cb8ff4f 100644
--- a/maidag/tests/testsuite.at
+++ b/maidag/tests/testsuite.at
@@ -29,4 +29,5 @@ MUT_VERSION(maidag)
 m4_include([mda.at])
 m4_include([lmtp.at])
 m4_include([url-mbox.at])
+m4_include([forward.at])
 
diff --git a/mail/testsuite/mail/send.exp b/mail/testsuite/mail/send.exp
index 5576f06..916a546 100644
--- a/mail/testsuite/mail/send.exp
+++ b/mail/testsuite/mail/send.exp
@@ -95,7 +95,6 @@ if ![mu_check_capability ENABLE_SENDMAIL] {
        "  48: > All mimsy were the borogoves,"\
        "  49: > And the mome raths outgrabe."\
        "  50: > "\
-       "  51: "\
        "END OF MESSAGE"
 }
 
diff --git a/sieve/tests/redirect.at b/sieve/tests/redirect.at
index 37291f4..0449447 100644
--- a/sieve/tests/redirect.at
+++ b/sieve/tests/redirect.at
@@ -52,7 +52,6 @@ ENVELOPE TO: <address@hidden>
   13: 
   14: --
   15: Wile E. Coyote   "Super Genius"   address@hidden
-  16: 
 END OF MESSAGE
 ENVELOPE FROM: address@hidden
 ENVELOPE TO: <address@hidden>
@@ -70,7 +69,6 @@ ENVELOPE TO: <address@hidden>
   11: $20,000 IN LESS THAN TWO MONTHS!  AND IT'S LEGAL!!!!!!!!!
   12: !!!!!!!!!!!!!!!!!!111111111!!!!!!!11111111111!!1  JUST
   13: SEND $5 IN SMALL, UNMARKED BILLS TO THE ADDRESSES BELOW!
-  14: 
 END OF MESSAGE
 ENVELOPE FROM: address@hidden
 ENVELOPE TO: <address@hidden>
@@ -85,7 +83,6 @@ ENVELOPE TO: <address@hidden>
    8: Subject: Coffee
    9: 
   10: How about some coffee?
-  11: 
 END OF MESSAGE
 ],
 [REDIRECT on msg uid 1: to address@hidden
diff --git a/sieve/tests/reject.at b/sieve/tests/reject.at
index f1253f6..d7acfc0 100644
--- a/sieve/tests/reject.at
+++ b/sieve/tests/reject.at
@@ -100,7 +100,6 @@ ENVELOPE TO: <address@hidden>
   43: Wile E. Coyote   "Super Genius"   address@hidden
   44: 
   45: --(boundary)
-  46: 
 END OF MESSAGE
 ENVELOPE FROM: address@hidden
 ENVELOPE TO: <address@hidden>
@@ -148,7 +147,6 @@ ENVELOPE TO: <address@hidden>
   41: SEND $5 IN SMALL, UNMARKED BILLS TO THE ADDRESSES BELOW!
   42: 
   43: --(boundary)
-  44: 
 END OF MESSAGE
 ENVELOPE FROM: address@hidden
 ENVELOPE TO: <address@hidden>
@@ -193,7 +191,6 @@ ENVELOPE TO: <address@hidden>
   38: How about some coffee?
   39: 
   40: --(boundary)
-  41: 
 END OF MESSAGE
 ],
 [REJECT on msg uid 1


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]