Gnus development mailing list
 help / color / mirror / Atom feed
* multiple gmail accounts: smtp and expiry
@ 2012-04-14 17:36 George McNinch
  2012-04-17 12:43 ` Sivaram Neelakantan
  0 siblings, 1 reply; 6+ messages in thread
From: George McNinch @ 2012-04-14 17:36 UTC (permalink / raw)
  To: info-gnus-english; +Cc: ding

Hi,

To the extent that this is useful, I thought I'd share some
idea(s)/solution(s) to issues related to smtp and expiry for multiple
gmail accounts in gnus.

* expiry

I want expired mail from a gmail account to expire to the "correct"
[GMail]/Trash folder(s) for the account.  After some pondering, the
following seems to work. I'd be interested in alternate suggestions,
though.

Suppose that I have two gnus imap groups corresponding to gmail
accounts:

nnimap+gmail1
nnimap+gmail2

Use the following to create the per-group "expiry targets".

;----------------------------------------
 (setq gm-gmail1-expiry-targets
       (list (from ".*" "nnimap+gmail1:[Gmail]/Trash"))
 
 (setq gm-gmail2-expiry-targets
       (list (from ".*" "nnimap+gmail2:[Gmail]/Trash"))
       
 (defun gm-gmail1-expiry-target-function (group)
   (setq nnmail-fancy-expiry-targets gm-gmail1-expiry-targets)
   (nnmail-fancy-expiry-target group))

 (defun gm-gmail2-expiry-target-function (group)
   (setq nnmail-fancy-expiry-targets gm-gmail2-expiry-targets)
   (nnmail-fancy-expiry-target group))
;----------------------------------------

Now use gnus-parameters (or group parameters, or topic parameters)
to connect the expiry functions:

;----------------------------------------
 (setq gnus-parameters
  '(
    ("nnimap\\+gmail1.*"
     (expiry-target . gm-gmail1-expiry-target-function)
     )
    ("nnimap\\+gmail2.*"
     (expiry-target . gm-gmail2-expiry-target-function)
     )
 ))
;----------------------------------------


I guess my feeling is that it might be better (??!) if
nnmail-fancy-expiry-target(s) could also qualify expiry targets based on
the value of group, rather than just based data found in the header of
the article. But this might be unwieldy for reasons I haven't thought
of...and anyhow the above seems to do the job.

* smtp

I wanted to be able to adjust the smtp-user via gnus-posting-styles --
e.g. so that "sent" mail automatically ends up in the 

[Gmail]/Sent

folder of the correct gmail account.

One solution is to adapt some code found here

   http://emacswiki.org/emacs/MultipleSMTPAccounts

as follows.

;----------------------------------------
(eval-after-load "smtpmail"
  '(progn
     (defun smtpmail-get-and-delete-smtp-user-from-header ()
       "Find header field X-SMTP-User and if found return value as
         string and delete header field. If a header field of this
         name doesn't exist, return nil."
       (save-excursion
	 (goto-char (point-min))
	 (save-match-data
	   (let ((smtp-server))
	     (loop until (or (eobp) (looking-at "^[ \t]*$"))
		   if (looking-at "X-SMTP-User[ \t]*:[ \t]*\\(.*?\\)[ \t]*\n")
		   return (prog1 (match-string 1) (replace-match ""))
		   else
		   do (forward-line 1))))))
     
     (defadvice smtpmail-via-smtp (around set-smtp-user-from-header activate)
       (let ((smtpmail-smtp-user (or (smtpmail-get-and-delete-smtp-user-from-header)
				       smtpmail-smtp-user)))
	 ad-do-it
	 ))))

;----------------------------------------

Now just do something like

(setq gnus-posting-styles
  '(    
    ("gmail1"
      ("X-SMTP-User" "gmail1-user")
    )
    ("gmail2"
      ("X-SMTP-User" "gmail2-user")
    )
   )
)

(or add the relevant lines to existing defn of gnus-posting-styles...)
to insert "X-SMTP-User" headers temporarily in the mail for consumption by
smtpmail-via-smtp when sending the mail.

best,
george

-- 
  ,--<>----
  | George McNinch <gmcninch (at) gmail.com>
  | http://gmcninch.math.tufts.edu
  `--<>----

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

end of thread, other threads:[~2012-04-20 16:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-14 17:36 multiple gmail accounts: smtp and expiry George McNinch
2012-04-17 12:43 ` Sivaram Neelakantan
2012-04-17 13:48   ` Richard Riley
2012-04-18 15:42     ` Sivaram Neelakantan
2012-04-18 15:47       ` Richard Riley
2012-04-20 16:27         ` Sivaram Neelakantan

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