Gnus development mailing list
 help / color / mirror / Atom feed
* Hooks for moving an article and for setting it expirable
@ 2014-08-05 16:26 Christopher Culver
  2014-08-07 20:45 ` Adam Sjøgren
  2014-08-08  1:59 ` Eric Abrahamsen
  0 siblings, 2 replies; 14+ messages in thread
From: Christopher Culver @ 2014-08-05 16:26 UTC (permalink / raw)
  To: ding

I’d like to configure gnus so that when I move (with the keyboard
command B m) an e-mail out of my inbox into another mail group, it
automatically runs the article through a pipe (to train my spam
filter). Ditto for setting an message expirable (with the keyboard
command E).

I’ve had a look at the "Function Hooks" chapter in the Gnus manual, but
I cannot find an appropriate hook for when an article is moved or when
it is marked expirable. Do such hooks exist?




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-05 16:26 Hooks for moving an article and for setting it expirable Christopher Culver
@ 2014-08-07 20:45 ` Adam Sjøgren
  2014-08-08  1:59 ` Eric Abrahamsen
  1 sibling, 0 replies; 14+ messages in thread
From: Adam Sjøgren @ 2014-08-07 20:45 UTC (permalink / raw)
  To: ding

Christopher Culver <crculver@christopherculver.com> writes:

> I’d like to configure gnus so that when I move (with the keyboard
> command B m) an e-mail out of my inbox into another mail group, it
> automatically runs the article through a pipe (to train my spam
> filter). Ditto for setting an message expirable (with the keyboard
> command E).

The spam-handling part of Gnus can do similar things to this (and much,
much more).

May be worth a look :-)


  Best regards,

    Adam

-- 
 "I say, either agree with me or take a hike! I'm             Adam Sjøgren
  right, period! End of discussion!"                     asjo@koldfront.dk




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-05 16:26 Hooks for moving an article and for setting it expirable Christopher Culver
  2014-08-07 20:45 ` Adam Sjøgren
@ 2014-08-08  1:59 ` Eric Abrahamsen
  2014-08-17 20:10   ` Christopher Culver
  1 sibling, 1 reply; 14+ messages in thread
From: Eric Abrahamsen @ 2014-08-08  1:59 UTC (permalink / raw)
  To: ding

Christopher Culver <crculver@christopherculver.com> writes:

> I’d like to configure gnus so that when I move (with the keyboard
> command B m) an e-mail out of my inbox into another mail group, it
> automatically runs the article through a pipe (to train my spam
> filter). Ditto for setting an message expirable (with the keyboard
> command E).
>
> I’ve had a look at the "Function Hooks" chapter in the Gnus manual, but
> I cannot find an appropriate hook for when an article is moved or when
> it is marked expirable. Do such hooks exist?

Adam's probably right, but to answer your question directly:

gnus-summary-article-move-hook
gnus-summary-article-expire-hook

E




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-08  1:59 ` Eric Abrahamsen
@ 2014-08-17 20:10   ` Christopher Culver
  2014-08-18  0:03     ` Eric Abrahamsen
  0 siblings, 1 reply; 14+ messages in thread
From: Christopher Culver @ 2014-08-17 20:10 UTC (permalink / raw)
  To: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> Christopher Culver <crculver@christopherculver.com> writes:
>> I’ve had a look at the "Function Hooks" chapter in the Gnus manual, but
>> I cannot find an appropriate hook for when an article is moved or when
>> it is marked expirable. Do such hooks exist?
>
> gnus-summary-article-move-hook
> gnus-summary-article-expire-hook

Thanks, it is very strange that there is no mention of this in the
officially hosted Gnus manual. But when you attach a function to
these hooks, what arguments exactly is the function called with?




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-17 20:10   ` Christopher Culver
@ 2014-08-18  0:03     ` Eric Abrahamsen
  2014-08-18 13:47       ` Christopher Culver
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Abrahamsen @ 2014-08-18  0:03 UTC (permalink / raw)
  To: ding

Christopher Culver <crculver@christopherculver.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>> Christopher Culver <crculver@christopherculver.com> writes:
>>> I’ve had a look at the "Function Hooks" chapter in the Gnus manual, but
>>> I cannot find an appropriate hook for when an article is moved or when
>>> it is marked expirable. Do such hooks exist?
>>
>> gnus-summary-article-move-hook
>> gnus-summary-article-expire-hook
>
> Thanks, it is very strange that there is no mention of this in the
> officially hosted Gnus manual. But when you attach a function to
> these hooks, what arguments exactly is the function called with?

Hmm, it is a little unfortunate that the docstrings of those hooks don't
say... Both of them are called with the same arguments: ACTION (which
can be a symbol like move, delete, crosspost, or copy), DATA (which is
the header data as returned by `gnus-data-header'), FROM-GROUP (where
the article's coming from), TO-GROUP (where it's going), and
SELECT-METHOD, for the current select method.

