all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] org-attach: Attach current Gnus article parts
@ 2022-05-07 14:31 Juan Manuel Macías
  2022-05-08 12:30 ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Juan Manuel Macías @ 2022-05-07 14:31 UTC (permalink / raw)
  To: orgmode

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]

Hi all,

In the attached patch I add a new command for org-attach: save *all*
attachments from the current Gnus article to the current org-attach-dir.

(Sorry for repeating the word "attach" so much :-))

NB:

1. If no Gnus article is open, it returns an error message.

2. I've only tested it on Emacs 28. I don't know if it can cause any
problems on earlier Emacs/Gnus versions.

3. Although there are several alternatives to Gnus, I have chosen Gnus
specifically because it is part of GNU Emacs.

4. I think an option could be added to save only certain types of files
(pdf, png, jpg, docx, etc.).

Best regards,

Juan Manuel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org-attach.el-new-command-to-attach-Gnus-curren.patch --]
[-- Type: text/x-patch, Size: 1865 bytes --]

From 03a53680df38300110c2095a98bc1dec8cc7adce Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Sat, 7 May 2022 16:04:06 +0200
Subject: [PATCH] lisp/org-attach.el: new command to attach Gnus current
 article parts

* (org-attach-gnus-save-parts-current-article): Attach current Gnus
article parts
* (org-attach-commands): add a new key
---
 lisp/org-attach.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 5ee2b84b2..54c8a2bdb 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -206,6 +206,8 @@ git-functionality from this file.")
      "Attach a file using symbolic-link method.")
     ((?u ?\C-u) org-attach-url
      "Attach a file from URL (downloading it).")
