commit-mailutils
[Top][All Lists]
Advanced

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

[SCM] GNU Mailutils branch, master, updated. rel-2_1-58-g52fffeb


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. rel-2_1-58-g52fffeb
Date: Thu, 01 Apr 2010 20:14:41 +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=52fffebc9d359125c21130d93a67b225b4778457

The branch, master has been updated
       via  52fffebc9d359125c21130d93a67b225b4778457 (commit)
       via  c73e770c70d3e358e65759130d7fdff047750a69 (commit)
      from  832dad5395744b45ed705d8b9bab6432cdbf7d0e (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 52fffebc9d359125c21130d93a67b225b4778457
Author: Sergey Poznyakoff <address@hidden>
Date:   Thu Apr 1 23:12:33 2010 +0300

    Implement mailbox iterators in Scheme.
    
    * libmu_scm/mu_mailbox.c (struct mu_mailbox)<itr>: New member.
    (mu_scm_mailbox_free): Destroy the iterator.
    (mu_scm_mailbox_create0): Initialize itr to NULL.
    (mu-mailbox-first-message, mu-mailbox-next-message)
    (mu-mailbox-more-messages?): New function.
    * guimb/scm/sieve-core.scm (sieve-run): Rewrite
    main loop in the True Schemish Way.

commit c73e770c70d3e358e65759130d7fdff047750a69
Author: Sergey Poznyakoff <address@hidden>
Date:   Thu Apr 1 21:39:24 2010 +0300

    Implement mailbox iterators.
    
    * include/mailutils/mailbox.h (mu_mailbox_get_iterator): New function.
    * libproto/include/mailbox0.h (struct _mu_mailbox)<iterator>: New
    member.
    * mailbox/mbxitr.c: New file.
    * mailbox/Makefile.am (libmailutils_la_SOURCES): Add mbxitr.c

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

Summary of changes:
 guimb/scm/sieve-core.scm    |   17 +++--
 include/mailutils/mailbox.h |    3 +
 libmu_scm/mu_mailbox.c      |  109 +++++++++++++++++++++++++++++
 libproto/include/mailbox0.h |    4 +-
 mailbox/Makefile.am         |    1 +
 mailbox/mbxitr.c            |  160 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 285 insertions(+), 9 deletions(-)
 create mode 100644 mailbox/mbxitr.c

diff --git a/guimb/scm/sieve-core.scm b/guimb/scm/sieve-core.scm
index 5a11c65..f5f335c 100644
--- a/guimb/scm/sieve-core.scm
+++ b/guimb/scm/sieve-core.scm
@@ -472,14 +472,15 @@
   (if (not sieve-my-email)
       (set! sieve-my-email (mu-username->email)))
 ;  (DEBUG 1 "Mailbox: " sieve-mailbox)
-  
-  (let ((count (mu-mailbox-messages-count sieve-mailbox)))
-    (do ((n 1 (1+ n)))
-       ((> n count) #f)
-       (set! sieve-current-message
-             (mu-mailbox-get-message sieve-mailbox n))
-       (sieve-run-current-message thunk))
-    (sieve-close-mailboxes)))
+
+  (let msg-loop ((msg (mu-mailbox-first-message sieve-mailbox)))
+    (if (not (eof-object? msg))
+       (begin
+         (set! sieve-current-message msg)
+         (sieve-run-current-message thunk)
+         (msg-loop (mu-mailbox-next-message sieve-mailbox)))))
+
+  (sieve-close-mailboxes))
 
 (define (sieve-command-line)
   (catch #t
diff --git a/include/mailutils/mailbox.h b/include/mailutils/mailbox.h
index d554c9b..d3aa895 100644
--- a/include/mailutils/mailbox.h
+++ b/include/mailutils/mailbox.h
@@ -107,6 +107,9 @@ extern int  mu_mailbox_get_observable  (mu_mailbox_t, 
mu_observable_t *);
 /* Locking */  
 extern int mu_mailbox_lock (mu_mailbox_t mbox);
 extern int mu_mailbox_unlock (mu_mailbox_t mbox);
+
+extern int mu_mailbox_get_iterator (mu_mailbox_t mbx,
+                                   mu_iterator_t *piterator);
   
 #ifdef __cplusplus
 }
diff --git a/libmu_scm/mu_mailbox.c b/libmu_scm/mu_mailbox.c
index 8a54fda..663755e 100644
--- a/libmu_scm/mu_mailbox.c
+++ b/libmu_scm/mu_mailbox.c
@@ -18,6 +18,7 @@
    Boston, MA 02110-1301 USA */
 
 #include "mu_scm.h"
+#include <mailutils/iterator.h>
 
 static scm_t_bits mailbox_tag;
 
@@ -26,6 +27,7 @@ static scm_t_bits mailbox_tag;
 struct mu_mailbox
 {
   mu_mailbox_t mbox;       /* Mailbox */
+  mu_iterator_t itr;
   int noclose;
 };
 
@@ -40,6 +42,9 @@ static scm_sizet
 mu_scm_mailbox_free (SCM mailbox_smob)
 {
   struct mu_mailbox *mum = (struct mu_mailbox *) SCM_CDR (mailbox_smob);
+
+  mu_iterator_destroy (&mum->itr);
+  
   if (!mum->noclose)
     {
       mu_mailbox_close (mum->mbox);
@@ -112,6 +117,7 @@ mu_scm_mailbox_create0 (mu_mailbox_t mbox, int noclose)
 
   mum = scm_gc_malloc (sizeof (struct mu_mailbox), "mailbox");
   mum->mbox = mbox;
+  mum->itr = NULL;
   mum->noclose = noclose;
   SCM_RETURN_NEWSMOB (mailbox_tag, mum);
 }
@@ -409,6 +415,109 @@ SCM_DEFINE (scm_mu_mailbox_append_message, 
"mu-mailbox-append-message", 2, 0, 0,
 }
 #undef FUNC_NAME
 
+/* Iterations */
+#define ITROP(op, descr)                       \
+  do                                           \
+    {                                          \
+      int status = op;                         \
+      if (status == MU_ERR_NOENT)              \
+       return SCM_EOF_VAL;                     \
+      if (status)                              \
+       mu_scm_error (FUNC_NAME, status,        \
+                     "~A: " descr ": ~A",      \
+                     scm_list_2 (MBOX,         \
+                                 scm_from_locale_string (mu_strerror 
(status)))); \
+    }                                                                  \
+  while (0)
+
+SCM_DEFINE (scm_mu_mailbox_first_message, "mu-mailbox-first-message", 1, 0, 0,
+           (SCM MBOX),
+           "Returns first message from the mailbox.")
+#define FUNC_NAME s_scm_mu_mailbox_first_message
+{
+  struct mu_mailbox *mum;
+  int status;
+  mu_message_t msg;
+  
+  SCM_ASSERT (mu_scm_is_mailbox (MBOX), MBOX, SCM_ARG1, FUNC_NAME);
+  mum = (struct mu_mailbox *) SCM_CDR (MBOX);
+  if (!mum->itr)
+    {
+      status = mu_mailbox_get_iterator (mum->mbox, &mum->itr);
+      if (status)
+       mu_scm_error (FUNC_NAME, status,
+                     "~A: cannot create iterator: ~A",
+                     scm_list_2 (MBOX,
+                                 scm_from_locale_string (mu_strerror 
(status))));
+    }
+  ITROP (mu_iterator_first (mum->itr), "moving to the first message");
+  ITROP (mu_iterator_current (mum->itr, (void**)&msg),
+        "getting current message");
+  return mu_scm_message_create (MBOX, msg);
+}
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_mu_mailbox_next_message, "mu-mailbox-next-message", 1, 0, 0,
+           (SCM MBOX),
+           "Returns next message from the mailbox.")
+#define FUNC_NAME s_scm_mu_mailbox_next_message
+{
+  struct mu_mailbox *mum;
+  int status;
+  mu_message_t msg;
+  
+  SCM_ASSERT (mu_scm_is_mailbox (MBOX), MBOX, SCM_ARG1, FUNC_NAME);
+  mum = (struct mu_mailbox *) SCM_CDR (MBOX);
+  if (!mum->itr)
+    {
+      status = mu_mailbox_get_iterator (mum->mbox, &mum->itr);
+      if (status)
+       mu_scm_error (FUNC_NAME, status,
+                     "~A: cannot create iterator: ~A",
+                     scm_list_2 (MBOX,
+                                 scm_from_locale_string (mu_strerror 
(status))));
+      ITROP (mu_iterator_first (mum->itr), "moving to the first message");
+    }
+  else
+    ITROP (mu_iterator_next (mum->itr), "advancing iterator");
+  
+  ITROP (mu_iterator_current (mum->itr, (void**)&msg),
+        "getting current message");
+  return mu_scm_message_create (MBOX, msg);
+}
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_mu_mailbox_more_messages_p, "mu-mailbox-more-messages?", 1, 0, 
0,
+           (SCM MBOX),
+           "Returns next message from the mailbox.")
+#define FUNC_NAME s_scm_mu_mailbox_more_messages_p
+{
+  struct mu_mailbox *mum;
+  int status;
+  
+  SCM_ASSERT (mu_scm_is_mailbox (MBOX), MBOX, SCM_ARG1, FUNC_NAME);
+  mum = (struct mu_mailbox *) SCM_CDR (MBOX);
+  if (!mum->itr)
+    {
+      status = mu_mailbox_get_iterator (mum->mbox, &mum->itr);
+      if (status)
+       mu_scm_error (FUNC_NAME, status,
+                     "~A: cannot create iterator: ~A",
+                     scm_list_2 (MBOX,
+                                 scm_from_locale_string (mu_strerror 
(status))));
+      status = mu_iterator_first (mum->itr);
+      if (status == MU_ERR_NOENT)
+       return SCM_BOOL_F;
+      if (status)
+       mu_scm_error (FUNC_NAME, status,
+                     "~A: cannot set iterator to the first message: ~A",
+                     scm_list_2 (MBOX,
+                                 scm_from_locale_string (mu_strerror 
(status))));
+    }
+  return scm_from_bool (!!mu_iterator_is_done (mum->itr));
+}
+#undef FUNC_NAME
+
 /* Initialize the module */
 void
 mu_scm_mailbox_init ()
