Discussion:
Adding a Bcc in a send-hook
Matthew R. Dempsky
2007-02-28 17:41:46 UTC
Permalink
I'd like to setup mutt to set a ``Bcc: ***@utdallas.edu'' header
field whenever I address email to ``$***@utdallas.edu'' (except when
foo=utdlug). Right now I have the following line in my .muttrc:

send-hook '~t @utdallas\.edu$ !~t ^***@utdallas\.edu$' 'my_hdr "From: ***@student.utdallas.edu" ; my_hdr "Bcc: ***@utdallas.edu"'

The default From field is set as I'd like, but Bcc is not.

Is there another way to achieve the desired effect (i.e., routing an
extra copy of the email to my utdallas.edu mailbox so I can be
informed when their spam filtering software decides to trash my
messages)?

(In case it's relevant, I'm using mutt 1.5.12-hcache from OpenBSD 4.0.)

Thanks.
Kyle Wheeler
2007-02-28 18:11:48 UTC
Permalink
(except when foo=utdlug). Right now I have the following line in my
The default From field is set as I'd like, but Bcc is not.
Which is to be expected. From the manual
(http://www.mutt.org/doc/manual/manual-3.html):

Note: the send-hook's are only executed ONCE after getting the
initial list of recipients. Adding a recipient after replying or
editing the message will NOT cause any send-hook to be executed.
Also note that my_hdr commands which modify recipient headers, or
the message's subject, don't have any effect on the current
message when executed from a send-hook.

Particularly that last bit.
Is there another way to achieve the desired effect (i.e., routing an
extra copy of the email to my utdallas.edu mailbox so I can be
informed when their spam filtering software decides to trash my
messages)?
Sure. One way (this may seem pretty idiotic) is to use 'push' in your
hook, rather than trying to get the hook to do it itself. That allows
mutt to get around to changing the recipients when it is convenient.
Like this:

send-hook '~t @utdallas\.edu$ !~t ^***@utdallas\.edu$' \
'push <edit-bcc>***@utdallas.edu<enter>'

Also, my_hdr is a rather silly way to set your from address. Is there
a reason that you're not using $from? There may be a better way to
achieve what you're after.

~Kyle
- --
Backups are for wimps. Real men upload their data to an FTP site and
have everyone else mirror it.
-- Linus Torvalds
Matthew R. Dempsky
2007-02-28 19:05:35 UTC
Permalink
Post by Kyle Wheeler
Which is to be expected. From the manual
Yeah, someone else quoted that to me before I posted, but I didn't see
it in the man pages.
Post by Kyle Wheeler
Sure. One way (this may seem pretty idiotic) is to use 'push' in your
hook, rather than trying to get the hook to do it itself. That allows
mutt to get around to changing the recipients when it is convenient.
This seems to have a nasty effect if I start composing an email and
then decide to cancel it. (The pushed key presses get sent to the
folder index.) If I could fix that I'd be happy.
Post by Kyle Wheeler
Also, my_hdr is a rather silly way to set your from address. Is there
a reason that you're not using $from? There may be a better way to
achieve what you're after.
I also have

set realname="Matthew R. Dempsky"
set from="***@alkemio.org"
set use_from
set envelope_from
set reverse_name=yes

(and a bunch of alternatives) in my .muttrc to use ***@alkemio.org by
default. I only want to use ***@student.utdallas.edu when
sending email to school faculty/staff.

I tried using

send-hook ... 'set from=***@student.utdallas.edu'

but that sets the from address for all future emails and not the
current one. Is there a different way you had in mind?

Thanks.
Christian Ebert
2007-02-28 20:34:35 UTC
Permalink
Post by Matthew R. Dempsky
Post by Kyle Wheeler
Also, my_hdr is a rather silly way to set your from address. Is there
a reason that you're not using $from? There may be a better way to
achieve what you're after.
I also have
set realname="Matthew R. Dempsky"
set use_from
set envelope_from
set reverse_name=yes
sending email to school faculty/staff.
I tried using
but that sets the from address for all future emails and not the
current one. Is there a different way you had in mind?
The "canonical" way, I believe, is:

set from="***@alkemio.org"
set use_from
# unset overriding header in default hook
send-hook ~A 'un_myhdr From:'
# set overriding header
send-hook faculty|staff '\
my_hdr From: ***@student.utdallas.edu'

c
--
_B A U S T E L L E N_ lesen! --->> <http://www.blacktrash.org/baustellen.html>
Matthew R. Dempsky
2007-02-28 20:40:05 UTC
Permalink
Post by Matthew R. Dempsky
set use_from
# unset overriding header in default hook
send-hook ~A 'un_myhdr From:'
# set overriding header
send-hook faculty|staff '\
Sorry, that's what I already have---I just forgot to mention the
``send-hook ~A ...'' line.
Kyle Wheeler
2007-02-28 21:19:00 UTC
Permalink
Post by Matthew R. Dempsky
Post by Kyle Wheeler
Sure. One way (this may seem pretty idiotic) is to use 'push' in
your hook, rather than trying to get the hook to do it itself. That
allows mutt to get around to changing the recipients when it is
This seems to have a nasty effect if I start composing an email and
then decide to cancel it. (The pushed key presses get sent to the
folder index.) If I could fix that I'd be happy.
Hmmm. I'm not quite sure what you're talking about. When I start
composing a mail, mutt first asks me who I'd like to send it to. If I
cancel out of that, the send-hook is not triggered. If I provide an
address, then it asks me what subject I'd like to use for my mail, and
if I cancel out of THAT, the send-hook is not triggered either. If I
do give it a subject, it launches my editor. I can decide "nah, didn't
want to send it" at that point, but when I exit my editor, I'm
presented the "compose" menu where I can see that the bcc has already
been set. If I cancel sending at that point, there's still no problem
because the push'd commands have already executed.

What method of cancelling sending a mail are you using that causes a
problem with this send-hook?
Post by Matthew R. Dempsky
Post by Kyle Wheeler
Also, my_hdr is a rather silly way to set your from address. Is
there a reason that you're not using $from? There may be a better
way to achieve what you're after.
[snip]
Post by Matthew R. Dempsky
Is there a different way you had in mind?
Nope, guess not. Nevermind then.

~Kyle
- --
Nip the shoots of arbitrary power in the bud, is the only maxim which
can ever preserve the liberties of the people.
-- John Quincy Adams
Matthew R. Dempsky
2007-02-28 21:27:20 UTC
Permalink
I can decide "nah, didn't want to send it" at that point, but when I
exit my editor, I'm presented the "compose" menu where I can see that
the bcc has already been set.
When I exit my editor (mg) without saving, I'm returned to the index
or pager (whichever I was at when I pressed 'm').
Christian Ebert
2007-02-28 22:20:06 UTC
Permalink
Post by Matthew R. Dempsky
I can decide "nah, didn't want to send it" at that point, but when I
exit my editor, I'm presented the "compose" menu where I can see that
the bcc has already been set.
When I exit my editor (mg) without saving, I'm returned to the index
or pager (whichever I was at when I pressed 'm').
That's true. But it gave me the idea to do this entirely in the
editor. For vim it would be (simplified) something like:

send-hook <pattern> '\
set editor="vim -c \"/^Bcc: defaultbcc/s/: .*/: otherbcc/\""'

c
--
_B A U S T E L L E N_ lesen! --->> <http://www.blacktrash.org/baustellen.html>
Nicolas Rachinsky
2007-02-28 21:35:27 UTC
Permalink
Post by Kyle Wheeler
What method of cancelling sending a mail are you using that causes a
problem with this send-hook?
The default of abort_unmodified could cause this, I think.

Nicolas
--
http://www.rachinsky.de/nicolas
Kyle Wheeler
2007-02-28 21:45:29 UTC
Permalink
Post by Nicolas Rachinsky
Post by Kyle Wheeler
What method of cancelling sending a mail are you using that causes a
problem with this send-hook?
The default of abort_unmodified could cause this, I think.
Ahhh. Hmm. Well, then I'm out of ideas.

~Kyle
- --
All men by nature desire to know.
-- Aristotle
Christian Ebert
2007-02-28 19:39:52 UTC
Permalink
Post by Kyle Wheeler
Post by Matthew R. Dempsky
Is there another way to achieve the desired effect (i.e., routing an
extra copy of the email to my utdallas.edu mailbox so I can be
informed when their spam filtering software decides to trash my
messages)?
Sure. One way (this may seem pretty idiotic) is to use 'push' in your
hook, rather than trying to get the hook to do it itself. That allows
mutt to get around to changing the recipients when it is convenient.
Wow! I was always looking for a away to circumvent the send-hook
restriction concerning recipients. This might be idiotic but the
hack is extremely useful for me. Thanks for sharing this!

c
--
_B A U S T E L L E N_ lesen! --->> <http://www.blacktrash.org/baustellen.html>
Loading...