emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs/lisp/net tramp-imap.el


From: Michael Albinus
Subject: [Emacs-diffs] emacs/lisp/net tramp-imap.el
Date: Tue, 27 Oct 2009 10:52:54 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Michael Albinus <albinus>       09/10/27 10:52:54

Modified files:
        lisp/net       : tramp-imap.el 

Log message:
        * net/tramp-imap.el (top): Add `X-Size' to `imap-hash-headers'.
        (tramp-imap-do-copy-or-rename-file): Don't use the inode, when
        calling `tramp-imap-put-file'.  Add file size to the call.
        (tramp-imap-get-file-entries): Compute also user name, file size,
        and date.
        (tramp-imap-handle-insert-directory): Insert uid and gid.
        (tramp-imap-handle-file-attributes): Transform uid and gid
        according to `id-format'.
        (tramp-imap-put-file): New optional parameter SIZE.  Encode file
        size in header X-Size.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/net/tramp-imap.el?cvsroot=emacs&r1=1.3&r2=1.4

Patches:
Index: tramp-imap.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/net/tramp-imap.el,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- tramp-imap.el       26 Oct 2009 09:05:09 -0000      1.3
+++ tramp-imap.el       27 Oct 2009 10:52:54 -0000      1.4
@@ -60,6 +60,9 @@
 (require 'epa)
 (autoload 'auth-source-user-or-password "auth-source")
 
+;; We use the additional header "X-Size" for encoding the size of a file.
+(add-to-list 'imap-hash-headers 'X-Size 'append)
+
 ;; Define Tramp IMAP method ...
 (defconst tramp-imap-method "imap"
   "*Method to connect via IMAP protocol.")
@@ -243,8 +246,7 @@
            (tramp-imap-put-file
             v (current-buffer)
             (tramp-imap-file-name-name v)
-            (tramp-imap-get-file-inode newname)
-            nil))
+            nil nil (nth 7 (file-attributes filename))))
        ;; One of them is not located on a IMAP mailbox.
        (insert-file-contents filename)
        (write-region (point-min) (point-max) newname)))
@@ -319,17 +321,25 @@
     (imap-hash-map (lambda (uid headers body)
                     (let ((subject (substring
                                     (aget headers 'Subject "")
-                                    (length tramp-imap-subject-marker))))
+                                    (length tramp-imap-subject-marker)))
+                          (from (aget headers 'From ""))
+                          (date (date-to-time (aget headers 'Date "")))
+                          (size (string-to-number
+                                 (or (aget headers 'X-Size "0") "0"))))
+                      (setq from
+                            (if (string-match "<\\(address@hidden)@" from)
+                                (match-string 1 from)
+                              "nobody"))
                       (list
                        subject
                        nil
                        -1
-                       1
-                       1
-                       '(0 0)
-                       '(0 0)
-                       '(0 0)
-                       1
+                       from
+                       "nogroup"
+                       date
+                       date
+                       date
+                       size
                        "-rw-rw-rw-"
                        nil
                        uid
@@ -440,7 +450,8 @@
               "%10s %3d %-8s %-8s %8s %s "
               (nth 9 x) ; mode
               (nth 11 x) ; inode
-              "nobody" "nogroup"
+              (nth 3 x) ; uid
+              (nth 4 x) ; gid
               (nth 8 x) ; size
               (format-time-string
                (if (tramp-time-less-p
@@ -499,7 +510,11 @@
 (defun tramp-imap-handle-file-attributes (filename &optional id-format)
   "Like `file-attributes' for Tramp-IMAP FILENAME."
   (with-parsed-tramp-file-name (expand-file-name filename) nil
-    (cdr-safe (nth 0 (tramp-imap-get-file-entries v localname)))))
+    (let ((res (cdr-safe (nth 0 (tramp-imap-get-file-entries v localname)))))
+      (unless (or (null res) (eq id-format 'string))
+       (setcar (nthcdr 2 res) 1)
+       (setcar (nthcdr 3 res) 1))
+      res)))
 
 (defun tramp-imap-get-file-inode (filename &optional id-format)
   "Get inode equivalent \(actually the UID) for Tramp-IMAP FILENAME."
@@ -560,10 +575,13 @@
        (tramp-message v 4 "Fetching %s to tmp file %s...done" filename tmpfile)
        tmpfile))))
 
-(defun tramp-imap-put-file (vec filename-or-buffer &optional subject inode 
encode)
+(defun tramp-imap-put-file
+  (vec filename-or-buffer &optional subject inode encode size)
   "Write contents of FILENAME-OR-BUFFER to Tramp-IMAP file VEC with name 
SUBJECT.
 When INODE is given, delete that old remote file after writing the new one
-\(normally this is the old file with the same name)."
+\(normally this is the old file with the same name).  A non-nil ENCODE
+forces the encoding of the buffer or file.  SIZE, when available, indicates
+the file size; this is needed, if the file or buffer is already encoded."
   ;; `tramp-current-host' is used in `tramp-imap-passphrase-callback-function'.
   (let ((tramp-current-host (tramp-file-name-real-host vec))
        (iht (tramp-imap-make-iht vec)))
@@ -573,7 +591,18 @@
                           (format
                            "%s%s"
                            tramp-imap-subject-marker
-                           (or subject "no subject"))))
+                           (or subject "no subject")))
+                         (cons
+                          'X-Size
+                          (number-to-string
+                           (cond
+                            ((numberp size) size)
+                            ((bufferp filename-or-buffer)
+                             (buffer-size filename-or-buffer))
+                            ((stringp filename-or-buffer)
+                             (nth 7 (file-attributes filename-or-buffer)))
+                            ;; We don't know the size.
+                            (t -1)))))
                    (cond ((bufferp filename-or-buffer)
                           (with-current-buffer filename-or-buffer
                             (if encode
@@ -748,11 +777,7 @@
 ;;   "/imaps:imap.gmail.com:/INBOX.test/" results in error
 ;;   "error in process filter: Internal error, tag 5 status BAD code nil text 
UNSELECT not allowed now."
 
-;; * Improve `tramp-imap-handle-file-attributes'
-;;   - size
-;;   - modification time
-;;   - user
-;;   - Return info for directories.
+;; * Improve `tramp-imap-handle-file-attributes' for directories.
 
 ;; * Saving a file creates a second one, instead of overwriting.
 




reply via email to

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