Discussion:
Deleting mail in virtual group
Alexander Baier
2014-10-04 09:19:17 UTC
Permalink
Hello,

This is my setup:

I sync my E-Mail to disk with mbsync and access it from gnus via the
nnmaildir backend. Each IMAP-folder corresponds to a group
(e.g. nnmaildir+mailbox:Inbox). To be able to read a complete conversion
(that is including my answers) I have a virtual group that combines
Inbox and Sent groups.
From the summary buffer of the virtual group I want to delete the
current article. Deleting is done by moving said article to a designated
group (e.g. nnmaildir+mailbox:Trash).


Problem:

Moving an article from a virtual group does not work:
"gnus-summary-move-article: The current group does not support article
moving".


Solution?:

I want to write my own command that finds the original group of the
article in question and executes the move in that group. Is there a
function that gets me the original group of an article in a virtual
group?

Regards,
--
Alexander Baier
Eric Abrahamsen
2014-10-04 12:48:55 UTC
Permalink
Post by Alexander Baier
Hello,
I sync my E-Mail to disk with mbsync and access it from gnus via the
nnmaildir backend. Each IMAP-folder corresponds to a group
(e.g. nnmaildir+mailbox:Inbox). To be able to read a complete conversion
(that is including my answers) I have a virtual group that combines
Inbox and Sent groups.
From the summary buffer of the virtual group I want to delete the
current article. Deleting is done by moving said article to a designated
group (e.g. nnmaildir+mailbox:Trash).
"gnus-summary-move-article: The current group does not support article
moving".
I want to write my own command that finds the original group of the
article in question and executes the move in that group. Is there a
function that gets me the original group of an article in a virtual
group?
Regards,
I'm pretty sure that nnvirtual-find-group-art will do what you want.
Feed it the article number of the article under point, along with
gnus-newsgroup-name in the virtual Summary buffer. See how it works!

Eric
Alexander Baier
2014-10-04 14:10:15 UTC
Permalink
Post by Eric Abrahamsen
Post by Alexander Baier
I want to write my own command that finds the original group of the
article in question and executes the move in that group. Is there a
function that gets me the original group of an article in a virtual
group?
I'm pretty sure that nnvirtual-find-group-art will do what you want.
Feed it the article number of the article under point, along with
gnus-newsgroup-name in the virtual Summary buffer. See how it works!
Thank you for your quick reply! These to functions do what I want and I
get the correct original group and article. But now I am stuck and do
not know how to get to the original group. This is what I tried:

#+BEGIN_SRC emacs-lisp
(defun my-nnvirtual-delete-article ()
(interactive)
(let ((original (nnvirtual-find-group-art
gnus-newsgroup-name
(gnus-summary-article-number))))
(with-current-buffer gnus-group-buffer
(gnus-group-goto-group (car original))
(gnus-summary-goto-article (cdr original)))))
#+END_SRC

The group and article number returned by nnvirtual-find-group-art are
correct, I checked. But the with-current-buffer part does not seem to
work, as gnus always displays the article from the nnvirtual group with
the original number.

How do I switch to the original group?

TIA,
--
Alexander Baier
Eric Abrahamsen
2014-10-05 08:36:46 UTC
Permalink
Post by Alexander Baier
Post by Eric Abrahamsen
Post by Alexander Baier
I want to write my own command that finds the original group of the
article in question and executes the move in that group. Is there a
function that gets me the original group of an article in a virtual
group?
I'm pretty sure that nnvirtual-find-group-art will do what you want.
Feed it the article number of the article under point, along with
gnus-newsgroup-name in the virtual Summary buffer. See how it works!
Thank you for your quick reply! These to functions do what I want and I
get the correct original group and article. But now I am stuck and do
#+BEGIN_SRC emacs-lisp
(defun my-nnvirtual-delete-article ()
(interactive)
(let ((original (nnvirtual-find-group-art
gnus-newsgroup-name
(gnus-summary-article-number))))
(with-current-buffer gnus-group-buffer
(gnus-group-goto-group (car original))
(gnus-summary-goto-article (cdr original)))))
#+END_SRC
All `gnus-group-goto-group' does is move to the group's line in the
*Group* buffer. Try `gnus-group-read-group' instead. That -- or
something involving that -- ought to do what you want.
Post by Alexander Baier
The group and article number returned by nnvirtual-find-group-art are
correct, I checked. But the with-current-buffer part does not seem to
work, as gnus always displays the article from the nnvirtual group with
the original number.
How do I switch to the original group?
TIA,
Alexander Baier
2014-10-05 18:28:11 UTC
Permalink
Post by Eric Abrahamsen
Post by Alexander Baier
Post by Eric Abrahamsen
Post by Alexander Baier
I want to write my own command that finds the original group of the
article in question and executes the move in that group. Is there a
function that gets me the original group of an article in a virtual
group?
I'm pretty sure that nnvirtual-find-group-art will do what you want.
Feed it the article number of the article under point, along with
gnus-newsgroup-name in the virtual Summary buffer. See how it works!
Thank you for your quick reply! These to functions do what I want and I
get the correct original group and article. But now I am stuck and do
#+BEGIN_SRC emacs-lisp
(defun my-nnvirtual-delete-article ()
(interactive)
(let ((original (nnvirtual-find-group-art
gnus-newsgroup-name
(gnus-summary-article-number))))
(with-current-buffer gnus-group-buffer
(gnus-group-goto-group (car original))
(gnus-summary-goto-article (cdr original)))))
#+END_SRC
All `gnus-group-goto-group' does is move to the group's line in the
*Group* buffer. Try `gnus-group-read-group' instead. That -- or
something involving that -- ought to do what you want.
Yes, gnus-group-read-group works! The following code takes the current
article and moves it from its original group to a specified trash
group:

#+BEGIN_SRC emacs-lisp
(defun my-nnvirtual-delete-article ()
(interactive)
(let* ((original (nnvirtual-find-group-art
gnus-newsgroup-name
(gnus-summary-article-number)))
(group (car original))
(article (cdr original))
(trash (cl-assoc group my-gnus-trash-locations
:test (lambda (item rx)
(string-match-p rx item)))))
(unless trash
(error "No trash folder configured for group %s" group))
(with-current-buffer gnus-group-buffer
(gnus-group-read-group nil nil group (list article))
(gnus-summary-move-article 1 (cdr trash)))))

(defvar my-gnus-trash-locations
'(("nnmaildir\\+mailbox:.*" . "nnmaildir+mailbox:Trash"))
"Locations of trash folders.")
#+END_SRC

The problem with this code is that I end up in the original group after
the moving/deleting is finished and not in the virtual group. This
surprises me, as I always thought of `with-current-buffer' as a macro
that save my window configuration. Apparently this is not the case, why
is that?

Regards,
--
Alexander Baier
Eric Abrahamsen
2014-10-06 02:44:08 UTC
Permalink
Post by Alexander Baier
Post by Eric Abrahamsen
Post by Alexander Baier
Post by Eric Abrahamsen
Post by Alexander Baier
I want to write my own command that finds the original group of the
article in question and executes the move in that group. Is there a
function that gets me the original group of an article in a virtual
group?
I'm pretty sure that nnvirtual-find-group-art will do what you want.
Feed it the article number of the article under point, along with
gnus-newsgroup-name in the virtual Summary buffer. See how it works!
Thank you for your quick reply! These to functions do what I want and I
get the correct original group and article. But now I am stuck and do
#+BEGIN_SRC emacs-lisp
(defun my-nnvirtual-delete-article ()
(interactive)
(let ((original (nnvirtual-find-group-art
gnus-newsgroup-name
(gnus-summary-article-number))))
(with-current-buffer gnus-group-buffer
(gnus-group-goto-group (car original))
(gnus-summary-goto-article (cdr original)))))
#+END_SRC
All `gnus-group-goto-group' does is move to the group's line in the
*Group* buffer. Try `gnus-group-read-group' instead. That -- or
something involving that -- ought to do what you want.
Yes, gnus-group-read-group works! The following code takes the current
article and moves it from its original group to a specified trash
#+BEGIN_SRC emacs-lisp
(defun my-nnvirtual-delete-article ()
(interactive)
(let* ((original (nnvirtual-find-group-art
gnus-newsgroup-name
(gnus-summary-article-number)))
(group (car original))
(article (cdr original))
(trash (cl-assoc group my-gnus-trash-locations
:test (lambda (item rx)
(string-match-p rx item)))))
(unless trash
(error "No trash folder configured for group %s" group))
(with-current-buffer gnus-group-buffer
(gnus-group-read-group nil nil group (list article))
(gnus-summary-move-article 1 (cdr trash)))))
(defvar my-gnus-trash-locations
'(("nnmaildir\\+mailbox:.*" . "nnmaildir+mailbox:Trash"))
"Locations of trash folders.")
#+END_SRC
The problem with this code is that I end up in the original group after
the moving/deleting is finished and not in the virtual group. This
surprises me, as I always thought of `with-current-buffer' as a macro
that save my window configuration. Apparently this is not the case, why
is that?
That I can't tell you! My only guess is that virtual group *Summary*
buffer is actually getting destroyed in the process of shifting groups
and moving messages, and there's nowhere to return to. You could test by
manually replicating what `with-current-buffer' does: save the current
buffer in your let form, then try to `switch-to-buffer' back to it when
the article's been moved, and see if it still exists.

Eric

Loading...