Gnus development mailing list
 help / color / mirror / Atom feed
* function to access raw article
@ 2014-10-31  8:29 Alexander Baier
  2014-10-31  8:53 ` Igor Sosa Mayor
  2014-10-31 12:55 ` Ted Zlatanov
  0 siblings, 2 replies; 15+ messages in thread
From: Alexander Baier @ 2014-10-31  8:29 UTC (permalink / raw)
  To: ding

Hello,

I want to access the raw (unwashed) version of an article from emacs
lisp to search for a regexp. I do this in order to extract information
from the body of the article to be used in the summary line. I used
`gnus-summary-show-raw-article' which did not seem to work. What is the
preferred way of doing this?

Regards,
-- 
Alexander Baier



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

* Re: function to access raw article
  2014-10-31  8:29 function to access raw article Alexander Baier
@ 2014-10-31  8:53 ` Igor Sosa Mayor
  2014-10-31  9:57   ` Alexander Baier
  2014-10-31 12:55 ` Ted Zlatanov
  1 sibling, 1 reply; 15+ messages in thread
From: Igor Sosa Mayor @ 2014-10-31  8:53 UTC (permalink / raw)
  To: ding

Alexander Baier <alexander.baier@mailbox.org> writes:

> Hello,
>
> I want to access the raw (unwashed) version of an article from emacs
> lisp to search for a regexp. I do this in order to extract information
> from the body of the article to be used in the summary line. I used
> `gnus-summary-show-raw-article' which did not seem to work. What is the
> preferred way of doing this?

I think gnus-summary-show-raw-article should work...

But in any way, I don't think this is necessary to get the summary line
(do you mean 'subject')? What do you want to achieve exactly?

-- 
:: Igor Sosa Mayor     :: joseleopoldo1792@gmail.com ::
:: GnuPG: 0x1C1E2890   :: http://www.gnupg.org/      ::
:: jabberid: rogorido  ::                            ::




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

* Re: function to access raw article
  2014-10-31  8:53 ` Igor Sosa Mayor
@ 2014-10-31  9:57   ` Alexander Baier
  2014-10-31 11:04     ` Steinar Bang
  2014-10-31 14:19     ` Eric Abrahamsen
  0 siblings, 2 replies; 15+ messages in thread
From: Alexander Baier @ 2014-10-31  9:57 UTC (permalink / raw)
  To: Igor Sosa Mayor; +Cc: ding

On 2014-10-31 09:53 Igor Sosa Mayor wrote:
> Alexander Baier <alexander.baier@mailbox.org> writes:
>
>> Hello,
>>
>> I want to access the raw (unwashed) version of an article from emacs
>> lisp to search for a regexp. I do this in order to extract information
>> from the body of the article to be used in the summary line. I used
>> `gnus-summary-show-raw-article' which did not seem to work. What is the
>> preferred way of doing this?
>
> I think gnus-summary-show-raw-article should work...
>
> But in any way, I don't think this is necessary to get the summary line
> (do you mean 'subject')? What do you want to achieve exactly?

I have information in the body of the the article that I want to display
in the summary line. To do this, I wrote a function
gnus-user-format-function-Y that extracts said information from the
body. I then include %uY in my gnus-summary-line-format to include the
information in the summary line. My current function looks like this:

#+BEGIN_SRC emacs-lisp
  (defun gnus-user-format-function-Y (header)
    "Returns the title of a youtube video."
    (with-current-buffer gnus-article-buffer
      (gnus-summary-show-raw-article)
      (gnus-summary-select-article-buffer)
      (goto-char (point-min))
      (search-forward-regexp "\n.*just uploaded a video\n\\(.*\\)\nhttp:.*")
      (match-string-no-properties 1)))
#+END_SRC

If I enter a group with this function specified in the
sumary-line-format I get the following messages in the *Messages* buffer:

Error updating the summary line
Can't find article 832 [2 times]

Furthermore gnus displays
"Hiding all threads... <some fast growing number>" in the echo area and
hangs. When I press C-g I see a garbled summary buffer.

