(gnus-group-completing-read): Remove all newlines from group names. They mess up...
[gnus] / lisp / nnimap.el
index 8f0a112..701ed1e 100644 (file)
@@ -477,7 +477,7 @@ textual parts.")
                                (let ((start (point)))
                                  (forward-sexp 1)
                                  (downcase-region start (point))
-                                 (goto-char (point))
+                                 (goto-char start)
                                  (read (current-buffer))))
                    parts (nnimap-find-wanted-parts structure))))
          (when (if parts
@@ -565,9 +565,9 @@ textual parts.")
        (pop bstruc))
       (setq type (car bstruc))
       (setq bstruc (car (cdr bstruc)))
-      (when (and (stringp (car bstruc))
-                (string= (downcase (car bstruc)) "boundary"))
-       (setq boundary (cadr bstruc))))
+      (let ((has-boundary (member "boundary" bstruc)))
+        (when has-boundary
+          (setq boundary (cadr has-boundary)))))
     (when subp
       (insert (format "Content-type: multipart/%s; boundary=%S\n\n"
                      (downcase type) boundary)))
@@ -617,7 +617,13 @@ textual parts.")
     (nreverse parts)))
 
 (deffoo nnimap-request-group (group &optional server dont-check info)
-  (let ((result (nnimap-possibly-change-group group server))
+  (let ((result (nnimap-possibly-change-group
+                ;; Don't SELECT the group if we're going to select it
+                ;; later, anyway.
+                (if dont-check
+                    nil
+                  group)
+                server))
        articles active marks high low)
     (with-current-buffer nntp-server-buffer
       (when result
@@ -634,6 +640,7 @@ textual parts.")
                   (nnimap-send-command "SELECT %S" (utf7-encode group t)))
                  (flag-sequence
                   (nnimap-send-command "UID FETCH 1:* FLAGS")))
+             (setf (nnimap-group nnimap-object) group)
              (nnimap-wait-for-response flag-sequence)
              (setq marks
                    (nnimap-flags-to-marks
@@ -707,6 +714,7 @@ textual parts.")
 (deffoo nnimap-request-move-article (article group server accept-form
                                             &optional last internal-move-group)
   (with-temp-buffer
+    (mm-disable-multibyte)
     (when (nnimap-request-article article group server (current-buffer))
       ;; If the move is internal (on the same server), just do it the easy
       ;; way.
@@ -762,6 +770,7 @@ textual parts.")
     (dolist (article articles)
       (let ((target nnmail-expiry-target))
        (with-temp-buffer
+          (mm-disable-multibyte)
          (when (nnimap-request-article article group server (current-buffer))
            (nnheader-message 7 "Expiring article %s:%d" group article)
            (when (functionp target)
@@ -872,7 +881,7 @@ textual parts.")
     (let ((message-id (message-field-value "message-id"))
          sequence message)
       (nnimap-add-cr)
-      (setq message (buffer-string))
+      (setq message (buffer-substring-no-properties (point-min) (point-max)))
       (with-current-buffer (nnimap-buffer)
        (setq sequence (nnimap-send-command
                        "APPEND %S {%d}" (utf7-encode group t)
@@ -890,6 +899,17 @@ textual parts.")
            (cons group
                  (nnimap-find-article-by-message-id group message-id))))))))
 
+(deffoo nnimap-request-replace-article (article group buffer)
+  (let (group-art)
+    (when (and (nnimap-possibly-change-group group nil)
+              ;; Put the article into the group.
+              (with-current-buffer buffer
+                (setq group-art
+                      (nnimap-request-accept-article group nil t))))
+      (nnimap-delete-article (list article))
+      ;; Return the new article number.
+      (cdr group-art))))
+
 (defun nnimap-add-cr ()
   (goto-char (point-min))
   (while (re-search-forward "\r?\n" nil t)
@@ -1105,12 +1125,13 @@ textual parts.")
        (unless (eq permanent-flags 'not-scanned)
          (gnus-group-set-parameter
           info 'permanent-flags
-          (if (memq '%* permanent-flags)
-              t
-            nil)))
+          (and (or (memq '%* permanent-flags)
+                   (memq '%Seen permanent-flags))
+               permanent-flags)))
        ;; Update marks and read articles if this isn't a
        ;; read-only IMAP group.
-       (when (cdr (assq 'permanent-flags (gnus-info-params info)))
+       (when (setq permanent-flags
+                   (cdr (assq 'permanent-flags (gnus-info-params info))))
          (if (and highestmodseq
                   (not start-article))
              ;; We've gotten the data by QRESYNCing.
@@ -1136,27 +1157,32 @@ textual parts.")
                            (gnus-info-read info))
                         (gnus-info-read info))
                       read)))
-             (gnus-info-set-read info read)
+             (when (or (not (listp permanent-flags))
+                       (memq '%Seen permanent-flags))
+               (gnus-info-set-read info read))
              ;; Update the marks.
              (setq marks (gnus-info-marks info))
              (dolist (type (cdr nnimap-mark-alist))
-               (let ((old-marks (assoc (car type) marks))
-                     (new-marks
-                      (gnus-compress-sequence
-                       (cdr (or (assoc (caddr type) flags) ; %Flagged
-                                (assoc (intern (cadr type) obarray) flags)
-                                (assoc (cadr type) flags)))))) ; "\Flagged"
-                 (setq marks (delq old-marks marks))
-                 (pop old-marks)
-                 (when (and old-marks
-                            (> start-article 1))
-                   (setq old-marks (gnus-range-difference
-                                    old-marks
-                                    (cons start-article high)))
-                   (setq new-marks (gnus-range-nconcat old-marks new-marks)))
-                 (when new-marks
-                   (push (cons (car type) new-marks) marks)))
-               (gnus-info-set-marks info marks t)))))
+               (when (or (not (listp permanent-flags))
+                         (memq (assoc (caddr type) flags) permanent-flags)
+                         (memq '%* permanent-flags))
+                 (let ((old-marks (assoc (car type) marks))
+                       (new-marks
+                        (gnus-compress-sequence
+                         (cdr (or (assoc (caddr type) flags) ; %Flagged
+                                  (assoc (intern (cadr type) obarray) flags)
+                                  (assoc (cadr type) flags)))))) ; "\Flagged"
+                   (setq marks (delq old-marks marks))
+                   (pop old-marks)
+                   (when (and old-marks
+                              (> start-article 1))
+                     (setq old-marks (gnus-range-difference
+                                      old-marks
+                                      (cons start-article high)))
+                     (setq new-marks (gnus-range-nconcat old-marks new-marks)))
+                   (when new-marks
+                     (push (cons (car type) new-marks) marks)))))
+             (gnus-info-set-marks info marks t))))
        ;; Note the active level for the next run-through.
        (gnus-group-set-parameter info 'active (gnus-active group))
        (gnus-group-set-parameter info 'uidvalidity uidvalidity)
@@ -1461,6 +1487,7 @@ textual parts.")
 (defun nnimap-parse-line (line)
   (let (char result)
     (with-temp-buffer
+      (mm-disable-multibyte)
       (insert line)
       (goto-char (point-min))
       (while (not (eobp))