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-327-g4283831


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-327-g4283831
Date: Tue, 28 Dec 2010 09:53:16 +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=42838314448528fd390d93a0b07a0d3d2d9d312f

The branch, master has been updated
       via  42838314448528fd390d93a0b07a0d3d2d9d312f (commit)
       via  2a6014f9aeb0cbe5e98c5a994f9577d5e6f34208 (commit)
      from  5591d2b7002564432e85426df073c4804e514e16 (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 42838314448528fd390d93a0b07a0d3d2d9d312f
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Dec 28 11:32:53 2010 +0200

    Various fixes
    
    * libmu_sieve/extensions/vacation.c (build_mime): Remove superfluous seek.
    (test_and_update_prop): days==0 means "forever", i.e. send a replay to
    each user only once.
    (vacation_reply): If :file tag is given, treat the argument as the
    name of a file containing the reply message.
    (vacation_tags): Add "sender" and "file" tags.
    
    * libmu_sieve/extensions/moderator.c: Always unref transport stream
    after passing it to mu_stream_to_message.
    * maidag/lmtp.c: Likewise.
    * mh/mh_stream.c: Likewise.
    * mh/prompter.c: Likewise.
    * mh/burst.c (flush_stream): Remove extra unnref.
    * sieve/sieve.c: Likewise.
    * testsuite/smtpsend.c: Likewise.

commit 2a6014f9aeb0cbe5e98c5a994f9577d5e6f34208
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Dec 27 13:28:31 2010 +0200

    vacation: remove dependency on DBM; other minor fixes.
    
    * libmu_sieve/extensions/vacation.c: Use _sget accessors where possible.
    Use mu_property_t instead of db database.
    * libmu_sieve/sieve.y (mu_sieve_get_mailer): Verbosely report
    errors.
    * libmailutils/base/locker.c (mu_locker_create): Create the
    locker if the file name part of its full name does not exist.

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

Summary of changes:
 libmailutils/base/locker.c         |   32 +++++-
 libmu_sieve/extensions/moderator.c |    2 +-
 libmu_sieve/extensions/vacation.c  |  256 +++++++++++++++++++++++-------------
 libmu_sieve/sieve.y                |   26 ++++-
 maidag/lmtp.c                      |    2 +-
 mh/burst.c                         |    1 -
 mh/mh_stream.c                     |    1 +
 mh/prompter.c                      |    1 +
 sieve/sieve.c                      |    1 +
 testsuite/smtpsend.c               |    1 +
 10 files changed, 226 insertions(+), 97 deletions(-)

diff --git a/libmailutils/base/locker.c b/libmailutils/base/locker.c
index dc33fdc..5f34947 100644
--- a/libmailutils/base/locker.c
+++ b/libmailutils/base/locker.c
@@ -447,7 +447,37 @@ mu_locker_create (mu_locker_t *plocker, const char *fname, 
int flags)
     return EINVAL;
 
   if ((err = mu_unroll_symlink (fname, &filename)))
-    return err;
+    {
+      if (err == ENOENT)
+       {
+         /* Try the directory part.  If it unrolls successfully (i.e.
+            all its components exist), tuck the filename part back in
+            the resulting path and use it as the lock filename. */
+         char *p, *tmp = strdup (fname);
+         if (!tmp)
+           return ENOMEM;
+         p = strchr (tmp, '/');
+         if (!p)
+           filename = tmp;
+         else
+           {
+             err = mu_unroll_symlink (tmp, &filename);
+             free (tmp);
+             if (err)
+               return err;
+             tmp = realloc (filename, strlen (filename) + strlen (p) + 1);
+             if (!tmp)
+               {
+                 free (filename);
+                 return ENOMEM;
+               }
+             strcat (tmp, p);
+             filename = tmp;
+           }
+       }
+      else
+       return err;
+    }
 
   l = calloc (1, sizeof (*l));
 
diff --git a/libmu_sieve/extensions/moderator.c 
b/libmu_sieve/extensions/moderator.c
index 760cf96..dfba761 100644
--- a/libmu_sieve/extensions/moderator.c
+++ b/libmu_sieve/extensions/moderator.c
@@ -239,6 +239,7 @@ moderator_message_get_part (mu_sieve_machine_t mach,
       mu_body_get_streamref (body, &str);
 
       rc = mu_stream_to_message (str, pmsg);
+      mu_stream_destroy (&str);
       if (rc)
        {
          mu_sieve_error (mach,
@@ -246,7 +247,6 @@ moderator_message_get_part (mu_sieve_machine_t mach,
                          mu_strerror (rc));
          return 1;
        }
-      mu_stream_destroy (&str);
     }
   else if (value)
     {
diff --git a/libmu_sieve/extensions/vacation.c 
b/libmu_sieve/extensions/vacation.c
index 6f63f65..75dabfe 100644
--- a/libmu_sieve/extensions/vacation.c
+++ b/libmu_sieve/extensions/vacation.c
@@ -97,7 +97,6 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, 
mu_mime_t *pmime,
       return 1;
     }
 
-  mu_stream_seek (input, 0, MU_SEEK_SET, NULL);
   rc = mu_stream_copy (stream, input, 0, NULL);
   if (rc)
     {
@@ -140,7 +139,8 @@ diag (mu_sieve_machine_t mach)
 }
 
 
-struct addr_data {
+struct addr_data
+{
   mu_address_t addr;
   char *my_address;
 };
@@ -159,38 +159,38 @@ _compare (void *item, void *data)
    of the originating mail. Return non-zero if so and store a pointer
    to the matching address to *MY_ADDRESS. */
 static int
-match_addresses (mu_header_t hdr, mu_sieve_value_t *addresses, char 
**my_address)
+match_addresses (mu_header_t hdr, mu_sieve_value_t *addresses,
+                char **my_address)
 {
   int match = 0;
-  char *str;
+  const char *str;
   struct addr_data ad;
 
   ad.my_address = NULL;
-  if (mu_header_aget_value (hdr, MU_HEADER_TO, &str) == 0)
+  if (mu_header_sget_value (hdr, MU_HEADER_TO, &str) == 0)
     {
       if (!mu_address_create (&ad.addr, str))
        {
          match += mu_sieve_vlist_do (addresses, _compare, &ad);
          mu_address_destroy (&ad.addr);
        }
-      free (str);
     }
 
-  if (!match && mu_header_aget_value (hdr, MU_HEADER_CC, &str) == 0)
+  if (!match && mu_header_sget_value (hdr, MU_HEADER_CC, &str) == 0)
     {
       if (!mu_address_create (&ad.addr, str))
        {
          match += mu_sieve_vlist_do (addresses, _compare, &ad);
          mu_address_destroy (&ad.addr);
        }
-      free (str);
     }
   *my_address = ad.my_address;
   return match;
 }
 
 
-struct regex_data {
+struct regex_data
+{
   mu_sieve_machine_t mach;
   char *email;
 };
@@ -253,109 +253,162 @@ static int
 bulk_precedence_p (mu_header_t hdr)
 {
   int rc = 0;
-  char *str;
-  if (mu_header_aget_value (hdr, MU_HEADER_PRECEDENCE, &str) == 0)
+  const char *str;
+  if (mu_header_sget_value (hdr, MU_HEADER_PRECEDENCE, &str) == 0)
     {
       rc = mu_c_strcasecmp (str, "bulk") == 0
           || mu_c_strcasecmp (str, "junk") == 0;
-      free (str);
     }
   return rc;
 }
 
-#define        DAYS_MIN        1
 #define        DAYS_DEFAULT    7
 #define        DAYS_MAX        60
 
-/* Check and updated vacation database. Return 0 if the mail should
-   be answered. */
+static int
+test_and_update_prop (mu_property_t prop, const char *from,
+                     time_t now, unsigned int days,
+                     mu_sieve_machine_t mach)
+{
+  const char *result;
+  char *timebuf;
+  time_t last;
+  
+  int rc = mu_property_sget_value (prop, from, &result);
+  switch (rc)
+    {
+    case MU_ERR_NOENT:
+      break;
+      
+    case 0:
+      if (days == 0)
+       return 1;
+      last = (time_t) strtoul (result, NULL, 0);
+      if (last + (24 * 60 * 60 * days) > now)
+       return 1;
+      break;
+      
+    default:
+      mu_sieve_error (mach, "%lu: mu_property_sget_value: %s",
+                     (unsigned long) mu_sieve_get_message_num (mach),
+                     mu_strerror (rc));
+      return -1;
+    }
+
+  rc = mu_asprintf (&timebuf, "%lu", (unsigned long) now);
+  if (rc)
+    {
+      mu_sieve_error (mach, "%lu: mu_asprintf: %s",
+                     (unsigned long) mu_sieve_get_message_num (mach),
+                     mu_strerror (rc));
+      return -1;
+    } 
+     
+  rc = mu_property_set_value (prop, from, timebuf, 1);
+  free (timebuf);
+  if (rc)
+    {
+      mu_sieve_error (mach, "%lu: mu_property_set_value: %s",
+                     (unsigned long) mu_sieve_get_message_num (mach),
+                     mu_strerror (rc));
+      return -1;
+    }
+  
+  rc = mu_property_save (prop);
+  if (rc)
+    {
+      mu_sieve_error (mach, "%lu: mu_property_save: %s",
+                     (unsigned long) mu_sieve_get_message_num (mach),
+                     mu_strerror (rc));
+      return -1;
+    }
+  return 0;
+}
+
+/* Check and update the vacation database. Return 0 if the mail should
+   be answered, 0 if it should not, and throw exception if an error
+   occurs. */
 static int
 check_db (mu_sieve_machine_t mach, mu_list_t tags, char *from)
 {
-#ifdef USE_DBM
-  DBM_FILE db;
-  DBM_DATUM key, value;
-  time_t now;
-  char buffer[64];
-  char *file, *home;
+  mu_property_t prop;
+  char *file;
   mu_sieve_value_t *arg;
   unsigned int days;
+  time_t now;
   int rc;
+  mu_stream_t str;
+  mu_locker_t locker;
   
   if (mu_sieve_tag_lookup (tags, "days", &arg))
     {
-      days = arg->v.number;
-      if (days < DAYS_MIN)
-       days = DAYS_MIN;
-      else if (days > DAYS_MAX)
+      if (days > DAYS_MAX)
        days = DAYS_MAX;
     }
   else
     days = DAYS_DEFAULT;
 
-  home = mu_get_homedir ();
-
-  file = mu_make_file_name (home ? home : ".", ".vacation");
+  file = mu_tilde_expansion ("~/.vacation", "/", NULL);
   if (!file)
     {
       mu_sieve_error (mach, _("%lu: cannot build db file name"),
                      (unsigned long) mu_sieve_get_message_num (mach));
-      free (home);
       mu_sieve_abort (mach);
     }
-  free (home);
-  
-  rc = mu_dbm_open (file, &db, MU_STREAM_RDWR, 0600);
+
+  rc = mu_locker_create (&locker, file, 0);
   if (rc)
     {
-      mu_sieve_error (mach,
-                     _("%lu: cannot open `%s': %s"),
-                     (unsigned long) mu_sieve_get_message_num (mach), file,
+      mu_sieve_error (mach, _("%lu: cannot lock %s: %s"),
+                     (unsigned long) mu_sieve_get_message_num (mach),
+                     file,
                      mu_strerror (rc));
       free (file);
       mu_sieve_abort (mach);
     }
-  free (file);
 
-  time (&now);
-
-  MU_DATUM_SIZE (key) = strlen (from);
-  MU_DATUM_PTR (key) = from;
-
-  rc = mu_dbm_fetch (db, key, &value);
-  if (!rc)
+  rc = mu_file_stream_create (&str, file, MU_STREAM_RDWR|MU_STREAM_CREAT);
+  if (rc)
     {
-      time_t last;
-      
-      strncpy(buffer, MU_DATUM_PTR (value), MU_DATUM_SIZE (value));
-      buffer[MU_DATUM_SIZE (value)] = 0;
-
-      last = (time_t) strtoul (buffer, NULL, 0);
+      mu_sieve_error (mach, "%lu: mu_file_stream_create(%s): %s",
+                     (unsigned long) mu_sieve_get_message_num (mach),
+                     file,
+                     mu_strerror (rc));
+      mu_locker_destroy (&locker);
+      free (file);
+      mu_sieve_abort (mach);
+    }
+  
+  free (file);
 
+  rc = mu_property_create_init (&prop, mu_assoc_property_init, str);
+  if (rc)
+    {
+      mu_sieve_error (mach, "%lu: mu_property_create_init: %s",
+                     (unsigned long) mu_sieve_get_message_num (mach),
+                     mu_strerror (rc));
+      mu_locker_destroy (&locker);
+      mu_sieve_abort (mach);
+    }
 
-      if (last + (24 * 60 * 60 * days) > now)
-       {
-         mu_dbm_close (db);
-         return 1;
-       }
+  rc = mu_locker_lock (locker);
+  if (rc)
+    {
+      mu_sieve_error (mach, "%lu: cannot lock vacation database: %s",
+                     (unsigned long) mu_sieve_get_message_num (mach),
+                     mu_strerror (rc));
+      mu_property_destroy (&prop);
+      mu_sieve_abort (mach);
     }
 
-  MU_DATUM_SIZE (value) = snprintf (buffer, sizeof buffer, "%ld", now);
-  MU_DATUM_PTR (value) = buffer;
-  MU_DATUM_SIZE (key) = strlen (from);
-  MU_DATUM_PTR (key) = from;
+  rc = test_and_update_prop (prop, from, now, days, mach);
+  mu_property_destroy (&prop);
+  mu_locker_unlock (locker);
+  mu_locker_destroy (&locker);
+  if (rc == -1)
+    mu_sieve_abort (mach);
 
-  mu_dbm_insert (db, key, value, 1);
-  mu_dbm_close (db);
-  return 0;
-#else
-  mu_sieve_error (mach,
-              /* TRANSLATORS: 'vacation' and ':days' are Sieve keywords.
-                 Do not translate them! */
-              _("%d: vacation compiled without DBM support. Ignoring :days 
tag"),
-              mu_sieve_get_message_num (mach));
-  return 0;
-#endif
+  return rc;
 }
 
 /* Add a reply prefix to the subject. *PSUBJECT points to the
@@ -411,7 +464,8 @@ vacation_subject (mu_sieve_machine_t mach, mu_list_t tags,
   if (mu_sieve_tag_lookup (tags, "subject", &arg))
     subject =  arg->v.string;
   else if (mu_message_get_header (msg, &hdr) == 0
-          && mu_header_aget_value_unfold (hdr, MU_HEADER_SUBJECT, &value) == 0)
+          && mu_header_aget_value_unfold (hdr, MU_HEADER_SUBJECT,
+                                          &value) == 0)
     {
       char *p;
       
@@ -436,9 +490,7 @@ vacation_subject (mu_sieve_machine_t mach, mu_list_t tags,
          if (rc)
            {
              mu_sieve_error (mach,
-                             /* TRANSLATORS: 'vacation' is the name of the
-                                Sieve action. Do not translate it! */
-                             _("%lu: vacation - cannot compile reply prefix 
regexp: %s: %s"),
+                             _("%lu: cannot compile reply prefix regexp: %s: 
%s"),
                              (unsigned long) mu_sieve_get_message_num (mach),
                              mu_strerror (rc),
                              err ? err : "");
@@ -478,11 +530,40 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, 
mu_message_t msg,
   char *value;
   mu_mailer_t mailer;
   int rc;
-  
-  if (build_mime (mach, tags, &mime, msg, text))
-    return -1;
-  mu_mime_get_message (mime, &newmsg);
-  mu_message_get_header (newmsg, &newhdr);
+
+  if (mu_sieve_tag_lookup (tags, "file", NULL))
+    {
+      mu_stream_t instr;
+      
+      rc = mu_mapfile_stream_create (&instr, text, MU_STREAM_READ);
+      if (rc)
+       {
+         mu_sieve_error (mach,
+                         _("%lu: cannot open message file %s: %s"),
+                         (unsigned long) mu_sieve_get_message_num (mach),
+                         text,
+                         mu_strerror (rc));
+         return -1;
+       }
+      rc = mu_stream_to_message (instr, &newmsg);
+      mu_stream_unref (instr);
+      if (rc)
+       {
+         mu_sieve_error (mach,
+                         _("%lu: cannot read message from file %s: %s"),
+                         (unsigned long) mu_sieve_get_message_num (mach),
+                         text,
+                         mu_strerror (rc));
+         return -1;
+       } 
+    }
+  else
+    {
+      if (build_mime (mach, tags, &mime, msg, text))
+       return -1;
+      mu_mime_get_message (mime, &newmsg);
+      mu_message_get_header (newmsg, &newhdr);
+    }
   
   rc = mu_address_create (&to_addr, to);
   if (rc)
@@ -521,23 +602,12 @@ vacation_reply (mu_sieve_machine_t mach, mu_list_t tags, 
mu_message_t msg,
         }
       
       mailer = mu_sieve_get_mailer (mach);
-      rc = mu_mailer_open (mailer, 0);
-      if (rc)
-       {
-         mu_url_t url = NULL;
-         mu_mailer_get_url (mailer, &url);
-      
-         mu_sieve_error (mach,
-                         _("%lu: cannot open mailer %s: %s"),
-                         (unsigned long) mu_sieve_get_message_num (mach),
-                         mu_url_to_string (url), mu_strerror (rc));
-       }
-      else
+      if (mailer)
        {
          rc = mu_mailer_send_message (mailer, newmsg, from_addr, to_addr);
-         mu_mailer_close (mailer);
        }
-      mu_mailer_destroy (&mailer);
+      else
+       rc = MU_ERR_FAILURE;
     }
   mu_address_destroy (&to_addr);
   mu_address_destroy (&from_addr);
@@ -610,7 +680,9 @@ static mu_sieve_tag_def_t vacation_tags[] = {
   {"addresses", SVT_STRING_LIST},
   {"reply_regex", SVT_STRING},
   {"reply_prefix", SVT_STRING},
+  {"sender", SVT_STRING},
   {"mime", SVT_VOID},
+  {"file", SVT_VOID},
   {NULL}
 };
 
diff --git a/libmu_sieve/sieve.y b/libmu_sieve/sieve.y
index 79ae1fb..45bc090 100644
--- a/libmu_sieve/sieve.y
+++ b/libmu_sieve/sieve.y
@@ -465,7 +465,31 @@ mu_mailer_t
 mu_sieve_get_mailer (mu_sieve_machine_t mach)
 {
   if (!mach->mailer)
-    mu_mailer_create (&mach->mailer, NULL);
+    {
+      int rc;
+
+      rc = mu_mailer_create (&mach->mailer, NULL);
+      if (rc)
+       {
+         mu_sieve_error (mach,
+                         _("%lu: cannot create mailer: %s"),
+                         (unsigned long) mu_sieve_get_message_num (mach),
+                         mu_strerror (rc));
+         return NULL;
+       }
+      rc = mu_mailer_open (mach->mailer, 0);
+      if (rc)
+       {
+         mu_url_t url = NULL;
+         mu_mailer_get_url (mach->mailer, &url);
+         mu_sieve_error (mach,
+                         _("%lu: cannot open mailer %s: %s"),
+                         (unsigned long) mu_sieve_get_message_num (mach),
+                         mu_url_to_string (url), mu_strerror (rc));
+         mu_mailer_destroy (&mach->mailer);
+         return NULL;
+       }
+    }
   return mach->mailer;
 }
 
diff --git a/maidag/lmtp.c b/maidag/lmtp.c
index 692ef16..b3c0fc4 100644
--- a/maidag/lmtp.c
+++ b/maidag/lmtp.c
@@ -416,6 +416,7 @@ cfun_data (mu_stream_t iostr, char *arg)
     }
 
   rc = mu_stream_to_message (tempstr, &mesg);
+  mu_stream_unref (tempstr);
   if (rc)
     {
       maidag_error (_("error creating temporary message: %s"),
@@ -425,7 +426,6 @@ cfun_data (mu_stream_t iostr, char *arg)
   
   rc = mu_list_do (rcpt_list, dot_deliver, iostr);
 
-  mu_stream_destroy (&tempstr);
   mu_message_destroy (&mesg, mu_message_get_owner (mesg));
   if (rc)
     mu_list_do (rcpt_list, dot_temp_fail, iostr);
diff --git a/mh/burst.c b/mh/burst.c
index 16f147d..47449d0 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -379,7 +379,6 @@ finish_stream (struct burst_stream *bs)
        mu_mailbox_uidnext (tmpbox, &map.first);
       burst_or_copy (msg, recursive, 1);
       mu_message_destroy (&msg, mu_message_get_owner (msg));
-      mu_stream_unref (bs->stream);
       bs->stream = 0;
       
       bs->partno++;
diff --git a/mh/mh_stream.c b/mh/mh_stream.c
index 9878503..2448f82 100644
--- a/mh/mh_stream.c
+++ b/mh/mh_stream.c
@@ -30,6 +30,7 @@ mh_stream_to_message (mu_stream_t instream)
   mu_message_t msg;
 
   rc = mu_stream_to_message (instream, &msg);
+  mu_stream_unref (instream);
   if (rc)
     {
       mu_error (_("cannot open draft message stream: %s"),
diff --git a/mh/prompter.c b/mh/prompter.c
index 4a1ede2..1327ebe 100644
--- a/mh/prompter.c
+++ b/mh/prompter.c
@@ -186,6 +186,7 @@ main (int argc, char **argv)
       return 1;
     }
   rc = mu_stream_to_message (in, &msg);
+  mu_stream_unref (in);
   if (rc)
     {
       mu_error (_("input stream %s is not a message (%s)"),
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 8e3f337..50d1706 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -355,6 +355,7 @@ sieve_message (mu_sieve_machine_t mach)
       return EX_SOFTWARE;
     }
   rc = mu_stream_to_message (instr, &msg);
+  mu_stream_unref (instr);
   if (rc)
     {
       mu_error (_("cannot create message from stream: %s"),
diff --git a/testsuite/smtpsend.c b/testsuite/smtpsend.c
index 058c290..0df5431 100644
--- a/testsuite/smtpsend.c
+++ b/testsuite/smtpsend.c
@@ -268,6 +268,7 @@ main (int argc, char **argv)
        mu_list_set_comparator (skiphdr_list, headercmp);
       
       MU_ASSERT (mu_stream_to_message (instr, &msg));
+      mu_stream_unref (instr);
       MU_ASSERT (mu_smtp_data (smtp, &ostr));
       MU_ASSERT (mu_message_get_header (msg, &hdr));
       MU_ASSERT (mu_header_get_iterator (hdr, &itr));


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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