Regards,
-- 
Alexander Baier



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

* Re: function to access raw article
  2014-10-31  9:57   ` Alexander Baier
@ 2014-10-31 11:04     ` Steinar Bang
  2014-10-31 11:43       ` Alexander Baier
  2014-10-31 11:45       ` Igor Sosa Mayor
  2014-10-31 14:19     ` Eric Abrahamsen
  1 sibling, 2 replies; 15+ messages in thread
From: Steinar Bang @ 2014-10-31 11:04 UTC (permalink / raw)
  To: ding

>>>>> Alexander Baier <alexander.baier@mailbox.org>:

> I have information in the body of the the article that I want to
> display in the summary line.

One problem with this, could be that some backends don't have the
article body available at the time of rendering the summary buffer...?
(I think this is the case for nntp, and possibly also nnimap...?)

I think the summary buffer uses what's available in what's returned by
NNTP as NOV data:
 http://tools.ietf.org/html/rfc3977#section-8




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

* Re: function to access raw article
  2014-10-31 11:04     ` Steinar Bang
@ 2014-10-31 11:43       ` Alexander Baier
  2014-10-31 11:45       ` Igor Sosa Mayor
  1 sibling, 0 replies; 15+ messages in thread
From: Alexander Baier @ 2014-10-31 11:43 UTC (permalink / raw)
  To: ding

On 2014-10-31 12:04 Steinar Bang wrote:
>>>>>> Alexander Baier <alexander.baier@mailbox.org>:
>
>> I have information in the body of the the article that I want to
>> display in the summary line.
>
> One problem with this, could be that some backends don't have the
> article body available at the time of rendering the summary buffer...?
> (I think this is the case for nntp, and possibly also nnimap...?)

The backend in question is nnmaildir, which should have access to the
articles body, as it is already locally available in my file
system. The gnus-summary-line-format is set as a group parameter on only
one group, so that it does not interfere with my normal summary line.

Maybe gnus does not expect me to call some article display commands
during the rendering of the summary buffer? Does anyone know any
specifics on this?

> I think the summary buffer uses what's available in what's returned by
> NNTP as NOV data:
>  http://tools.ietf.org/html/rfc3977#section-8

