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-548-g2b62203


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-548-g2b62203
Date: Fri, 23 Dec 2011 15:26:39 +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=2b62203b38aebd3cac815de74813a0bbacb086a6

The branch, master has been updated
       via  2b62203b38aebd3cac815de74813a0bbacb086a6 (commit)
      from  e4dc7185c62a3042b9a05828be83c1f1ca308dcb (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 2b62203b38aebd3cac815de74813a0bbacb086a6
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Dec 23 17:10:58 2011 +0200

    Finish imap mailbox implementation.
    
    Some features are missing (notably, quick access), but overall the
    implementation offers all necessary features and performs a lot
    better than 2.x.
    
    Additionally, this commit fixes a minor bug in the imap4d implementation:
    the STORE command did not accept empty flag list.
    
    * NEWS: Update.
    * imap4d/store.c (store_thunk): Accept empty list as "items" argument.
    
    * include/mailutils/imap.h (mu_imap_store_flags): New proto.
    * include/mailutils/imaputil.h (mu_imap_format_flags): Add new argument.
    * include/mailutils/sys/imap.h (_MU_IMAP_MSG_ATTRCHG): New flag.
    * libmailutils/imapio/flags.c: Accept three arguments, last one being
    a boolean flag specifying whether we want \Recent in the output.
    * libproto/imap/storeflg.c: New flag.
    * libproto/imap/Makefile.am (libmu_imap_la_SOURCES): Add storeflg.c.
    * libproto/imap/mbox.c: Finish the basic implementation.
    
    * imap4d/sync.c: Update calls to mu_imap_format_flags.
    * imap4d/util.c: Likewise.
    * mu/imap.c: Likewise.
    * libmailutils/imapio/sendflg.c (mu_imapio_send_flags): Likewise.

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

Summary of changes:
 NEWS                                  |    5 +-
 imap4d/store.c                        |   16 +-
 imap4d/sync.c                         |    2 +-
 imap4d/util.c                         |    2 +-
 include/mailutils/imap.h              |   10 +
 include/mailutils/imaputil.h          |    2 +-
 include/mailutils/sys/imap.h          |    7 +-
 libmailutils/imapio/flags.c           |    4 +-
 libmailutils/imapio/sendflg.c         |    2 +-
 libproto/imap/Makefile.am             |    1 +
 libproto/imap/mbox.c                  |  295 ++++++++++++++++++++++++++-------
 libproto/imap/{login.c => storeflg.c} |   58 ++++----
 mu/imap.c                             |    6 +-
 13 files changed, 295 insertions(+), 115 deletions(-)
 copy libproto/imap/{login.c => storeflg.c} (62%)

diff --git a/NEWS b/NEWS
index 25cf5d1..101f39a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU mailutils NEWS -- history of user-visible changes. 2011-12-17
+GNU mailutils NEWS -- history of user-visible changes. 2011-12-23
 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 Free Software Foundation, Inc.
 See the end of file for copying conditions.
@@ -23,7 +23,6 @@ Due to the global nature of these changes, the rewrite of 
some parts
 of the package is not yet finished, while some others are considered
 experimental.  Not currently implemented are:
 
- - imap client
  - nntp client
  
 Experimental features are:
@@ -144,7 +143,7 @@ It is normally not needed to specify --with-gdbm, 
--with-berkeley-db
 or --with-ndbm explicitly.  Configuration will automatically pick up
 all available DBM libraries it can use.
 
-** Imap and nntp clients are not yet implemented
+** Nntp client is not yet implemented
 
 ** Link with GSASL by default
 
diff --git a/imap4d/store.c b/imap4d/store.c
index 17f853c..20318b5 100644
--- a/imap4d/store.c
+++ b/imap4d/store.c
@@ -75,14 +75,14 @@ store_thunk (imap4d_parsebuf_t p)
   if (status)
     imap4d_parsebuf_exit (p, "Failed to parse message set");
 
-  if (p->token[0] != '(')
-    imap4d_parsebuf_exit (p, "Syntax error");
-  imap4d_parsebuf_next (p, 1);
-  
-  do
-    if (mu_imap_flag_to_attribute (p->token, &pclos->type))
-      imap4d_parsebuf_exit (p, "Unrecognized flag");
-  while (imap4d_parsebuf_next (p, 1) && p->token[0] != ')');
+  if (strcmp (p->token, "NIL"))
+    {
+      if (p->token[0] != '(')
+       imap4d_parsebuf_exit (p, "Syntax error");
+      while (imap4d_parsebuf_next (p, 1) && p->token[0] != ')')
+       if (mu_imap_flag_to_attribute (p->token, &pclos->type))
+         imap4d_parsebuf_exit (p, "Unrecognized flag");
+    }
   return RESP_OK;
 }
 