diff --git a/libproto/include/mailbox0.h b/libproto/include/mailbox0.h
index bbe25f1..a052e43 100644
--- a/libproto/include/mailbox0.h
+++ b/libproto/include/mailbox0.h
@@ -29,6 +29,7 @@
 
 #include <mailutils/monitor.h>
 #include <mailutils/mailbox.h>
+#include <mailutils/iterator.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -46,7 +47,8 @@ struct _mu_mailbox
   int flags;
   mu_folder_t folder;
   mu_monitor_t monitor;
-
+  mu_iterator_t iterator;
+  
   /* Back pointer to the specific mailbox */
   void *data;
 
diff --git a/mailbox/Makefile.am b/mailbox/Makefile.am
index 845bc58..5146528 100644
--- a/mailbox/Makefile.am
+++ b/mailbox/Makefile.am
@@ -95,6 +95,7 @@ libmailutils_la_SOURCES = \
  mailer.c\
  mapfile_stream.c\
  mbx_default.c\
+ mbxitr.c\
  md5.c\
  message.c\
  memory_stream.c\
diff --git a/mailbox/mbxitr.c b/mailbox/mbxitr.c
new file mode 100644
index 0000000..6137e12
--- /dev/null
+++ b/mailbox/mbxitr.c
@@ -0,0 +1,160 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library; if not, write to the
+   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301 USA */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include <mailutils/debug.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/iterator.h>
+
+#include <mailbox0.h>
+
+struct mailbox_iterator
+{
+  mu_mailbox_t mbx;
+  size_t idx;
+};
+
+static int
+mbx_first (void *owner)
+{
+  struct mailbox_iterator *itr = owner;
+  itr->idx = 1;
+  return 0;
+}
+
+static int
+mbx_next (void *owner)
+{
+  struct mailbox_iterator *itr = owner;
+  itr->idx++;
+  return 0;
+}
+
+static int
+mbx_getitem (void *owner, void **pret, const void **pkey)
+{
+  struct mailbox_iterator *itr = owner;
+  size_t count;
+  int rc;
+  
+  rc = mu_mailbox_messages_count (itr->mbx, &count);
+  if (rc)
+    return rc;
+  if (itr->idx > count)
+    return MU_ERR_NOENT;
+  rc = mu_mailbox_get_message (itr->mbx, itr->idx, (mu_message_t*)pret);
+  if (rc == 0 && pkey)
+    *pkey = NULL; /* FIXME: Perhaps return UIDL or other unique id? */
+  return rc;
+}
+
+static int
+mbx_finished_p (void *owner)
+{
+  struct mailbox_iterator *itr = owner;
+  size_t count;
+
+  if (mu_mailbox_messages_count (itr->mbx, &count))
+    return 1;
+  return itr->idx > count;
+}
+
+static int
+mbx_destroy (mu_iterator_t iterator, void *data)
+{
+  struct mailbox_iterator *itr = data;
+
+  mu_iterator_detach (&itr->mbx->iterator, iterator);
+  free (data);
+  return 0;
+}
+
+static int
+mbx_curitem_p (void *owner, void *item)
+{
+  void *ptr;
+
+  if (mbx_getitem (owner, &ptr, NULL))
+    return 0;
+  return ptr == item;/* FIXME: Is it ok? */
+}
+
+static int
+mbx_data_dup (void **ptr, void *owner)
+{
+  struct mailbox_iterator *itr = owner;
+
+  *ptr = malloc (sizeof (struct mailbox_iterator));
+  if (*ptr == NULL)
+    return ENOMEM;
+  memcpy (*ptr, owner, sizeof (struct mailbox_iterator));
+  mu_iterator_attach (&itr->mbx->iterator, *ptr);
+  return 0;
+}
+
+int
+mu_mailbox_get_iterator (mu_mailbox_t mbx, mu_iterator_t *piterator)
+{
+  mu_iterator_t iterator;
+  int status;
+  struct mailbox_iterator *itr;
+
+  if (!mbx)
+    return EINVAL;
+
+  itr = calloc (1, sizeof *itr);
+  if (!itr)
+    return ENOMEM;
+  itr->mbx = mbx;
+  itr->idx = 1;
+
+  status = mu_iterator_create (&iterator, itr);
+  if (status)
+    {
+      free (itr);
+      return status;
+    }
+
+  mu_iterator_set_first (iterator, mbx_first);
+  mu_iterator_set_next (iterator, mbx_next);
+  mu_iterator_set_getitem (iterator, mbx_getitem);
+  mu_iterator_set_finished_p (iterator, mbx_finished_p);
+  mu_iterator_set_curitem_p (iterator, mbx_curitem_p);
+  mu_iterator_set_destroy (iterator, mbx_destroy);
+  mu_iterator_set_dup (iterator, mbx_data_dup);
+
+  mu_iterator_attach (&mbx->iterator, iterator);
+
+  *piterator = iterator;
+  return 0;
+}
+
+
+
+
+
+  
+


hooks/post-receive
-- 
GNU Mailutils




reply via email to

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