balsa r7883 - in trunk: . libbalsa libbalsa/imap



Author: pawels
Date: Mon Mar  3 22:25:41 2008
New Revision: 7883
URL: http://svn.gnome.org/viewvc/balsa?rev=7883&view=rev

Log:
* libbalsa/mailbox_imap.c: peek only into mailboxes, do no trigger
  implicit \seen flag toggling.
* libbalsa/imap/imap-handle.c: recognize BODY[TEXT].
* libbalsa/imap/imap-commands.[ch]: add peek argument.


Modified:
   trunk/ChangeLog
   trunk/libbalsa/imap/imap-commands.c
   trunk/libbalsa/imap/imap-commands.h
   trunk/libbalsa/imap/imap-handle.c
   trunk/libbalsa/mailbox_imap.c

Modified: trunk/libbalsa/imap/imap-commands.c
==============================================================================
--- trunk/libbalsa/imap/imap-commands.c	(original)
+++ trunk/libbalsa/imap/imap-commands.c	Mon Mar  3 22:25:41 2008
@@ -1070,9 +1070,9 @@
 
 ImapResponse
 imap_mbox_handle_fetch_rfc822_uid(ImapMboxHandle* handle, unsigned uid, 
-                              FILE *fl)
+                                  gboolean peek, FILE *fl)
 {
-  char cmd[40];
+  char cmd[80];
   ImapFetchBodyCb cb = handle->body_cb;
   void          *arg = handle->body_arg;
   ImapResponse rc;
@@ -1081,7 +1081,9 @@
   HANDLE_LOCK(handle);
   handle->body_cb  = write_nstring;
   handle->body_arg = fl;
-  sprintf(cmd, "UID FETCH %u RFC822", uid);
+  sprintf(cmd, peek 
+          ? "UID FETCH %u (BODY.PEEK[HEADER] BODY.PEEK[TEXT])"
+          : "UID FETCH %u RFC822", uid);
   rc = imap_cmd_exec(handle, cmd);
   handle->body_cb  = cb;
   handle->body_arg = arg;
@@ -1121,6 +1123,7 @@
 ImapResponse
 imap_mbox_handle_fetch_body(ImapMboxHandle* handle, 
                             unsigned seqno, const char *section,
+                            gboolean peek_only,
                             ImapFetchBodyOptions options,
                             ImapFetchBodyCb body_cb, void *arg)
 {
@@ -1128,6 +1131,7 @@
   ImapFetchBodyCb fcb = handle->body_cb;
   void          *farg = handle->body_arg;
   ImapResponse rc;
+  const gchar *peek_string = peek_only ? ".PEEK" : "";
 
   IMAP_REQUIRED_STATE1(handle, IMHS_SELECTED, IMR_BAD);
 
@@ -1142,8 +1146,8 @@
     ibd.first_run = TRUE;
     handle->body_cb = imap_binary_handler;
     handle->body_arg = &ibd;
-    snprintf(cmd, sizeof(cmd), "FETCH %u BINARY[%s]",
-             seqno, section);
+    snprintf(cmd, sizeof(cmd), "FETCH %u BINARY%s[%s]",
+             seqno, peek_string, section);
     rc = imap_cmd_exec(handle, cmd);
     if(rc != IMR_NO) { /* unknown-cte */
       handle->body_cb  = fcb;
@@ -1155,8 +1159,8 @@
   handle->body_arg = arg;
   /* Pure IMAP without extensions */
   if(options == IMFB_NONE)
-    snprintf(cmd, sizeof(cmd), "FETCH %u BODY[%s]",
-             seqno, section);
+    snprintf(cmd, sizeof(cmd), "FETCH %u BODY%s[%s]",
+             seqno, peek_string, section);
   else {
     char prefix[160];
     if(options == IMFB_HEADER) {
@@ -1173,8 +1177,8 @@
       prefix[sizeof(prefix)-1] = '\0';
     } else
       snprintf(prefix, sizeof(prefix), "%s.MIME", section);
-    snprintf(cmd, sizeof(cmd), "FETCH %u (BODY[%s] BODY[%s])",
-             seqno, prefix, section);
+    snprintf(cmd, sizeof(cmd), "FETCH %u (BODY%s[%s] BODY%s[%s])",
+             seqno, peek_string, prefix, peek_string, section);
   }
   rc = imap_cmd_exec(handle, cmd);
   handle->body_cb  = fcb;

Modified: trunk/libbalsa/imap/imap-commands.h
==============================================================================
--- trunk/libbalsa/imap/imap-commands.h	(original)
+++ trunk/libbalsa/imap/imap-commands.h	Mon Mar  3 22:25:41 2008
@@ -118,11 +118,13 @@
 					   void *cb_data);
 
 ImapResponse imap_mbox_handle_fetch_rfc822_uid(ImapMboxHandle* handle,
-                                               unsigned uid, FILE *fl);
+                                               unsigned uid, gboolean peek,
+                                               FILE *fl);
 
 ImapResponse imap_mbox_handle_fetch_body(ImapMboxHandle* handle, 
                                          unsigned seqno, 
                                          const char *section,
+                                         gboolean peek_only,
                                          ImapFetchBodyOptions options,
                                          ImapFetchBodyCb body_handler,
                                          void *arg);

Modified: trunk/libbalsa/imap/imap-handle.c
==============================================================================
--- trunk/libbalsa/imap/imap-handle.c	(original)
+++ trunk/libbalsa/imap/imap-handle.c	Mon Mar  3 22:25:41 2008
@@ -3544,7 +3544,8 @@
     }
     c = imap_get_atom(h->sio, buf, sizeof buf);
     if (c == ']' &&
-        g_ascii_strcasecmp(buf, "HEADER") == 0) {
+        (g_ascii_strcasecmp(buf, "HEADER") == 0 ||
+         g_ascii_strcasecmp(buf, "TEXT") == 0)) {
       sio_ungetc (h->sio); /* put the ']' back */
       rc = ir_body_section(h->sio, seqno, h->body_cb, h->body_arg);
     } else {

Modified: trunk/libbalsa/mailbox_imap.c
==============================================================================
--- trunk/libbalsa/mailbox_imap.c	(original)
+++ trunk/libbalsa/mailbox_imap.c	Mon Mar  3 22:25:41 2008
@@ -1125,7 +1125,8 @@
         cache = fopen(path, "wb");
         if(cache) {
             II(rc,mimap->handle,
-               imap_mbox_handle_fetch_rfc822_uid(mimap->handle, uid, cache));
+               imap_mbox_handle_fetch_rfc822_uid(mimap->handle, uid,
+                                                 TRUE, cache));
             fclose(cache);
         }
 
@@ -2340,7 +2341,7 @@
         if (dt.body->octets > 0)
         II(rc,mimap->handle,
            imap_mbox_handle_fetch_body(mimap->handle, msg->msgno,
-                                       section, ifbo, append_str, &dt));
+                                       section, TRUE, ifbo, append_str, &dt));
         libbalsa_unlock_mailbox(msg->mailbox);
         if(rc != IMR_OK) {
             fprintf(stderr, "Error fetching imap message no %lu section %s\n",



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