diff --git a/imap4d/sync.c b/imap4d/sync.c
index e14b015..d054f95 100644
--- a/imap4d/sync.c
+++ b/imap4d/sync.c
@@ -100,7 +100,7 @@ notify (void)
              if (nflags != attr_table[i-1])
                {
                  io_sendf ("* %lu FETCH FLAGS (",  (unsigned long) i);
-                 mu_imap_format_flags (iostream, nflags);
+                 mu_imap_format_flags (iostream, nflags, 1);
                  io_sendf (")\n");
                  attr_table[i-1] = nflags;
                }
diff --git a/imap4d/util.c b/imap4d/util.c
index 5ade76b..643d962 100644
--- a/imap4d/util.c
+++ b/imap4d/util.c
@@ -499,7 +499,7 @@ util_print_flags (mu_attribute_t attr)
   int flags = 0;
 
   mu_attribute_get_flags (attr, &flags);
-  mu_imap_format_flags (iostream, flags);
+  mu_imap_format_flags (iostream, flags, 1);
 }
 
 int
diff --git a/include/mailutils/imap.h b/include/mailutils/imap.h
index b6f9e57..2e8e371 100644
--- a/include/mailutils/imap.h
+++ b/include/mailutils/imap.h
@@ -71,6 +71,16 @@ int mu_imap_fetch (mu_imap_t imap, int uid, const char 
*msgset,
 int mu_imap_store (mu_imap_t imap, int uid, const char *msgset,
                   const char *items);
 
+#define MU_IMAP_STORE_SET 0
+#define MU_IMAP_STORE_ADD 1
+#define MU_IMAP_STORE_CLR 2
+#define MU_IMAP_STORE_SILENT 0x10
+
+#define MU_IMAP_STORE_OPMASK 0xf
+
+int mu_imap_store_flags (mu_imap_t imap, int uid, const char *msgset,
+                        int op, int flags);
+  
 int mu_imap_delete (mu_imap_t imap, const char *mailbox);
 int mu_imap_rename (mu_imap_t imap, const char *mailbox,
                    const char *new_mailbox);
diff --git a/include/mailutils/imaputil.h b/include/mailutils/imaputil.h
index 09ddce4..3f922dc 100644
--- a/include/mailutils/imaputil.h
+++ b/include/mailutils/imaputil.h
@@ -26,7 +26,7 @@ extern "C" {
 int mu_imap_wildmatch (const char *pattern, const char *name, int delim);
 
 int mu_imap_flag_to_attribute (const char *item, int *attr);
-int mu_imap_format_flags (mu_stream_t str, int flags);
+  int mu_imap_format_flags (mu_stream_t str, int flags, int include_recent);
 
 #ifdef __cplusplus
 }
diff --git a/include/mailutils/sys/imap.h b/include/mailutils/sys/imap.h
index a06e1b0..fd0f905 100644
--- a/include/mailutils/sys/imap.h
+++ b/include/mailutils/sys/imap.h
@@ -240,9 +240,10 @@ int _mu_imaps_url_init (mu_url_t url);
 
 int _mu_imap_mailbox_init (mu_mailbox_t mailbox);
 
-#define _MU_IMAP_MSG_SCANNED   0x01
-#define _MU_IMAP_MSG_CACHED    0x02
-#define _MU_IMAP_MSG_LINES     0x04
+#define _MU_IMAP_MSG_SCANNED   0x01 /* Message has already been scanned */
+#define _MU_IMAP_MSG_CACHED    0x02 /* Message is cached */
+#define _MU_IMAP_MSG_LINES     0x04 /* Number of lines is computed */
+#define _MU_IMAP_MSG_ATTRCHG   0x08 /* Message attributes has changed */
 
 struct _mu_imap_message
 {
diff --git a/libmailutils/imapio/flags.c b/libmailutils/imapio/flags.c
index 8bee66d..5d6188a 100644
--- a/libmailutils/imapio/flags.c
+++ b/libmailutils/imapio/flags.c
@@ -60,7 +60,7 @@ mu_imap_flag_to_attribute (const char *item, int *attr)
 }
 
 int
-mu_imap_format_flags (mu_stream_t str, int flags)
+mu_imap_format_flags (mu_stream_t str, int flags, int include_recent)
 {
   int i;
   int delim = 0;
@@ -74,7 +74,7 @@ mu_imap_format_flags (mu_stream_t str, int flags)
        delim = 1;
       }
 
-  if (MU_ATTRIBUTE_IS_UNSEEN (flags))
+  if (include_recent && MU_ATTRIBUTE_IS_UNSEEN (flags))
     {
       if (delim)
        mu_stream_printf (str, " ");
diff --git a/libmailutils/imapio/sendflg.c b/libmailutils/imapio/sendflg.c
index b4e0d3b..94cfe22 100644
--- a/libmailutils/imapio/sendflg.c
+++ b/libmailutils/imapio/sendflg.c
@@ -29,7 +29,7 @@ mu_imapio_send_flags (struct _mu_imapio *io, int flags)
   rc = mu_stream_write (io->_imap_stream, "(", 1, NULL);
   if (rc)
     return rc;
-  rc = mu_imap_format_flags (io->_imap_stream, flags);
+  rc = mu_imap_format_flags (io->_imap_stream, flags, io->_imap_server);
   if (rc == 0)
     rc = mu_stream_write (io->_imap_stream, ")", 1, NULL);
   return rc;
diff --git a/libproto/imap/Makefile.am b/libproto/imap/Makefile.am
index e950890..bc86ba5 100644
--- a/libproto/imap/Makefile.am
+++ b/libproto/imap/Makefile.am
@@ -60,6 +60,7 @@ libmu_imap_la_SOURCES = \
  status.c\
  starttls.c\
  store.c\
+ storeflg.c\
  subscribe.c\
  tag.c\
  trace.c\
diff --git a/libproto/imap/mbox.c b/libproto/imap/mbox.c
index 841942e..d7a93a6 100644
--- a/libproto/imap/mbox.c
+++ b/libproto/imap/mbox.c
@@ -83,67 +83,66 @@ struct save_closure
   struct _mu_imap_message *imsg;
 };
 
-static void
-_save_message (void *data, int code, size_t sdat, void *pdat)
+static int
+_save_message_parser (void *item, void *data)
 {
+  union mu_imap_fetch_response *resp = item;
   struct save_closure *clos = data;
-  struct _mu_imap_message *imsg = clos->imsg;
-  struct _mu_imap_mailbox *imbx = imsg->imbx;
-  mu_list_t list = pdat;
-  union mu_imap_fetch_response *resp;
-  int rc;
-  mu_stream_t istr, flt;
-  mu_off_t size;
-  
-  rc = mu_list_get (list, 0, (void**)&resp);
-  if (rc)
-    {
-      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
-               (_("cannot get response item: %s"),
-                mu_strerror (rc)));
-      imbx->last_error = rc;
-      return;
-    }
 
-  if (resp->type != MU_IMAP_FETCH_BODY)
+  if (resp->type == MU_IMAP_FETCH_BODY)
     {
-      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
-               (_("fetch returned a not requested item %d"), resp->type));
-      imbx->last_error = MU_ERR_FAILURE;
-      return;
-    }
-  rc = mu_static_memory_stream_create (&istr, resp->body.text,
-                                      strlen (resp->body.text));
-
-  if (rc)
-    {
-      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
-               (_("mu_static_memory_stream_create: %s"),
-                mu_strerror (rc)));
-      imbx->last_error = rc;
-      return;
-    }
+      struct _mu_imap_message *imsg = clos->imsg;
+      struct _mu_imap_mailbox *imbx = imsg->imbx;
+      int rc;
+      mu_stream_t istr, flt;
+      mu_off_t size;
+  
+      rc = mu_static_memory_stream_create (&istr, resp->body.text,
+                                          strlen (resp->body.text));
+      
+      if (rc)
+       {
+         mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+                   (_("mu_static_memory_stream_create: %s"),
+                    mu_strerror (rc)));
+         imbx->last_error = rc;
+         return 0;
+       }
 