Thank you for the pointer! Sadly this would not be enough for me. :(

Regards,
-- 
Alexander Baier



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

* Re: function to access raw article
  2014-10-31 11:04     ` Steinar Bang
  2014-10-31 11:43       ` Alexander Baier
@ 2014-10-31 11:45       ` Igor Sosa Mayor
  2014-10-31 11:50         ` Alexander Baier
  1 sibling, 1 reply; 15+ messages in thread
From: Igor Sosa Mayor @ 2014-10-31 11:45 UTC (permalink / raw)
  To: ding

Steinar Bang <sb@dod.no> writes:

>>>>>> Alexander Baier <alexander.baier@mailbox.org>:
>
>> I have information in the body of the the article that I want to
>> display in the summary line.
>
> One problem with this, could be that some backends don't have the
> article body available at the time of rendering the summary buffer...?
> (I think this is the case for nntp, and possibly also nnimap...?)

I also think this could be the problem... Have you trie with other
backends? 

-- 
:: Igor Sosa Mayor     :: joseleopoldo1792@gmail.com ::
:: GnuPG: 0x1C1E2890   :: http://www.gnupg.org/      ::
:: jabberid: rogorido  ::                            ::




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

* Re: function to access raw article
  2014-10-31 11:45       ` Igor Sosa Mayor
@ 2014-10-31 11:50         ` Alexander Baier
  0 siblings, 0 replies; 15+ messages in thread
From: Alexander Baier @ 2014-10-31 11:50 UTC (permalink / raw)
  To: Igor Sosa Mayor; +Cc: ding

On 2014-10-31 12:45 Igor Sosa Mayor wrote:
> Steinar Bang <sb@dod.no> writes:
>
>>>>>>> Alexander Baier <alexander.baier@mailbox.org>:
>>
>>> I have information in the body of the the article that I want to
>>> display in the summary line.
>>
>> One problem with this, could be that some backends don't have the
>> article body available at the time of rendering the summary buffer...?
>> (I think this is the case for nntp, and possibly also nnimap...?)
>
> I also think this could be the problem... Have you trie with other
> backends? 

See my previous answer to Steinar's post. I only have nntp and nnmaildir
backends available here. The nnmaildir is the one I am trying it with.

Regards,
-- 
Alexander Baier



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

* Re: function to access raw article
  2014-10-31  8:29 function to access raw article Alexander Baier
  2014-10-31  8:53 ` Igor Sosa Mayor
@ 2014-10-31 12:55 ` Ted Zlatanov
  2014-10-31 13:38   ` Alexander Baier
  1 sibling, 1 reply; 15+ messages in thread
From: Ted Zlatanov @ 2014-10-31 12:55 UTC (permalink / raw)
  To: ding

On Fri, 31 Oct 2014 09:29:41 +0100 Alexander Baier <alexander.baier@mailbox.org> wrote: 

AB> I want to access the raw (unwashed) version of an article from emacs
AB> lisp to search for a regexp. I do this in order to extract information
AB> from the body of the article to be used in the summary line. I used
AB> `gnus-summary-show-raw-article' which did not seem to work. What is the
AB> preferred way of doing this?

Try `spam-get-article-as-string' in spam.el, which is used by spam
backends that need the full article.  But as others said, it may not
work :)

Ted




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

* Re: function to access raw article
  2014-10-31 12:55 ` Ted Zlatanov
@ 2014-10-31 13:38   ` Alexander Baier
  2014-10-31 14:01     ` Alexander Baier
  2014-10-31 14:22     ` Peter Münster
  0 siblings, 2 replies; 15+ messages in thread
From: Alexander Baier @ 2014-10-31 13:38 UTC (permalink / raw)
  To: ding

On 2014-10-31 13:55 Ted Zlatanov wrote:
> On Fri, 31 Oct 2014 09:29:41 +0100 Alexander Baier
> <alexander.baier@mailbox.org> wrote:
>
> AB> I want to access the raw (unwashed) version of an article from emacs
> AB> lisp to search for a regexp. I do this in order to extract information
> AB> from the body of the article to be used in the summary line. I used
> AB> `gnus-summary-show-raw-article' which did not seem to work. What is the
> AB> preferred way of doing this?
>
> Try `spam-get-article-as-string' in spam.el, which is used by spam
> backends that need the full article.  But as others said, it may not
> work :)
>

This is it! The following works like a charm. It is designed to extract
the title of the video from a mail you get from youtube when someone you
are subscribed to uploads a new video.

#+BEGIN_SRC emacs-lisp
  (defun gnus-user-format-function-Y (header)
    "Returns the title of a youtube video."
    (let ((body (spam-get-article-as-string (elt header 0))))
      (string-match "\n.*just uploaded a video\n\\(.*\\)\nhttp:.*" body)
      (match-string-no-properties 1 body)))
#+END_SRC

Thank you Ted, Steinar and Igor! :)

Regards,
-- 
Alexander Baier



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

* Re: function to access raw article
  2014-10-31 13:38   ` Alexander Baier
@ 2014-10-31 14:01     ` Alexander Baier
  2014-10-31 14:22     ` Peter Münster
  1 sibling, 0 replies; 15+ messages in thread
From: Alexander Baier @ 2014-10-31 14:01 UTC (permalink / raw)
  To: ding

On 2014-10-31 14:38 Alexander Baier wrote:
> On 2014-10-31 13:55 Ted Zlatanov wrote:
>> On Fri, 31 Oct 2014 09:29:41 +0100 Alexander Baier
>> <alexander.baier@mailbox.org> wrote:
>>
>> AB> I want to access the raw (unwashed) version of an article from emacs
>> AB> lisp to search for a regexp. I do this in order to extract information
>> AB> from the body of the article to be used in the summary line. I used
>> AB> `gnus-summary-show-raw-article' which did not seem to work. What is the
>> AB> preferred way of doing this?
>>
>> Try `spam-get-article-as-string' in spam.el, which is used by spam
>> backends that need the full article.  But as others said, it may not
>> work :)
>>
>
> This is it! The following works like a charm. It is designed to extract
> the title of the video from a mail you get from youtube when someone you
> are subscribed to uploads a new video.
>
> #+BEGIN_SRC emacs-lisp
>   (defun gnus-user-format-function-Y (header)
>     "Returns the title of a youtube video."
>     (let ((body (spam-get-article-as-string (elt header 0))))
>       (string-match "\n.*just uploaded a video\n\\(.*\\)\nhttp:.*" body)
>       (match-string-no-properties 1 body)))
> #+END_SRC
>
> Thank you Ted, Steinar and Igor! :)
>
> Regards,

