Gnus development mailing list
 help / color / mirror / Atom feed
* message-send-mail-function, agent, and a day of work
@ 2004-04-15 16:05 Wes Hardaker
  2004-04-15 17:20 ` Kevin Greiner
  0 siblings, 1 reply; 7+ messages in thread
From: Wes Hardaker @ 2004-04-15 16:05 UTC (permalink / raw)
  Cc: Michael Baer


I spent way too much time the other day figuring out why my simple
code to switch smtp servers was not working and all.  I was properly
setting every variable I could find documented, but the effect seemed
to be nothing.  The end result was because I was running with the
agent turned on, I was missing a variable that is not documented with
the rest of them (which makes some sense, as all the agents stuff is
in one place).

The problem is essentially this:

1) when you read about sending mail, the documentation says that the
   variable 'message-send-mail-function is consulted to figure out how
   to send mail.  This is what I was trying to modify.

2) However, the agent has his own variable for what to do when sending
   anything:  gnus-agent-send-mail-function.

The problem is twofold: first, there is no reference to the second
variable in least a warning in the documentation related to sending
mail.  Since the agent is turned on by default now, this will likely
confuse a lot of people.  Second, the second variable is independent
of the first.  This is part of the confusion.  I think the most simple
solution would be to make the second variable point to a different
function which checks the value of the first variable and uses that
at runtime.  By default they both point at the same value, however, if
the first one changes the second one never picks up that change in
value.

The gnus-agent-send-mail-function variable is set in gnus-agentize as
follows:

  (unless gnus-agent-send-mail-function
    (setq gnus-agent-send-mail-function
	  (or message-send-mail-real-function
	      message-send-mail-function)
	  message-send-mail-real-function 'gnus-agent-send-mail))

I'm suggesting this would be better:

  (defun gnus-agent-use-current-send-mail-function ()
         (funcall (or message-send-mail-real-function
                      message-send-mail-function)))

  (unless gnus-agent-send-mail-function
    (setq gnus-agent-send-mail-function
          'gnus-agent-use-current-send-mail-function))

This way dynamic changes to the message-send-mail-function are picked
up, but it still allows for customization of the agent specifically if
desired.

Thoughts?

-- 
"In the bathtub of history the truth is harder to hold than the soap,
 and much more difficult to find."  -- Terry Pratchett



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

* Re: message-send-mail-function, agent, and a day of work
  2004-04-15 16:05 message-send-mail-function, agent, and a day of work Wes Hardaker
@ 2004-04-15 17:20 ` Kevin Greiner
  2004-04-15 18:26   ` Wes Hardaker
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Greiner @ 2004-04-15 17:20 UTC (permalink / raw)


Wes Hardaker <wes@hardakers.net> writes:

> I spent way too much time the other day figuring out why my simple
> code to switch smtp servers was not working and all.  I was properly
> setting every variable I could find documented, but the effect seemed
> to be nothing.  The end result was because I was running with the
> agent turned on, I was missing a variable that is not documented with
> the rest of them (which makes some sense, as all the agents stuff is
> in one place).
>
> The problem is essentially this:
>
> 1) when you read about sending mail, the documentation says that the
>    variable 'message-send-mail-function is consulted to figure out how
>    to send mail.  This is what I was trying to modify.
>
> 2) However, the agent has his own variable for what to do when sending
>    anything:  gnus-agent-send-mail-function.
>
> The problem is twofold: first, there is no reference to the second
> variable in least a warning in the documentation related to sending
> mail.  Since the agent is turned on by default now, this will likely
> confuse a lot of people.  Second, the second variable is independent
> of the first.  This is part of the confusion.  I think the most simple
> solution would be to make the second variable point to a different
> function which checks the value of the first variable and uses that
> at runtime.  By default they both point at the same value, however, if
> the first one changes the second one never picks up that change in
> value.
>
> The gnus-agent-send-mail-function variable is set in gnus-agentize as
> follows:
>
>   (unless gnus-agent-send-mail-function
>     (setq gnus-agent-send-mail-function
> 	  (or message-send-mail-real-function
> 	      message-send-mail-function)
> 	  message-send-mail-real-function 'gnus-agent-send-mail))
>
> I'm suggesting this would be better:
>
>   (defun gnus-agent-use-current-send-mail-function ()
>          (funcall (or message-send-mail-real-function
>                       message-send-mail-function)))
>
>   (unless gnus-agent-send-mail-function
>     (setq gnus-agent-send-mail-function
>           'gnus-agent-use-current-send-mail-function))
>
> This way dynamic changes to the message-send-mail-function are picked
> up, but it still allows for customization of the agent specifically if
> desired.
>
> Thoughts?

The setq that assigns gnus-agent-send-mail-function must also assign
message-send-mail-real-function so that the mail functions will be
redirected to gnus-agent-send-mail.  Since you left that out, the
agent's ability to queue mail for later transmission is lost.  If we
simply restore the missing assignment, we get an infinite loop as
gnus-agent-send-function calls
gnus-agent-use-current-send-mail-function which funcalls
message-send-mail-real-function (i.e. gnus-agent-send-mail).

Your configuration shouldn't be changing
message-send-mail-real-function so
gnus-agent-use-current-send-mail-function could be re-written to just
funcall message-send-mail-function.

Hmmm.... This should work but it means that the agent will ignore the
initial value of message-send-mail-real-function.  Not at all sure if
that is the right thing to do.

(defun gnus-agent-use-current-send-mail-function ()
       (funcall message-send-mail-function))

(unless gnus-agent-send-mail-function
  (setq gnus-agent-send-mail-function   'gnus-agent-use-current-send-mail-function
        message-send-mail-real-function 'gnus-agent-send-mail))


Now, one question, are you writing your smtp switch logic into the
function called by message-send-mail-function?  I believe that you
must, if you want offline mail to also be send via multiple smtp
servers.

Kevin



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

* Re: message-send-mail-function, agent, and a day of work
  2004-04-15 17:20 ` Kevin Greiner
