Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* Need help writing predicate function
@ 2023-12-04 16:44 Max Evans
  2023-12-04 18:05 ` Eric S Fraga
  2023-12-05  0:17 ` Bob Newell
  0 siblings, 2 replies; 3+ messages in thread
From: Max Evans @ 2023-12-04 16:44 UTC (permalink / raw)
  To: info-gnus-english

Help, gnus!

I'm trying to write a simple predicate function to use in my
posting-styles, since from my reading of the manual you can't match
two things at once otherwise, which is what I want to do.

I'm trying to make a rule that kicks in only when a certain company
sends me an email AND when it's sent to a particular address. It's
only relevant when I'm replying back to them, though.

Here's what I've got so far:

(defun max-gnus-predicate ()
  (when (eq major-mode 'gnus-article-mode)
    (and (string-match "foo@bar.org" (with-current-buffer gnus-article-buffer
				       (message-fetch-field "from")))
	 (string-match "visitantar+alias@protonmail.com" (with-current-buffer gnus-article-buffer
							   (message-fetch-field "to"))))))
						 
The problem I'm running into is that the function fails if the
*Article* buffer ever gets killed. When that happens, it corrupts the
mail header. Which makes sense with how I've written it.

I'm sure there's a smarter way of doing what I want to do, so would
someone mind helping me out?

(Please keep me in the thread. I'm not subscribed.)

-Max



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

* Re: Need help writing predicate function
  2023-12-04 16:44 Need help writing predicate function Max Evans
@ 2023-12-04 18:05 ` Eric S Fraga
  2023-12-05  0:17 ` Bob Newell
  1 sibling, 0 replies; 3+ messages in thread
From: Eric S Fraga @ 2023-12-04 18:05 UTC (permalink / raw)
  To: info-gnus-english

You might want to look at what gnus does.  In particular, it copies the
article buffer first using gnus-copy-article-buffer (in gnus-msg.el)
before considering the styles.  That copy of the article buffer should
be accessible in your max-gnus-predicate function... if I understand the
gnus code correctly which is a big *if*.

-- 
Eric S Fraga via gnus (Emacs 30.0.50 2023-09-14) on Debian 12.2



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

* Re: Need help writing predicate function
  2023-12-04 16:44 Need help writing predicate function Max Evans
  2023-12-04 18:05 ` Eric S Fraga
@ 2023-12-05  0:17 ` Bob Newell
  1 sibling, 0 replies; 3+ messages in thread
From: Bob Newell @ 2023-12-05  0:17 UTC (permalink / raw)
  To: Max Evans; +Cc: info-gnus-english


I do something similar to change identity and/or input
language based on addressee.  I just put it in a hook
  
(add-hook 'message-setup-hook 'rjn-change-stuff-by-addressee t)

and that works for me; the appropriate identity gets chosen
via gnus-alias-use-identity when the message reply is set up.

My complete code is this.  It is not the same as you ask but
easily modified.  You'd only need the upper half.

(defun rjn-change-stuff-by-addressee ()
  (interactive)
  (let ((addressee (message-fetch-field "To"))
	netaddr person smtppref)
    (if addressee
        (setq netaddr (cadr (mail-extract-address-components addressee))))
    (if netaddr
          (setq person (car (bbdb-search (bbdb-records) :mail netaddr))))
    (if person
        (setq smtppref (bbdb-record-field person 'smtp)))
    (if smtppref
	   (gnus-alias-use-identity smtppref))
    	      ) 

  (let ((addressee (message-fetch-field "To"))
	netaddr person langpref)
    (if addressee
        (setq netaddr (cadr (mail-extract-address-components addressee))))
    (if netaddr
	(progn
          (setq person (car (bbdb-search (bbdb-records) :mail netaddr)))))
	    (if person
		(setq langpref (bbdb-record-field person 'language)))
    (if langpref
	(set-input-method langpref)))
  )

-- 
Bob Newell
Honolulu, Hawai`i

- Via GNU/Linux/Emacs/Gnus/BBDB


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

end of thread, other threads:[~2023-12-05  0:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04 16:44 Need help writing predicate function Max Evans
2023-12-04 18:05 ` Eric S Fraga
2023-12-05  0:17 ` Bob Newell

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