I have updated the regexp to catch multiline titles:

#+BEGIN_SRC emacs-lisp
  (defun gnus-user-format-function-Y (header)
    "Returns the title of a youtube video."
    (let ((body (spam-get-article-as-string (elt header 0)))
          (regex (concat "Content-Type: text/plain;.*\n"
                         "\n.*just uploaded a video\n"
                         "\\(.*\\(?:\n.*\\)*?\\)\nhttp:.*")))
      (string-match regex body)
      (s-replace "\n" "" (match-string-no-properties 1 body))))
#+END_SRC

Regards,
-- 
Alexander Baier



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

* Re: function to access raw article
  2014-10-31  9:57   ` Alexander Baier
  2014-10-31 11:04     ` Steinar Bang
@ 2014-10-31 14:19     ` Eric Abrahamsen
  2014-10-31 15:18       ` Alexander Baier
  1 sibling, 1 reply; 15+ messages in thread
From: Eric Abrahamsen @ 2014-10-31 14:19 UTC (permalink / raw)
  To: ding

Alexander Baier <alexander.baier@mailbox.org> writes:

> On 2014-10-31 09:53 Igor Sosa Mayor wrote:
>> Alexander Baier <alexander.baier@mailbox.org> writes:
>>
>>> Hello,
>>>
>>> I want to access the raw (unwashed) version of an article from emacs
>>> lisp to search for a regexp. I do this in order to extract information
>>> from the body of the article to be used in the summary line. I used
>>> `gnus-summary-show-raw-article' which did not seem to work. What is the
>>> preferred way of doing this?
>>
>> I think gnus-summary-show-raw-article should work...
>>
>> But in any way, I don't think this is necessary to get the summary line
>> (do you mean 'subject')? What do you want to achieve exactly?
>
> I have information in the body of the the article that I want to display
> in the summary line. To do this, I wrote a function
> gnus-user-format-function-Y that extracts said information from the
> body. I then include %uY in my gnus-summary-line-format to include the
> information in the summary line. My current function looks like this:
>
> #+BEGIN_SRC emacs-lisp
>   (defun gnus-user-format-function-Y (header)
>     "Returns the title of a youtube video."
>     (with-current-buffer gnus-article-buffer
>       (gnus-summary-show-raw-article)
>       (gnus-summary-select-article-buffer)
>       (goto-char (point-min))
>       (search-forward-regexp "\n.*just uploaded a video\n\\(.*\\)\nhttp:.*")
>       (match-string-no-properties 1)))
> #+END_SRC

Try something like this:

(when (buffer-live-p (get-buffer gnus-original-article-buffer))
  (with-current-buffer gnus-original-article-buffer
    (goto-char (point-min))
    ;;etc
    ))

At any rate, I'm pretty sure you want to be using
gnus-original-article-buffer.

HTH,
Eric




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

* Re: function to access raw article
  2014-10-31 13:38   ` Alexander Baier
  2014-10-31 14:01     ` Alexander Baier
@ 2014-10-31 14:22     ` Peter Münster
  2014-10-31 15:20       ` Alexander Baier
  1 sibling, 1 reply; 15+ messages in thread
From: Peter Münster @ 2014-10-31 14:22 UTC (permalink / raw)
  To: ding

On Fri, Oct 31 2014, Alexander Baier wrote:

> This is it! The following works like a charm. It is designed to extract
> the title of the video from a mail you get from youtube when someone you
> are subscribed to uploads a new video.
>
>   (defun gnus-user-format-function-Y (header)

Hi,

If you ever get performance problems (delays when generating the summary
buffer), then you could let procmail + formail do the job. These tools
can add new header lines, for example:
X-youtube-titles: title 1, title 2, etc.

Or you can rewrite the subject. Then, Gnus won't need to parse the body
no more.

-- 
           Peter




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

* Re: function to access raw article
  2014-10-31 14:19     ` Eric Abrahamsen
