Return uid of append message if requested
authordmaus <dmaus>
Thu, 2 Jun 2011 11:46:59 +0000 (11:46 +0000)
committerdmaus <dmaus>
Thu, 2 Jun 2011 11:46:59 +0000 (11:46 +0000)
* elmo-date.el (elmo-time-make-imap-date-string): New
function. Return IMAP4 compliant date string.

* elmo-imap4.el (elmo-folder-append-buffer): Return uid of append
message if requested.

elmo/ChangeLog
elmo/elmo-date.el
elmo/elmo-imap4.el

index 597f7ec..ebe1eef 100644 (file)
@@ -1,3 +1,11 @@
+2011-06-02  David Maus  <dmaus@ictsoc.de>
+
+       * elmo-date.el (elmo-time-make-imap-date-string): New
+       function. Return IMAP4 compliant date string.
+
+       * elmo-imap4.el (elmo-folder-append-buffer): Return uid of append
+       message if requested.
+
 2011-05-29  David Maus  <dmaus@ictsoc.de>
 
        * elmo-maildir.el (elmo-folder-append-buffer): Return number of
index 7d986ea..f51873f 100644 (file)
@@ -224,6 +224,10 @@ Otherwise treat \\ in NEWTEXT string as special:
   (let ((system-time-locale "C"))
     (format-time-string "%a, %d %b %Y %T %z" time)))
 
+(defun elmo-time-make-imap-date-string (time)
+  (let ((system-time-locale "C"))
+    (format-time-string "%d-%b-%Y %T %z")))
+
 (defun elmo-time-less-p (lhs rhs)
   (while (and (car lhs) (car rhs))
     (cond ((< (car lhs) (car rhs))
index 9feda9e..d040a61 100644 (file)
@@ -2718,6 +2718,7 @@ If optional argument REMOVE is non-nil, remove FLAG."
   ((folder elmo-imap4-folder) &optional flags number return-number)
   (if (elmo-folder-plugged-p folder)
       (let ((session (elmo-imap4-get-session folder))
+           (internaldate (elmo-time-make-imap-date-string (current-time)))
            send-buffer result)
        (elmo-imap4-session-select-mailbox session
                                           (elmo-imap4-folder-mailbox-internal
@@ -2734,11 +2735,42 @@ If optional argument REMOVE is non-nil, remove FLAG."
                    (if (and flags (elmo-folder-use-flag-p folder))
                        (concat " (" (elmo-imap4-flags-to-imap flags) ") ")
                      " () ")
+                   (if return-number
+                       (concat " \"" internaldate "\" ")
+                     "")
                    (elmo-imap4-buffer-literal send-buffer))))
          (kill-buffer send-buffer))
        (when result
          (elmo-folder-preserve-flags
-          folder (elmo-msgdb-get-message-id-from-buffer) flags))
+          folder (elmo-msgdb-get-message-id-from-buffer) flags)
+         (when return-number
+           (unless (setq result (cadadr (assq 'appenduid (cdar result))))
+             (let ((candidates 
+                    (elmo-imap4-response-value
+                     (elmo-imap4-send-command-wait
+                      session
+                      (list
+                       "uid search since "
+                       (car (split-string internaldate " ")))) 'search)))
+               (if (null candidates)
+                   (setq result t)
+                 (setq candidates 
+                       (elmo-imap4-response-value-all
+                        (elmo-imap4-send-command-wait
+                         session
+                         (list
+                          "uid fetch "
+                          (mapconcat 'number-to-string candidates ",")
+                          " (internaldate)")) 'fetch))
+                 (while candidates
+                   (if (string= (cadar candidates) internaldate)
+                       (setq result (cons 
+                                     (cadadr candidates)
+                                     result)))
+                   (setq candidates (cddr candidates)))
+                 (setq result (or (null result)
+                                  (> (length result) 1)
+                                  (car result))))))))
        result)
     ;; Unplugged
     (if elmo-enable-disconnected-operation