info-gnus-english
[Top][All Lists]
Advanced

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

Re: Saving according to time received


From: N. Raghavendra
Subject: Re: Saving according to time received
Date: Sun, 01 Jun 2008 11:23:49 +0530
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (berkeley-unix)

At 2008-05-30T12:29:42+05:30, N. Raghavendra wrote:

> I want to save some articles according to the sender and the time
> received, i.e., each article should be saved to an mbox file of the
> form ~/foo/20050420T213752, where FOO is the sender and
> 2005-04-20T21:37:52 is the local time of receipt of the message.

The below seems to work.  I'd still appreciate any suggestions.

Raghavendra.

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

(defun my-date-iso-8601 (&optional time)
  "Return the ISO 8601 representation of local time TIME."
  (format-time-string "%FT%T" time))

(defun my-get-header (header)
  "Return the value of HEADER in the current article.
Returns false if HEADER is not found."
  (gnus-with-article-headers
    (message-fetch-field header)))

(defun my-sender-save-name ()
  "Construct a filename for saving the current article.
Returns a cons, whose `car' is the directory and whose `cdr' is
the filename."
  (let* ((from (mail-header-from gnus-current-headers))
         (date (or (my-get-header "x-from-line")
                   (mail-header-date gnus-current-headers)))
         (sender (if (and from (string-match "\\([^ <]+\\)@" from))
                     (match-string 1 from)
                   "nobody"))
         (filename
          (replace-regexp-in-string
           "\\-\\|:\\|T"
           (lambda (string)
             (cdr (assoc string '(("-" . "") (":" . "") ("T" . "-")))))
           (my-date-iso-8601 (apply 'encode-time (parse-time-string date))))))
    (cons (expand-file-name sender gnus-article-save-directory)
          filename)))

(defun my-summary-save-in-mail (&optional filename)
  "Save the current article in mbox format to FILENAME.
FILENAME defaults to a filename constructed from the sender and
date of receipt.  Prompts for the directory to save into, in case
FILENAME is not provided; the default is constructed from the
`from' header."
  (let ((filename
         (or filename
             (let* ((save-name (my-sender-save-name))
                    (save-name-dir (car save-name))
                    (save-name-file (cdr save-name))
                    (dir (read-directory-name
                          (format "Save in directory (default %s): "
                                  save-name-dir)
                          (file-name-as-directory gnus-article-save-directory)
                          save-name-dir)))
               (expand-file-name save-name-file dir)))))
    (gnus-eval-in-buffer-window gnus-save-article-buffer
      (save-excursion
        (save-restriction
          (widen)
          (gnus-output-to-mail filename))))
    filename))

(defun my-summary-save-article-mail ()
  "Save the current article in mbox format.
The default filename to save to is constructed from the date
received if available, otherwise from the date sent.  The default
directory to save into is constructed from the `from' header."
  (interactive)
  (let ((gnus-default-article-saver 'my-summary-save-in-mail))
    (gnus-summary-save-article)))

;; Define key bindings for the above.
(define-key gnus-summary-mode-map [?\s-o] 'my-summary-save-article-mail)
(define-key gnus-article-mode-map [?\s-o] 'my-summary-save-article-mail)

-- 
N. Raghavendra <raghu@mri.ernet.in> | http://www.retrotexts.net/
Harish-Chandra Research Institute   | http://www.mri.ernet.in/
See message headers for contact and OpenPGP information.


reply via email to

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