Gnus: How to save *all* attachments at once?
Asked Answered
B

1

7

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?

Bucolic answered 2/12, 2011 at 22:12 Comment(0)
P
2

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)))))))
Phytography answered 7/12, 2011 at 14:13 Comment(4)
Thank you very much, that solved it! I'm also using Gnus 5.13 and I put the first part and the "defcustom gnus-summary-save-parts-exclude-article t" part (with "t" instead of "nil") in my .gnus.el; was that what you intended? at least, that solved it! Many thanksBucolic
I edited my answer above to clarify what you should use. Only use the defadvice part for now as the short-term work-around until they accept my patch and release a new version.Phytography
Hi, what confused me is the part "you will want to set gnus-summary-save-parts-exclude-article to t". This variable (gnus-summary-save-parts-exclude-article) did not exist (I couldn't find it it C-h v), that's why I put in the defcustom gnus-summary-save-parts-exclude-article-part as well (but only these four lines, not the whole second part). I just realized that it indeed works only with the defadvice part. Thanks a lot.Bucolic
Great! So does this patch fully answer your question then? If so, I'll go ahead and submit my patch and if/when it is accepted I'll add a comment here so you will know to remove the defadvice when they release the next version of Gnus that has the patch applied.Phytography

© 2022 - 2024 — McMap. All rights reserved.