@ 2014-10-31 15:18       ` Alexander Baier
  2014-10-31 15:29         ` Eric Abrahamsen
  0 siblings, 1 reply; 15+ messages in thread
From: Alexander Baier @ 2014-10-31 15:18 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: ding

On 2014-10-31 15:19 Eric Abrahamsen wrote:
> Alexander Baier <alexander.baier@mailbox.org> writes:
>
>> On 2014-10-31 09:53 Igor Sosa Mayor wrote:
>>> Alexander Baier <alexander.baier@mailbox.org> writes:
>>>
>>>> Hello,
>>>>
>>>> I want to access the raw (unwashed) version of an article from emacs
>>>> lisp to search for a regexp. I do this in order to extract information
>>>> from the body of the article to be used in the summary line. I used
>>>> `gnus-summary-show-raw-article' which did not seem to work. What is the
>>>> preferred way of doing this?
>>>
>>> I think gnus-summary-show-raw-article should work...
>>>
>>> But in any way, I don't think this is necessary to get the summary line
>>> (do you mean 'subject')? What do you want to achieve exactly?
>>
>> I have information in the body of the the article that I want to display
>> in the summary line. To do this, I wrote a function
>> gnus-user-format-function-Y that extracts said information from the
>> body. I then include %uY in my gnus-summary-line-format to include the
>> information in the summary line. My current function looks like this:
>>
>> #+BEGIN_SRC emacs-lisp
>>   (defun gnus-user-format-function-Y (header)
>>     "Returns the title of a youtube video."
>>     (with-current-buffer gnus-article-buffer
>>       (gnus-summary-show-raw-article)
>>       (gnus-summary-select-article-buffer)
>>       (goto-char (point-min))
>>       (search-forward-regexp "\n.*just uploaded a video\n\\(.*\\)\nhttp:.*")
>>       (match-string-no-properties 1)))
>> #+END_SRC
>
> Try something like this:
>
> (when (buffer-live-p (get-buffer gnus-original-article-buffer))
>   (with-current-buffer gnus-original-article-buffer
>     (goto-char (point-min))
>     ;;etc
>     ))
>
> At any rate, I'm pretty sure you want to be using
> gnus-original-article-buffer.

I tried that and the buffer is never live.

Thanks,
-- 
Alexander Baier



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

* Re: function to access raw article
  2014-10-31 14:22     ` Peter Münster
@ 2014-10-31 15:20       ` Alexander Baier
  0 siblings, 0 replies; 15+ messages in thread
From: Alexander Baier @ 2014-10-31 15:20 UTC (permalink / raw)
  To: Peter Münster; +Cc: ding

On 2014-10-31 15:22 Peter Münster wrote:
> On Fri, Oct 31 2014, Alexander Baier wrote:
>
>> This is it! The following works like a charm. It is designed to extract
>> the title of the video from a mail you get from youtube when someone you
>> are subscribed to uploads a new video.
>>
>>   (defun gnus-user-format-function-Y (header)
>
> Hi,
>
> If you ever get performance problems (delays when generating the summary
> buffer), then you could let procmail + formail do the job. These tools
> can add new header lines, for example:
> X-youtube-titles: title 1, title 2, etc.
>
> Or you can rewrite the subject. Then, Gnus won't need to parse the body
> no more.

Thank you for the pointer! I don't think there will be performance
problems in my particular case, as I always display < 100 articles in
that group.

The advantage of doing it in gnus, is of course, that I do not have to
learn another tool. :)

Regards,
-- 
Alexander Baier



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

* Re: function to access raw article
  2014-10-31 15:18       ` Alexander Baier