-  rc = mu_filter_create (&flt, istr, "CRLF", MU_FILTER_DECODE, MU_STREAM_READ);
-  mu_stream_unref (istr);
-  if (rc)
-    {
-      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
-               (_("mu_filter_create: %s"), mu_strerror (rc)));
-      imbx->last_error = rc;
-      return;
-    }
+      rc = mu_filter_create (&flt, istr, "CRLF", MU_FILTER_DECODE,
+                            MU_STREAM_READ);
+      mu_stream_unref (istr);
+      if (rc)
+       {
+         mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+                   (_("mu_filter_create: %s"), mu_strerror (rc)));
+         imbx->last_error = rc;
+         return 0;
+       }
       
-  rc = mu_stream_copy (clos->save_stream, flt, 0, &size);
-  mu_stream_destroy (&flt);
-  if (rc)
-    {
-      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
-               (_("copying to cache failed: %s"), mu_strerror (rc)));
-      imbx->last_error = rc;
-      return;
+      rc = mu_stream_copy (clos->save_stream, flt, 0, &size);
+      mu_stream_destroy (&flt);
+      if (rc)
+       {
+         mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+                   (_("copying to cache failed: %s"), mu_strerror (rc)));
+         imbx->last_error = rc;
+         return 0;
+       }
+      clos->size = size;
     }