+    ((?g ?\C-g) org-attach-gnus-save-parts-current-article
+     "Attach current Gnus article parts")
     ((?b) org-attach-buffer
      "Select a buffer and attach its contents to the task.")
     ((?n ?\C-n) org-attach-new
@@ -488,6 +490,21 @@ DIR-property exists (that is different from the unset one)."
   (let ((org-attach-method 'url))
     (org-attach-attach url)))
 
+(defun org-attach-gnus-save-parts-current-article ()
+  "Attach current Gnus article parts."
+  (interactive)
+  (let* ((attach-dir (org-attach-dir 'get-create))
+	 (art gnus-article-current)
+	 (subject (gnus-summary-article-subject (cdr art))))
+    (if (not art)
+	(error "There is no open article")
+      (if (yes-or-no-p (format "Attach current article: \"%s\"" subject))
+	  (progn
+	    (org-attach-tag)
+	    (gnus-summary-save-parts "." attach-dir art)
+	    (message "New attachment: \"%s\"" subject))
+	(keyboard-quit)))))
+
 (defun org-attach-buffer (buffer-name)
   "Attach BUFFER-NAME's contents to current outline node.
 BUFFER-NAME is a string.  Signals a `file-already-exists' error
-- 
2.36.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] org-attach: Attach current Gnus article parts
  2022-05-07 14:31 [PATCH] org-attach: Attach current Gnus article parts Juan Manuel Macías
@ 2022-05-08 12:30 ` Ihor Radchenko
  2022-05-08 13:23   ` Juan Manuel Macías
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2022-05-08 12:30 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode

Juan Manuel Macías <maciaschain@posteo.net> writes:

> In the attached patch I add a new command for org-attach: save *all*
> attachments from the current Gnus article to the current org-attach-dir.
>
> (Sorry for repeating the word "attach" so much :-))
>
> NB:
>
> 1. If no Gnus article is open, it returns an error message.
>
> 2. I've only tested it on Emacs 28. I don't know if it can cause any
> problems on earlier Emacs/Gnus versions.
>
> 3. Although there are several alternatives to Gnus, I have chosen Gnus
> specifically because it is part of GNU Emacs.
>
> 4. I think an option could be added to save only certain types of files
> (pdf, png, jpg, docx, etc.).

I think that supporting only Gnus is too specific. Not all the people
use Gnus as mail reader. And the extra menu option you propose will only
eat up space for people not using Gnus.

I'd prefer a more generic approach working in any kind of email reader,
be it rmail, gnus, mu4e, notmuch, or wunderlust. The approach can
probably making use of message-mode or MML libraries from Emacs core.

Also, I do not like adding yet another menu option even if it is working
for other mail readers. Instead, it would be more consistent to follow
what we do for dired. See interactive spec in org-attach-attach.

Best,
Ihor


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] org-attach: Attach current Gnus article parts
  2022-05-08 12:30 ` Ihor Radchenko
@ 2022-05-08 13:23   ` Juan Manuel Macías
  2022-05-08 14:18     ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Juan Manuel Macías @ 2022-05-08 13:23 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: orgmode

Ihor Radchenko writes:

> I think that supporting only Gnus is too specific. Not all the people
> use Gnus as mail reader. And the extra menu option you propose will only
> eat up space for people not using Gnus.
>
> I'd prefer a more generic approach working in any kind of email reader,
> be it rmail, gnus, mu4e, notmuch, or wunderlust. The approach can
> probably making use of message-mode or MML libraries from Emacs core.

Well, as I said, I have chosen Gnus because it is part of GNU Emacs. In
any case, if anyone wants to write a patch with a more general solution,
I'd encourage them. I think that would be an interesting feature for
org-attach. I only use Gnus and unfortunately I'm not familiar with
other mail reader libraries (I could try to do something more "agnostic"
from message-mode, when I have some more time...).

What I don't quite understand is why it wouldn't be appropriate to add a
new entry with the new feature to the org-attach menu.

Best regards,

Juan Manuel 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] org-attach: Attach current Gnus article parts
  2022-05-08 13:23   ` Juan Manuel Macías
@ 2022-05-08 14:18     ` Ihor Radchenko
  2022-05-08 18:06       ` Juan Manuel Macías
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2022-05-08 14:18 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode

Juan Manuel Macías <maciaschain@posteo.net> writes:

> What I don't quite understand is why it wouldn't be appropriate to add a
> new entry with the new feature to the org-attach menu.

Thinking about it more, new feature in org-attach menu should actually
be ok.

My initial logic was that we cannot easily select attach method for
entries in the attach menu. However, anything other than 'cp method is
meaningless when saving article attachments.

> Well, as I said, I have chosen Gnus because it is part of GNU Emacs. In
> any case, if anyone wants to write a patch with a more general solution,
> I'd encourage them. I think that would be an interesting feature for
> org-attach. I only use Gnus and unfortunately I'm not familiar with
> other mail reader libraries (I could try to do something more "agnostic"
> from message-mode, when I have some more time...).

I think that a good example implementation is from notmuch.el. It does
not use anything specific to notmuch, just built-in mm-*.el from gnus:

(defun notmuch-save-attachments (mm-handle &optional queryp)
  (notmuch-foreach-mime-part
   (lambda (p)
     (let ((disposition (mm-handle-disposition p)))
       (and (listp disposition)
	    (or (equal (car disposition) "attachment")
		(and (equal (car disposition) "inline")
		     (assq 'filename disposition)))
	    (or (not queryp)
		(y-or-n-p
		 (concat "Save '" (cdr (assq 'filename disposition)) "' ")))
	    (mm-save-part p))))
   mm-handle))

(defun notmuch-foreach-mime-part (function mm-handle)
  (cond ((stringp (car mm-handle))
	 (dolist (part (cdr mm-handle))
	   (notmuch-foreach-mime-part function part)))
	((bufferp (car mm-handle))
	 (funcall function mm-handle))
	(t (dolist (part mm-handle)
	     (notmuch-foreach-mime-part function part)))))

Best,
Ihor


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] org-attach: Attach current Gnus article parts
  2022-05-08 14:18     ` Ihor Radchenko
@ 2022-05-08 18:06       ` Juan Manuel Macías
  0 siblings, 0 replies; 5+ messages in thread
From: Juan Manuel Macías @ 2022-05-08 18:06 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: orgmode

Ihor Radchenko writes:

> I think that a good example implementation is from notmuch.el. It does
> not use anything specific to notmuch, just built-in mm-*.el from gnus:

Thanks for the tip, Ihor. I'll take a look at it, and see if I can
sketch something usable...

Best regards,

Juan Manuel 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-08 18:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-07 14:31 [PATCH] org-attach: Attach current Gnus article parts Juan Manuel Macías
2022-05-08 12:30 ` Ihor Radchenko
2022-05-08 13:23   ` Juan Manuel Macías
2022-05-08 14:18     ` Ihor Radchenko
2022-05-08 18:06       ` Juan Manuel Macías

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.