Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnus: How to save *all* attachments at once?

I would like to save all attachments to an email at once. I therefore set gnus-summary-save-parts-default-mime to ".* /.*". However, when using "X m", I not only get all attachments, but also a file named "[email protected]/INBOX.2393.1" (referring to the account I'm reading emails from) which contains the signature of the email I received. How can I exclude files of this "type" from being saved on "X m"? In other words: How can I specify the correct regexp for gnus-summary-save-parts-default-mime to prevent this file from being saved, too?

like image 312
Marius Hofert Avatar asked Dec 02 '11 22:12

Marius Hofert


1 Answers

This defadvice will do what you want for the moment by excluding any parts that do not have filenames (in this case that is true of the article itself):

(defadvice gnus-summary-save-parts-1 (around gnus-summary-save-parts-exclude-self activate)
  (let ((handle (ad-get-arg 2)))
    (unless (and (not (stringp (car handle)))
                 (not (mm-handle-filename handle)))
      ad-do-it)))

I am using Gnus v5.13; if you're also using the same or similar version, let me know if this modified version of gnus-summary-save-parts-1 works for you; you will want to set gnus-summary-save-parts-exclude-article to t. If it works for you, I will submit a patch for it to the Gnus projects.

Note, either use the above defadvice OR use the code below, but do not use both together. The defadvice is an easy quick fix that you can use for the moment. The code below I will submit as a patch to the Gnus project and I only included this here for you to test to see if it works on your system if you are also using Gnus v5.13. If they accept this patch and make it part of a future release then you will not need the defadvice above; instead you'll just be able to customize the gnus-summary-save-parts-exclude-article variable.

(require 'gnus)
(require 'gnus-sum)

(defcustom gnus-summary-save-parts-exclude-article nil
  "If non-nil don't save article along with attachments."
  :group 'gnus-article-mime
  :type 'boolean)

(defun gnus-summary-save-parts-1 (type dir handle reverse)
  (if (stringp (car handle))
      (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
          (cdr handle))
    (when (if reverse
          (not (string-match type (mm-handle-media-type handle)))
        (string-match type (mm-handle-media-type handle)))
      (let* ((name (or
                    (mm-handle-filename handle)
                    (unless gnus-summary-save-parts-exclude-article
                      (format "%s.%d.%d" gnus-newsgroup-name
                              (cdr gnus-article-current)
                              gnus-summary-save-parts-counter))))
             (file (when name
                     (expand-file-name
                      (gnus-map-function
                       mm-file-name-rewrite-functions
                       (file-name-nondirectory
                        name))
                      dir))))
        (when file
          (incf gnus-summary-save-parts-counter)
          (unless (file-exists-p file)
            (mm-save-part-to-file handle file)))))))
like image 50
aculich Avatar answered Nov 03 '22 03:11

aculich