@ 2014-10-31 15:29         ` Eric Abrahamsen
  0 siblings, 0 replies; 15+ messages in thread
From: Eric Abrahamsen @ 2014-10-31 15:29 UTC (permalink / raw)
  To: ding

Alexander Baier <alexander.baier@mailbox.org> writes:

> On 2014-10-31 15:19 Eric Abrahamsen wrote:
>> Alexander Baier <alexander.baier@mailbox.org> writes:
>>
>>> On 2014-10-31 09:53 Igor Sosa Mayor wrote:
>>>> Alexander Baier <alexander.baier@mailbox.org> writes:
>>>>
>>>>> Hello,
>>>>>
>>>>> I want to access the raw (unwashed) version of an article from emacs
>>>>> lisp to search for a regexp. I do this in order to extract information
>>>>> from the body of the article to be used in the summary line. I used
>>>>> `gnus-summary-show-raw-article' which did not seem to work. What is the
>>>>> preferred way of doing this?
>>>>
>>>> I think gnus-summary-show-raw-article should work...
>>>>
>>>> But in any way, I don't think this is necessary to get the summary line
>>>> (do you mean 'subject')? What do you want to achieve exactly?
>>>
>>> I have information in the body of the the article that I want to display
>>> in the summary line. To do this, I wrote a function
>>> gnus-user-format-function-Y that extracts said information from the
>>> body. I then include %uY in my gnus-summary-line-format to include the
>>> information in the summary line. My current function looks like this:
>>>
>>> #+BEGIN_SRC emacs-lisp
>>>   (defun gnus-user-format-function-Y (header)
>>>     "Returns the title of a youtube video."
>>>     (with-current-buffer gnus-article-buffer
>>>       (gnus-summary-show-raw-article)
>>>       (gnus-summary-select-article-buffer)
>>>       (goto-char (point-min))
>>>       (search-forward-regexp "\n.*just uploaded a video\n\\(.*\\)\nhttp:.*")
>>>       (match-string-no-properties 1)))
>>> #+END_SRC
>>
>> Try something like this:
>>
>> (when (buffer-live-p (get-buffer gnus-original-article-buffer))
>>   (with-current-buffer gnus-original-article-buffer
>>     (goto-char (point-min))
>>     ;;etc
>>     ))
>>
>> At any rate, I'm pretty sure you want to be using
>> gnus-original-article-buffer.
>
> I tried that and the buffer is never live.

Ah, I wasn't sure if that would be the case. Good to know, I guess...




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

end of thread, other threads:[~2014-10-31 15:29 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-31  8:29 function to access raw article Alexander Baier
2014-10-31  8:53 ` Igor Sosa Mayor
2014-10-31  9:57   ` Alexander Baier
2014-10-31 11:04     ` Steinar Bang
2014-10-31 11:43       ` Alexander Baier
2014-10-31 11:45       ` Igor Sosa Mayor
2014-10-31 11:50         ` Alexander Baier
2014-10-31 14:19     ` Eric Abrahamsen
2014-10-31 15:18       ` Alexander Baier
2014-10-31 15:29         ` Eric Abrahamsen
2014-10-31 12:55 ` Ted Zlatanov
2014-10-31 13:38   ` Alexander Baier
2014-10-31 14:01     ` Alexander Baier
2014-10-31 14:22     ` Peter Münster
2014-10-31 15:20       ` Alexander Baier

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).