-  clos->size = size;
+  else
+    mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE0,
+             (_("fetch returned a not requested item %d"),
+              resp->type));
+  return 0;
+}
+
+static void
+_save_message (void *data, int code, size_t sdat, void *pdat)
+{
+  mu_list_t list = pdat;
+  mu_list_foreach (list, _save_message_parser, data);
 }
 
 static int
@@ -310,6 +309,7 @@ _imap_attr_set_flags (mu_attribute_t attr, int flags)
   if (!imsg)
     return EINVAL;
   imsg->attr_flags |= flags;
+  imsg->flags |= _MU_IMAP_MSG_ATTRCHG;
   return 0;
 }
 
@@ -321,6 +321,7 @@ _imap_attr_clr_flags (mu_attribute_t attr, int flags)
   if (!imsg)
     return EINVAL;
   imsg->attr_flags |= flags;
+  imsg->flags |= _MU_IMAP_MSG_ATTRCHG;
   return 0;
 }
 
@@ -511,6 +512,97 @@ _imap_msg_lines (mu_message_t msg, size_t *plines, int 
quick)
 }
 
 static int
+_copy_imapenvelope (struct mu_imapenvelope *env,
+                   struct mu_imapenvelope const *src)
+{  
+  env->date = src->date;
+  env->tz   = src->tz;
+  
+  if (src->subject && (env->subject = strdup (src->subject)) == NULL)
+    return ENOMEM;
+  if (src->from && (env->from = mu_address_dup (src->from)) == NULL)
+    return ENOMEM;
+  if (src->sender && (env->sender = mu_address_dup (src->sender)) == NULL)
+    return ENOMEM;
+  if (src->reply_to && (env->reply_to = mu_address_dup (src->reply_to))
+      == NULL)
+    return ENOMEM;
+  if (src->to && (env->to = mu_address_dup (src->to)) == NULL)
+    return ENOMEM;
+  if (src->cc && (env->cc = mu_address_dup (src->cc)) == NULL)
+    return ENOMEM;
+  if (src->bcc && (env->bcc = mu_address_dup (src->bcc)) == NULL)
+    return ENOMEM;
+  if (src->in_reply_to && (env->in_reply_to = strdup (src->in_reply_to))
+      == NULL)
+    return ENOMEM;
+  if (src->message_id && (env->message_id = strdup (src->message_id)) == NULL)
+    return ENOMEM;
+  return 0;
+}
+                  
+static int
+_imap_msg_imapenvelope (mu_message_t msg, struct mu_imapenvelope **penv)
+{
+  struct _mu_imap_message *imsg = mu_message_get_owner (msg);
+  int rc = 0;
+  struct mu_imapenvelope *env = calloc (1, sizeof (*env));
+
+  if (!env)
+    return ENOMEM;
+  rc = _copy_imapenvelope (env, imsg->env);
+  if (rc)
+    mu_message_imapenvelope_free (env);
+  else
+    *penv = env;
+  return rc;
+}
+
+static int
+fetch_bodystructure_parser (void *item, void *data)
+{
+  union mu_imap_fetch_response *resp = item;
+  struct mu_bodystructure **pbs = data;
+
+  if (resp->type == MU_IMAP_FETCH_BODYSTRUCTURE)
+    {
+      *pbs = resp->bodystructure.bs;
+      resp->bodystructure.bs = NULL;
+    }
+  else
+    mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE0,
+             (_("fetch returned a not requested item %d"),
+              resp->type));
+  return 0;
+}
+
+static void
+_imap_bodystructure_callback (void *data, int code, size_t sdat, void *pdat)
+{
+  mu_list_t list = pdat;
+  mu_list_foreach (list, fetch_bodystructure_parser, data);
+}
+  
+static int
+_imap_msg_bodystructure (mu_message_t msg, struct mu_bodystructure **pbs)
+{
+  struct _mu_imap_message *imsg = mu_message_get_owner (msg);
+  struct _mu_imap_mailbox *imbx = imsg->imbx;
+  mu_imap_t imap = imbx->mbox->folder->data;
+  int rc;
+  char *msgset;
+  
+  rc = mu_asprintf (&msgset, "%lu", _imap_msg_no (imsg));
+  if (rc)
+    return rc;
+
+  rc = _imap_fetch_with_callback (imap, msgset, "BODYSTRUCTURE",
+                                 _imap_bodystructure_callback, pbs);
+  free (msgset);
+  return rc;
+}
+
+static int
 _imap_mbx_get_message (mu_mailbox_t mailbox, size_t msgno, mu_message_t *pmsg)
 {
   struct _mu_imap_mailbox *imbx = mailbox->data;
@@ -535,7 +627,9 @@ _imap_mbx_get_message (mu_mailbox_t mailbox, size_t msgno, 
mu_message_t *pmsg)
       mu_message_set_get_stream (msg, _imap_msg_get_stream, imsg);
       mu_message_set_size (msg, _imap_msg_size, imsg);
       mu_message_set_lines (msg, _imap_msg_lines, imsg);
-
+      mu_message_set_imapenvelope (msg, _imap_msg_imapenvelope, imsg);
+      mu_message_set_bodystructure (msg, _imap_msg_bodystructure, imsg);
+      
       do
        {
          rc = _imap_msg_env_setup (imsg, msg);
@@ -621,6 +715,8 @@ _imap_mbx_open (mu_mailbox_t mbox, int flags)
   mu_url_t url;
   mu_imap_t imap;
   
+  mbox->flags = flags;
+  
   rc = mu_mailbox_get_url (mbox, &url);
   if (rc)
     return rc;
@@ -727,9 +823,86 @@ _imap_uidvalidity (mu_mailbox_t mbox, unsigned long *pn)
 static int
 _imap_mbx_expunge (mu_mailbox_t mbox)
 {
+  struct _mu_imap_mailbox *imbx = mbox->data;
   mu_folder_t folder = mbox->folder;
   mu_imap_t imap = folder->data;
-  return mu_imap_expunge (imap);
+  size_t i;
+  char *msgset;
+  int rc;
+  int delflg = 0;
+  
+  for (i = 0; i < imbx->msgs_cnt; i++)
+    {
+      if (imbx->msgs[i].flags & _MU_IMAP_MSG_ATTRCHG)
+       {
+         rc = mu_asprintf (&msgset, "%lu", i + 1);
+         if (rc)
+           break;
+         rc = mu_imap_store_flags (imap, 0, msgset,
+                                   MU_IMAP_STORE_SET|MU_IMAP_STORE_SILENT,
+                                   imbx->msgs[i].attr_flags);
+         delflg |= imbx->msgs[i].attr_flags & MU_ATTRIBUTE_DELETED;
+         free (msgset);
+         if (rc)
+           break;
+       }
+    }
+
+  if (rc)
+    return rc;
+
+  if (delflg)
+    rc = mu_imap_expunge (imap);
+  
+  return rc;
+}
+
+static int
+_imap_mbx_sync (mu_mailbox_t mbox)
+{
+  struct _mu_imap_mailbox *imbx = mbox->data;
+  mu_folder_t folder = mbox->folder;
+  mu_imap_t imap = folder->data;
+  size_t i;
+  char *msgset;
+  int rc;
+  
+  if (!imbx->msgs)
+    return 0; 
+
+  for (i = 0; i < imbx->msgs_cnt; i++)
+    {
+      if (imbx->msgs[i].flags & _MU_IMAP_MSG_ATTRCHG)
+       {
+         rc = mu_asprintf (&msgset, "%lu", i + 1);
+         if (rc)
+           break;
+         rc = mu_imap_store_flags (imap, 0, msgset,
+                                   MU_IMAP_STORE_SET|MU_IMAP_STORE_SILENT,
+                                   imbx->msgs[i].attr_flags);
+         free (msgset);
+         if (rc)
+           break;
+       }
+    }
+  
+  return rc;
+}
+
+static int
+_imap_mbx_append_message (mu_mailbox_t mbox, mu_message_t msg)
+{
+  int rc;
+  mu_folder_t folder = mbox->folder;
+  mu_imap_t imap = folder->data;
+  mu_url_t url;
+  const char *mbox_name;
+  
+  rc = mu_mailbox_get_url (mbox, &url);
+  if (rc)
+    return rc;
+  rc = mu_url_sget_path (url, &mbox_name);
+  return mu_imap_append_message (imap, mbox_name, 0, NULL, NULL, msg);
 }
 
 static int _compute_lines (struct mu_bodystructure *bs, size_t *pcount);
@@ -934,13 +1107,9 @@ _mu_imap_mailbox_init (mu_mailbox_t mailbox)
   mailbox->_scan = _imap_mbx_scan;
   mailbox->_is_updated = _imap_mbx_is_updated;
   mailbox->_get_message = _imap_mbx_get_message;
+  mailbox->_sync = _imap_mbx_sync;
+  
+  mailbox->_append_message = _imap_mbx_append_message;
   
-  //FIXME
-#if 0
-
-  /* Messages.  */
-  mailbox->_append_message = _mu_imap_append_message;
-
-#endif
   return 0;
 }
diff --git a/libproto/imap/login.c b/libproto/imap/storeflg.c
similarity index 62%
copy from libproto/imap/login.c
copy to libproto/imap/storeflg.c
index efdfb4b..66394d5 100644
--- a/libproto/imap/login.c
+++ b/libproto/imap/storeflg.c
@@ -18,58 +18,68 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
+
 #include <stdlib.h>
 #include <string.h>
 #include <mailutils/errno.h>
+#include <mailutils/assoc.h>
 #include <mailutils/stream.h>
-#include <mailutils/secret.h>
+#include <mailutils/imap.h>
+#include <mailutils/imaputil.h>
 #include <mailutils/sys/imap.h>
 
 int
-mu_imap_login (mu_imap_t imap, const char *user, const char *pass)
+mu_imap_store_flags (mu_imap_t imap, int uid, const char *msgset,
+                    int op, int flags)
 {
   int status;
+  static char *cmd[] = { "FLAGS", "+FLAGS", "-FLAGS" };
   
-  if (imap == NULL)
+  if (imap == NULL || (op & MU_IMAP_STORE_OPMASK) >= MU_ARRAY_SIZE (cmd))
     return EINVAL;
   if (!imap->io)
     return MU_ERR_NO_TRANSPORT;
-  if (imap->session_state != MU_IMAP_SESSION_NONAUTH)
+  if (imap->session_state < MU_IMAP_SESSION_SELECTED)
     return MU_ERR_SEQ;
-  
+
   switch (imap->client_state)
     {
     case MU_IMAP_CLIENT_READY:
-      if (mu_imap_trace_mask (imap, MU_IMAP_TRACE_QRY, MU_XSCRIPT_SECURE))
-       _mu_imap_xscript_level (imap, MU_XSCRIPT_SECURE);
       status = _mu_imap_tag_next (imap);
       MU_IMAP_CHECK_EAGAIN (imap, status);
-      status = mu_imapio_send_command (imap->io, imap->tag_str,
-                                      "LOGIN", user, pass, NULL);
-      _mu_imap_xscript_level (imap, MU_XSCRIPT_NORMAL);
-      /* FIXME: how to obscure the passwd in the stream buffer? */
-      MU_IMAP_CHECK_EAGAIN (imap, status);
+      mu_imapio_printf (imap->io, "%s ", imap->tag_str);
+      if (uid)
+       mu_imapio_printf (imap->io, "UID ");
+      mu_imapio_printf (imap->io, "STORE %s %s", msgset,
+                       cmd[op & MU_IMAP_STORE_OPMASK]);
+      if (op & MU_IMAP_STORE_SILENT)
+       mu_imapio_printf (imap->io, ".SILENT");
+      mu_imapio_send_flags (imap->io, flags);
+      mu_imapio_printf (imap->io, "\r\n");
+      status = mu_imapio_last_error (imap->io);
+      MU_IMAP_CHECK_ERROR (imap, status);
       MU_IMAP_FCLR (imap, MU_IMAP_RESP);
-      imap->client_state = MU_IMAP_CLIENT_LOGIN_RX;
-
-    case MU_IMAP_CLIENT_LOGIN_RX:
+      imap->client_state = MU_IMAP_CLIENT_STORE_RX;
+      
+    case MU_IMAP_CLIENT_STORE_RX:
+      /* FIXME: Handle unsolicited responses */
       status = _mu_imap_response (imap, NULL, NULL);
-      imap->client_state = MU_IMAP_CLIENT_READY;
       MU_IMAP_CHECK_EAGAIN (imap, status);
       switch (imap->resp_code)
        {
        case MU_IMAP_OK:
-         imap->session_state = MU_IMAP_SESSION_AUTH;
+         status = 0;
          break;
-
+         
        case MU_IMAP_NO:
-         status = EACCES;
+         status = MU_ERR_FAILURE;
          break;
 
        case MU_IMAP_BAD:
          status = MU_ERR_BADREPLY;
          break;
        }
+      imap->client_state = MU_IMAP_CLIENT_READY;
       break;
 
     default:
@@ -77,13 +87,3 @@ mu_imap_login (mu_imap_t imap, const char *user, const char 
*pass)
     }
   return status;
 }
-
-int
-mu_imap_login_secret (mu_imap_t imap, const char *user, mu_secret_t secret)
-{
-  int rc = mu_imap_login (imap, user, mu_secret_password (secret));
-  mu_secret_password_unref (secret);
-  return rc;
-}
-  
-  
diff --git a/mu/imap.c b/mu/imap.c
index c280740..0069ff5 100644
--- a/mu/imap.c
+++ b/mu/imap.c
@@ -422,7 +422,7 @@ fetch_response_printer (void *item, void *data)
       
     case MU_IMAP_FETCH_FLAGS:
       mu_stream_printf (str, "  flags = ");
-      mu_imap_format_flags (str, resp->flags.flags);
+      mu_imap_format_flags (str, resp->flags.flags, 1);
       mu_stream_printf (str, "\n");
       break;
       
@@ -796,13 +796,13 @@ print_imap_stats (struct mu_imap_stat *st)
   if (st->flags & MU_IMAP_STAT_DEFINED_FLAGS)
     {
       mu_printf (_("Flags defined: "));
-      mu_imap_format_flags (mu_strout, st->defined_flags);
+      mu_imap_format_flags (mu_strout, st->defined_flags, 0);
       mu_printf ("\n");
     }
   if (st->flags & MU_IMAP_STAT_PERMANENT_FLAGS)
     {
       mu_printf (_("Flags permanent: "));
-      mu_imap_format_flags (mu_strout, st->permanent_flags);
+      mu_imap_format_flags (mu_strout, st->permanent_flags, 0);
       mu_printf ("\n");
     }
 


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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