@ 2004-04-15 18:26   ` Wes Hardaker
  2004-04-15 20:28     ` Kevin Greiner
  0 siblings, 1 reply; 7+ messages in thread
From: Wes Hardaker @ 2004-04-15 18:26 UTC (permalink / raw)
  Cc: ding

>>>>> On Thu, 15 Apr 2004 12:20:31 -0500, Kevin Greiner <kgreiner@xpediantsolutions.com> said:

Kevin> Now, one question, are you writing your smtp switch logic into
Kevin> the function called by message-send-mail-function?  I believe
Kevin> that you must, if you want offline mail to also be send via
Kevin> multiple smtp servers.

Currently its written into a hook call at message-send-hook.  It
decides, based on the contents of the buffer, what to set the
gnus-agent-send-mail-function to (it used to change
message-send-mail-function, which didn't work as previously
discussed).

I haven't tried it off line yet.

My suggestion previously was how to fix the problem of my original
assumption which didn't hold true.  What I'm actually doing now works
just fine, but I'd rather that people not have to spend a day thinking
about it like I did.

-- 
"In the bathtub of history the truth is harder to hold than the soap,
 and much more difficult to find."  -- Terry Pratchett



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

* Re: message-send-mail-function, agent, and a day of work
  2004-04-15 18:26   ` Wes Hardaker
@ 2004-04-15 20:28     ` Kevin Greiner
  2004-04-15 20:35       ` Wes Hardaker
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Greiner @ 2004-04-15 20:28 UTC (permalink / raw)


Wes Hardaker <wes@hardakers.net> writes:

>>>>>> On Thu, 15 Apr 2004 12:20:31 -0500, Kevin Greiner <kgreiner@xpediantsolutions.com> said:
>
> Kevin> Now, one question, are you writing your smtp switch logic into
> Kevin> the function called by message-send-mail-function?  I believe
> Kevin> that you must, if you want offline mail to also be send via
> Kevin> multiple smtp servers.
>
> Currently its written into a hook call at message-send-hook.  It
> decides, based on the contents of the buffer, what to set the
> gnus-agent-send-mail-function to (it used to change
> message-send-mail-function, which didn't work as previously
> discussed).
>
> I haven't tried it off line yet.
>
> My suggestion previously was how to fix the problem of my original
> assumption which didn't hold true.  What I'm actually doing now works
> just fine, but I'd rather that people not have to spend a day thinking
> about it like I did.

Your original assumption should have been valid.  The fact that I
objected to your patch does not mean that the agent is implemented
correctly.  It has a bug that needs to be fixed.  In fact, since I
threw a wrench into your plans, I'll take a stab at patching it for
you.

If you are truely changing your code to set
gnus-agent-send-mail-function then you going down the wrong path.
Your code will now break for those users who have turned the agent off
as gnus-agent-send-mail-function will never be called.

I think that you should really consider how you want to handle offline
and delayed (message drafts) mail before proceeding with
implementation.  When offline, your messages are going to be copied
into the queue group.  When you go online, you have an option to mail
every message in queue. The message-send-hook will, I believe, be
called twice.  The first time will be as the message is added to queue
then again when the message is actually mailed.

I'm going to assume that the mail in queue should be dispatched to
multiple smtp servers so that being offline is transparent to the
actual delivery.  If that is the case, I believe that you'll need to
have the first message-send-hook put the selected smtp server into the
message as a header.  The second message-send-hook could then decode,
and remove, the custom header.

Kevin




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

* Re: message-send-mail-function, agent, and a day of work
  2004-04-15 20:28     ` Kevin Greiner
