Gnus development mailing list
 help / color / mirror / Atom feed
* letting split rules have access to the message body...
@ 2001-05-10 21:30 Josh Huber
  2001-05-11 13:20 ` Josh Huber
  2001-05-11 22:50 ` Kai Großjohann
  0 siblings, 2 replies; 8+ messages in thread
From: Josh Huber @ 2001-05-10 21:30 UTC (permalink / raw)


This was brought up a week or two ago, and people (Kai?) just said,
well...why don't you just do:

(save-restriction
    (widen)
    ...
    )

well, that didn't work for me, and I'm not quite sure how it would
work due to this little snippit of code in nnmail-article-group, which
does this:

	;; Find headers.
	(goto-char beg)
	(setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
	(set-buffer nntp-server-buffer)
	(erase-buffer)
	;; Copy the headers into the work buffer.
	(insert-buffer-substring obuf beg end)

thus, the original contents of the message are NOT accessible to the
split rules, even if you (widen).  Unless that is, I'm missing
something, which I could be...this is my first gnus source hack, so
here it goes.  I tested this on the re-spooling of *one* (1) message,
and disabled it, because I want to see if there could be any unwanted
side-effects, and how to fix them if there are problems:

Index: nnmail.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/nnmail.el,v
retrieving revision 6.13
diff -u -r6.13 nnmail.el
--- nnmail.el   2001/04/29 12:36:09     6.13
+++ nnmail.el   2001/05/10 21:23:41
@@ -941,8 +941,9 @@
        (setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
        (set-buffer nntp-server-buffer)
        (erase-buffer)
-       ;; Copy the headers into the work buffer.
-       (insert-buffer-substring obuf beg end)
+       ;; Copy the whole buffer in, and narrow to the headers...
+       (insert-buffer obuf)
+       (narrow-to-region beg end)
        ;; Fold continuation lines.
        (goto-char (point-min))
        (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)


This seems sane to me, but I'm looking for comments.  I don't want my
mail to blow up due to this small change :)

Thanks,

-- 
Josh Huber


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

* Re: letting split rules have access to the message body...
  2001-05-10 21:30 letting split rules have access to the message body Josh Huber
@ 2001-05-11 13:20 ` Josh Huber
  2001-05-11 22:50 ` Kai Großjohann
  1 sibling, 0 replies; 8+ messages in thread
From: Josh Huber @ 2001-05-11 13:20 UTC (permalink / raw)


Josh Huber <huber@alum.wpi.edu> writes:

> This seems sane to me, but I'm looking for comments.  I don't want my
> mail to blow up due to this small change :)

Well, it blew up for spool files, but I think this is a fixed diff.
Anyone have comments?  I'm using this now, and it seems to work well
for my setup:

Index: nnmail.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/nnmail.el,v
retrieving revision 6.13
diff -u -r6.13 nnmail.el
--- nnmail.el	2001/04/29 12:36:09	6.13
+++ nnmail.el	2001/05/11 13:05:20
@@ -938,11 +938,13 @@
       (save-excursion
 	;; Find headers.
 	(goto-char beg)
+	(setq max (point-max))
 	(setq end (if (search-forward "\n\n" nil t) (point) (point-max)))
 	(set-buffer nntp-server-buffer)
 	(erase-buffer)
-	;; Copy the headers into the work buffer.
-	(insert-buffer-substring obuf beg end)
+	;; Copy the whole buffer in, and narrow to the headers...
+	(insert-buffer-substring obuf beg max)
+	(narrow-to-region (point-min) (- end beg))
 	;; Fold continuation lines.
 	(goto-char (point-min))
 	(while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t)


-- 
Josh Huber


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

* Re: letting split rules have access to the message body...
  2001-05-10 21:30 letting split rules have access to the message body Josh Huber
  2001-05-11 13:20 ` Josh Huber
@ 2001-05-11 22:50 ` Kai Großjohann
  2001-05-14 19:13   ` Josh Huber
  1 sibling, 1 reply; 8+ messages in thread
From: Kai Großjohann @ 2001-05-11 22:50 UTC (permalink / raw)


On 10 May 2001, Josh Huber wrote:

> This was brought up a week or two ago, and people (Kai?) just said,
> well...why don't you just do:
> 
> (save-restriction
>     (widen)
>     ...
>     )

Stupid me.  There should be a save-excursion and a switch to
gnus-original-article-buffer in there, I think.

kai
-- 
The passive voice should never be used.


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

* Re: letting split rules have access to the message body...
  2001-05-11 22:50 ` Kai Großjohann
@ 2001-05-14 19:13   ` Josh Huber
  2001-05-14 20:16     ` Kai Großjohann
  0 siblings, 1 reply; 8+ messages in thread
From: Josh Huber @ 2001-05-14 19:13 UTC (permalink / raw)


Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:

> Stupid me.  There should be a save-excursion and a switch to
> gnus-original-article-buffer in there, I think.

You're absolutely right.  Thanks for the tip.

it would be nice if that sequence was documented in the manual. i.e.:

"If you want access to the full message body in a function called from
 a split rule, you'll have to do the following:

 (save-excursion
   (set-buffer gnus-original-article-buffer)
     ...
   )
"

Thanks,

-- 
Josh Huber


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

* Re: letting split rules have access to the message body...
  2001-05-14 19:13   ` Josh Huber
@ 2001-05-14 20:16     ` Kai Großjohann
  2001-05-14 21:18       ` Josh Huber
  0 siblings, 1 reply; 8+ messages in thread
From: Kai Großjohann @ 2001-05-14 20:16 UTC (permalink / raw)


On 14 May 2001, Josh Huber wrote:

> it would be nice if that sequence was documented in the
> manual. i.e.: [...]

It seems this has been done, at least in CVS:

/----[ from the Gnus info file, node `Fancy Mail Splitting' ]
|   6. `(: FUNCTION ARG1 ARG2 ...)':  If the split is a list, and the
|      first element is `:', then the second element will be called as a
|      function with ARGS given as arguments.  The function should return
|      a SPLIT.
| 
|      For instance, the following function could be used to split based
|      on the body of the messages:
| 
|           (defun split-on-body ()
|             (save-excursion
|               (set-buffer " *nnmail incoming*")
|               (goto-char (point-min))
|               (when (re-search-forward "Some.*string" nil t)
|                 "string.group")))
| 
|      The `" *nnmail incoming*"' is narrowed to the message in question
|      when the `:' function is run.
\----

Is this enough?

kai
-- 
The passive voice should never be used.


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

* Re: letting split rules have access to the message body...
  2001-05-14 20:16     ` Kai Großjohann
@ 2001-05-14 21:18       ` Josh Huber
  2001-05-15  9:24         ` Kai Großjohann
  0 siblings, 1 reply; 8+ messages in thread
From: Josh Huber @ 2001-05-14 21:18 UTC (permalink / raw)


Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:

> It seems this has been done, at least in CVS:
> 
> /----[ from the Gnus info file, node `Fancy Mail Splitting' ]
> |   6. `(: FUNCTION ARG1 ARG2 ...)':  If the split is a list, and the
> |      first element is `:', then the second element will be called as a
> |      function with ARGS given as arguments.  The function should return
> |      a SPLIT.
> | 
> |      For instance, the following function could be used to split based
> |      on the body of the messages:
> | 
> |           (defun split-on-body ()
> |             (save-excursion
> |               (set-buffer " *nnmail incoming*")
> |               (goto-char (point-min))
> |               (when (re-search-forward "Some.*string" nil t)
> |                 "string.group")))
> | 
> |      The `" *nnmail incoming*"' is narrowed to the message in question
> |      when the `:' function is run.
> \----
> 
> Is this enough?

Yes, except could you explain the wording for me?

when it says:

"The `" *nnmail incoming*"' is narrowed to the message in question
 when the `:' function is run."

Does this mean that if I (widen), i could potentially get other
messages?  In other words, is there a buffer that contains the
contents of the incoming spool file, which is then narrowed to each
message in turn?

I need to be able to narrow to the body of the message, the headers or
both.

Is it possible (for example) to narrow to the body of the already
narrowed region, and somehow widen to the previously narrowed region?
something like pop-narrow? :)

Thanks,

-- 
Josh Huber


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

* Re: letting split rules have access to the message body...
  2001-05-14 21:18       ` Josh Huber
@ 2001-05-15  9:24         ` Kai Großjohann
  2001-05-15 16:33           ` Josh Huber
  0 siblings, 1 reply; 8+ messages in thread
From: Kai Großjohann @ 2001-05-15  9:24 UTC (permalink / raw)


On 14 May 2001, Josh Huber wrote:

> Is it possible (for example) to narrow to the body of the already
> narrowed region, and somehow widen to the previously narrowed
> region?  something like pop-narrow? :)

I'm sure that

    (save-restriction
      ...narrow to headers...)
    (save-restriction
      ...narrow to body...)

does the right thing: after the first save-restriction returns, the
previous narrowing is in effect.  save-restriction is like let for
narrowing boundaries.

kai
-- 
The passive voice should never be used.


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

* Re: letting split rules have access to the message body...
  2001-05-15  9:24         ` Kai Großjohann
@ 2001-05-15 16:33           ` Josh Huber
  0 siblings, 0 replies; 8+ messages in thread
From: Josh Huber @ 2001-05-15 16:33 UTC (permalink / raw)


Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes:

> I'm sure that
> 
>     (save-restriction
>       ...narrow to headers...)
>     (save-restriction
>       ...narrow to body...)

Right, this does the right thing.

> does the right thing: after the first save-restriction returns, the
> previous narrowing is in effect.  save-restriction is like let for
> narrowing boundaries.

What I was hoping to do was something like

(save-restriction
  (...narrow to some region...)
  ...do some work...
  (widen)
  ...do more work...
  )

but this would widen it to the full buffer, correct?

In any case, it's easy to re-work the code I'm working to just wrap
the areas where I narrow with save-restriction.  Thats better than
copying the whole article to a separate buffer...since the message
could be very large.

Thanks for the help,

-- 
Josh Huber


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

end of thread, other threads:[~2001-05-15 16:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-10 21:30 letting split rules have access to the message body Josh Huber
2001-05-11 13:20 ` Josh Huber
2001-05-11 22:50 ` Kai Großjohann
2001-05-14 19:13   ` Josh Huber
2001-05-14 20:16     ` Kai Großjohann
2001-05-14 21:18       ` Josh Huber
2001-05-15  9:24         ` Kai Großjohann
2001-05-15 16:33           ` Josh Huber

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