emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [PATCH] org-attach: Attach current Gnus article parts
Date: Sat, 07 May 2022 14:31:19 +0000	[thread overview]
Message-ID: <87y1zdwh1k.fsf@posteo.net> (raw)

[-- 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


             reply	other threads:[~2022-05-07 14:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-07 14:31 Juan Manuel Macías [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y1zdwh1k.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] org-attach: Attach current Gnus article parts' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).