See, for example, the body of `gnus-summary-move-article' for both the
move hook and the delete hook in action.

Hope that helps,
Eric




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-18  0:03     ` Eric Abrahamsen
@ 2014-08-18 13:47       ` Christopher Culver
  2014-08-18 14:25         ` Eric Abrahamsen
  0 siblings, 1 reply; 14+ messages in thread
From: Christopher Culver @ 2014-08-18 13:47 UTC (permalink / raw)
  To: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> Hmm, it is a little unfortunate that the docstrings of those hooks don't
> say... Both of them are called with the same arguments: ACTION (which
> can be a symbol like move, delete, crosspost, or copy), DATA (which is
> the header data as returned by `gnus-data-header'), FROM-GROUP (where
> the article's coming from), TO-GROUP (where it's going), and
> SELECT-METHOD, for the current select method.

Strange, I would have expected one of the arguments to be the article
itself, not just the header. If I want a function called by a hook to do
something with the raw article, how can I get the raw article passed to
the function? Or can I simply call gnus-summary-save-in-pipe from within
the function and it would know to act on the article(s) presently being
moved or deleted? My knowledge of Emacs Lisp is still rudimentary and
maybe I don’t understand the scoping.

Christopher Culver




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-18 13:47       ` Christopher Culver
@ 2014-08-18 14:25         ` Eric Abrahamsen
  2014-08-18 15:27           ` Christopher Culver
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Abrahamsen @ 2014-08-18 14:25 UTC (permalink / raw)
  To: ding

Christopher Culver <crculver@christopherculver.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>> Hmm, it is a little unfortunate that the docstrings of those hooks don't
>> say... Both of them are called with the same arguments: ACTION (which
>> can be a symbol like move, delete, crosspost, or copy), DATA (which is
>> the header data as returned by `gnus-data-header'), FROM-GROUP (where
>> the article's coming from), TO-GROUP (where it's going), and
>> SELECT-METHOD, for the current select method.
>
> Strange, I would have expected one of the arguments to be the article
> itself, not just the header. If I want a function called by a hook to do
> something with the raw article, how can I get the raw article passed to
> the function? Or can I simply call gnus-summary-save-in-pipe from within
> the function and it would know to act on the article(s) presently being
> moved or deleted? My knowledge of Emacs Lisp is still rudimentary and
> maybe I don’t understand the scoping.
>
> Christopher Culver

Actually the data argument should be all you need. It will contain
several of the important email headers from the message, if that's good
enough, and that it isn't good enough, it also contains the article
number, which is all you need to retrieve the whole article.

Part of the confusing thing about this is that it's hard to tell what
"the article" actually is. As far as Gnus is concerned, the article
number is the important thing. But when you say you want the "raw
article" passed to the function, what does that mean, exactly? A buffer
holding the article? The article as a string? Practically speaking, you
can use that data to do pretty much anything you wanted to do with the
article.

I know that's not that helpful...

Eric




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-18 14:25         ` Eric Abrahamsen
@ 2014-08-18 15:27           ` Christopher Culver
  2014-08-18 17:16             ` Christopher Culver
  0 siblings, 1 reply; 14+ messages in thread
From: Christopher Culver @ 2014-08-18 15:27 UTC (permalink / raw)
  To: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> Actually the data argument should be all you need. It will contain
> several of the important email headers from the message, if that's good
> enough, and that it isn't good enough, it also contains the article
> number, which is all you need to retrieve the whole article.

OK, that’s good. I’ve already written quite a bit of a function to do
what I need, assuming that I can get the article number and then
retrieve the raw article with that information.

The problem now is that I have no idea what type gnus-data-header
returns. Emacs' describe-function is not helpful. Is it a string
equivalent to the header portion of the maildir file? Is it a key-values
list, and if so, what the keys?

It’s strange that a lot of these features of gnus, though they are
useful for extending it, are not documented at all. Once I get my own
extension working correctly, I hope that a patch to provide a bare
minimum of documentation on these variables and functions will be
accepted.

Christopher Culver




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-18 15:27           ` Christopher Culver
@ 2014-08-18 17:16             ` Christopher Culver
  2014-08-19  1:16               ` Eric Abrahamsen
  0 siblings, 1 reply; 14+ messages in thread
From: Christopher Culver @ 2014-08-18 17:16 UTC (permalink / raw)
  To: ding

Christopher Culver <crculver@christopherculver.com> writes:
> The problem now is that I have no idea what type gnus-data-header
> returns. Emacs' describe-function is not helpful. Is it a string
> equivalent to the header portion of the maildir file? Is it a key-values
> list, and if so, what the keys?

Printing the object to a buffer, I see that gnus-data-header returns an
array (vector table), where the article number is the first item (index
0). So, now I can work with this. But it is a pity that it is not
documented.




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-18 17:16             ` Christopher Culver
@ 2014-08-19  1:16               ` Eric Abrahamsen
  2014-08-20 18:16                 ` Christopher Culver
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Abrahamsen @ 2014-08-19  1:16 UTC (permalink / raw)
  To: ding

Christopher Culver <crculver@christopherculver.com> writes:

> Christopher Culver <crculver@christopherculver.com> writes:
>> The problem now is that I have no idea what type gnus-data-header
>> returns. Emacs' describe-function is not helpful. Is it a string
>> equivalent to the header portion of the maildir file? Is it a key-values
>> list, and if so, what the keys?
>
> Printing the object to a buffer, I see that gnus-data-header returns an
> array (vector table), where the article number is the first item (index
> 0). So, now I can work with this. But it is a pity that it is not
> documented.

In gnus-sum.el there are a series of `gnus-data-*' functions for working
with the data vector, there's a `gnus-data-number', for instance. Of
course, all that does is take the car of the vector! But if you're doing
more than that, it's probably better to use the pre-made functions.

It's true, there's not a lot of documentation in this area, either in
the manual or the docstrings. Have you read the Gnus Reference Guide
section of the info manual? It's fairly well hidden -- I only recently
found it, in the Appendices section -- but it explains some of the
internals. Not the data vector, though. There's also a
`gnus-with-article' macro, but that actually edits the article, and then
replaces the old one with the newly edited version.

Eric





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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-19  1:16               ` Eric Abrahamsen
@ 2014-08-20 18:16                 ` Christopher Culver
  2014-08-24  3:22                   ` Eric Abrahamsen
  0 siblings, 1 reply; 14+ messages in thread
From: Christopher Culver @ 2014-08-20 18:16 UTC (permalink / raw)
  To: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> In gnus-sum.el there are a series of `gnus-data-*' functions for
> working with the data vector, there's a `gnus-data-number', for
> instance. Of course, all that does is take the car of the vector! But
> if you're doing more than that, it's probably better to use the
> pre-made functions.

How does one use that? To save the article number as a variable specific
to the function I’m writing, I had (defvar the-article-number (aref
data-header 0)), which works. However, changing that to
(gnus-data-number data-header) gives an error.

The problem now with my function is that gnus-article-move-hook is
apparently called *after* the message has been totally moved from the
group in question and deleted from the summary buffer. Without the
article still present in the summary buffer, I cannot use the following
functions that I had expected to:

(gnus-summary-goto-subject the-article-number)  
(gnus-summary-save-in-pipe "my-piped-command" t)

Trying to use those functions results in the following error message:

No such file: /home/crculver/Mail/mail/misc/54433
No such article (may have expired or been canceled)

Does Gnus have a way of accessing messages in other groups than what is
visible in the summary buffer? Of course, the article number will change in
the group to which the message is moved.

Or is there a way to run the gnus-article-move-hook function *prior* to
the moving of the message?

With any hooked function, there's a desire to have access to the message
in question, since one might want to perform an action depending on its
contents. I hope I haven’t run into a fundamental design limitation of
Gnus here.




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-20 18:16                 ` Christopher Culver
@ 2014-08-24  3:22                   ` Eric Abrahamsen
  2014-08-26 23:50                     ` Christopher Culver
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Abrahamsen @ 2014-08-24  3:22 UTC (permalink / raw)
  To: ding

Christopher Culver <crculver@christopherculver.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>> In gnus-sum.el there are a series of `gnus-data-*' functions for
>> working with the data vector, there's a `gnus-data-number', for
>> instance. Of course, all that does is take the car of the vector! But
>> if you're doing more than that, it's probably better to use the
>> pre-made functions.
>
> How does one use that? To save the article number as a variable specific
> to the function I’m writing, I had (defvar the-article-number (aref
> data-header 0)), which works. However, changing that to
> (gnus-data-number data-header) gives an error.

Huh, that's weird, I don't see why (aref ARRAY 0) would be any different
from (car ARRAY)... What error do you get?

> The problem now with my function is that gnus-article-move-hook is
> apparently called *after* the message has been totally moved from the
> group in question and deleted from the summary buffer. Without the
> article still present in the summary buffer, I cannot use the following
> functions that I had expected to:
>
> (gnus-summary-goto-subject the-article-number)  
> (gnus-summary-save-in-pipe "my-piped-command" t)
>
> Trying to use those functions results in the following error message:
>
> No such file: /home/crculver/Mail/mail/misc/54433
> No such article (may have expired or been canceled)
>
> Does Gnus have a way of accessing messages in other groups than what is
> visible in the summary buffer? Of course, the article number will change in
> the group to which the message is moved.
>
> Or is there a way to run the gnus-article-move-hook function *prior* to
> the moving of the message?

There are several dynamic variables bound during
`gnus-summary-move-article' that you might be able to use. In the
message moving loop, the variables to-group and to-article *ought* to be
bound to the destination group, and the message's new article number in
that group. Maybe try using those variables in your hook function to
find the article at its new location?

HTH,
Eric




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-24  3:22                   ` Eric Abrahamsen
@ 2014-08-26 23:50                     ` Christopher Culver
  2014-08-27  2:07                       ` Eric Abrahamsen
  0 siblings, 1 reply; 14+ messages in thread
From: Christopher Culver @ 2014-08-26 23:50 UTC (permalink / raw)
  To: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> Christopher Culver <crculver@christopherculver.com> writes:
>> Does Gnus have a way of accessing messages in other groups than what
>> is visible in the summary buffer? Of course, the article number will
>> change in the group to which the message is moved. Or is there a way
>> to run the gnus-article-move-hook function *prior* to the moving of
>> the message?
>
> There are several dynamic variables bound during
> `gnus-summary-move-article' that you might be able to use. In the
> message moving loop, the variables to-group and to-article *ought* to be
> bound to the destination group, and the message's new article number in
> that group. Maybe try using those variables in your hook function to
> find the article at its new location?

If the Gnus internals create a variable referring to the to-article, how
do I access it? Attempting to do perform an action with a variable
"to-article" produces the error:

Symbol's value as variable is void: to-article

So, the only variables I seem to be able to access are the ones passed
by gnus-summary-article-move-hook to the hooked function: (action
data-header from &optional to method). And here the value of "to" is
only the destination group, not the destination message.

Christopher Culver




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

* Re: Hooks for moving an article and for setting it expirable
  2014-08-26 23:50                     ` Christopher Culver
@ 2014-08-27  2:07                       ` Eric Abrahamsen
  0 siblings, 0 replies; 14+ messages in thread
From: Eric Abrahamsen @ 2014-08-27  2:07 UTC (permalink / raw)
  To: ding

Christopher Culver <crculver@christopherculver.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>> Christopher Culver <crculver@christopherculver.com> writes:
>>> Does Gnus have a way of accessing messages in other groups than what
>>> is visible in the summary buffer? Of course, the article number will
>>> change in the group to which the message is moved. Or is there a way
>>> to run the gnus-article-move-hook function *prior* to the moving of
>>> the message?
>>
>> There are several dynamic variables bound during
>> `gnus-summary-move-article' that you might be able to use. In the
>> message moving loop, the variables to-group and to-article *ought* to be
>> bound to the destination group, and the message's new article number in
>> that group. Maybe try using those variables in your hook function to
>> find the article at its new location?
>
> If the Gnus internals create a variable referring to the to-article, how
> do I access it? Attempting to do perform an action with a variable
> "to-article" produces the error:
>
> Symbol's value as variable is void: to-article

Sorry, I wasn't looking closely enough at the code -- to-article is
already out of scope by the time the hook is run.

> So, the only variables I seem to be able to access are the ones passed
> by gnus-summary-article-move-hook to the hooked function: (action
> data-header from &optional to method). And here the value of "to" is
> only the destination group, not the destination message.

Yup, unfortunately I don't see any way of getting at the new article
number, it's just not present. It would make a lot of sense to me to
have that available to the hook functions, but it's not possible right
now. There might be some objection to changing the calling signature of
the hook functions, as well...

Eric




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

end of thread, other threads:[~2014-08-27  2:07 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-05 16:26 Hooks for moving an article and for setting it expirable Christopher Culver
2014-08-07 20:45 ` Adam Sjøgren
2014-08-08  1:59 ` Eric Abrahamsen
2014-08-17 20:10   ` Christopher Culver
2014-08-18  0:03     ` Eric Abrahamsen
2014-08-18 13:47       ` Christopher Culver
2014-08-18 14:25         ` Eric Abrahamsen
2014-08-18 15:27           ` Christopher Culver
2014-08-18 17:16             ` Christopher Culver
2014-08-19  1:16               ` Eric Abrahamsen
2014-08-20 18:16                 ` Christopher Culver
2014-08-24  3:22                   ` Eric Abrahamsen
2014-08-26 23:50                     ` Christopher Culver
2014-08-27  2:07                       ` Eric Abrahamsen

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 NNTP newsgroup(s).