@ 2004-04-15 20:35       ` Wes Hardaker
  2004-04-15 23:50         ` Kevin Greiner
  0 siblings, 1 reply; 7+ messages in thread
From: Wes Hardaker @ 2004-04-15 20:35 UTC (permalink / raw)
  Cc: ding

>>>>> On Thu, 15 Apr 2004 15:28:28 -0500, Kevin Greiner <kgreiner@xpediantsolutions.com> said:

Kevin> If you are truely changing your code to set
Kevin> gnus-agent-send-mail-function then you going down the wrong
Kevin> path.  Your code will now break for those users who have turned
Kevin> the agent off as gnus-agent-send-mail-function will never be
Kevin> called.

Sorry, I miss-led you.  Thats only in my .gnus file.  I haven't
touched real gnus code yet at this point.

Kevin> I'm going to assume that the mail in queue should be dispatched to
Kevin> multiple smtp servers so that being offline is transparent to the
Kevin> actual delivery.  If that is the case, I believe that you'll need to
Kevin> have the first message-send-hook put the selected smtp server into the
Kevin> message as a header.  The second message-send-hook could then decode,
Kevin> and remove, the custom header.

I actually was using a custom header at one point, but just reverted
to checking the From: header which is really all I care about matching
on.

-- 
"In the bathtub of history the truth is harder to hold than the soap,
 and much more difficult to find."  -- Terry Pratchett



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

* Re: message-send-mail-function, agent, and a day of work
  2004-04-15 20:35       ` Wes Hardaker
@ 2004-04-15 23:50         ` Kevin Greiner
  2004-04-16  4:09           ` Wes Hardaker
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Greiner @ 2004-04-15 23:50 UTC (permalink / raw)


Wes Hardaker <wes@hardakers.net> writes:

>>>>>> On Thu, 15 Apr 2004 15:28:28 -0500, Kevin Greiner <kgreiner@xpediantsolutions.com> said:
>
> Kevin> If you are truely changing your code to set
> Kevin> gnus-agent-send-mail-function then you going down the wrong
> Kevin> path.  Your code will now break for those users who have turned
> Kevin> the agent off as gnus-agent-send-mail-function will never be
> Kevin> called.
>
> Sorry, I miss-led you.  Thats only in my .gnus file.  I haven't
> touched real gnus code yet at this point.
>
> Kevin> I'm going to assume that the mail in queue should be dispatched to
> Kevin> multiple smtp servers so that being offline is transparent to the
> Kevin> actual delivery.  If that is the case, I believe that you'll need to
> Kevin> have the first message-send-hook put the selected smtp server into the
> Kevin> message as a header.  The second message-send-hook could then decode,
> Kevin> and remove, the custom header.
>
> I actually was using a custom header at one point, but just reverted
> to checking the From: header which is really all I care about matching
> on.

I just checked in a patch to gnus-agent that will, if it works is
intended, let you change message-send-mail-function.

I'll also take a look at updating the manual.

Kevin



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

* Re: message-send-mail-function, agent, and a day of work
  2004-04-15 23:50         ` Kevin Greiner
@ 2004-04-16  4:09           ` Wes Hardaker
  0 siblings, 0 replies; 7+ messages in thread
From: Wes Hardaker @ 2004-04-16  4:09 UTC (permalink / raw)
  Cc: ding

>>>>> On Thu, 15 Apr 2004 18:50:15 -0500, Kevin Greiner <kgreiner@xpediantsolutions.com> said:

Kevin> I just checked in a patch to gnus-agent that will, if it works is
Kevin> intended, let you change message-send-mail-function.

Excellent!  I'll give it a shot!

-- 
"In the bathtub of history the truth is harder to hold than the soap,
 and much more difficult to find."  -- Terry Pratchett



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

end of thread, other threads:[~2004-04-16  4:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-15 16:05 message-send-mail-function, agent, and a day of work Wes Hardaker
2004-04-15 17:20 ` Kevin Greiner
2004-04-15 18:26   ` Wes Hardaker
2004-04-15 20:28     ` Kevin Greiner
2004-04-15 20:35       ` Wes Hardaker
2004-04-15 23:50         ` Kevin Greiner
2004-04-16  4:09           ` Wes Hardaker

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