Still confused about contexts

392 views
Skip to first unread message

Alasdair McAndrew

unread,
Jan 2, 2017, 8:26:37 AM1/2/17
to mu-discuss
I'm still not succeeding in getting multiple accounts to work with
contexts.

I have two accounts (both gmail), which I'll call Work and Home,
with directories:

~/.mail/Work

~/.mail/Home

Current I have set mu4e-maildir to the directory ~/.mail/Home;
that is the Home directory, and it works fine.

I know I can't re-set this variable. I understand I can set the
variable "mu4e-inbox-folder" within each context. So my question
is: how do I set up the "mu4e-maildir" and the two different
values for "mu4e-inbox-folder" in such a way that keeps each
account within its own directory?

And can the "mu4e-get-mail-command" be set differently for each
context? I'm using mbsync, and I'd like to use

mbsync Work

or

mbsync Home

depending on the context.

Thanks very much,
Alasdair

--
Alasdair McAndrew
numbersandshapes.net

Stig Brautaset

unread,
Jan 2, 2017, 9:09:35 AM1/2/17
to mu-di...@googlegroups.com

Hi Alasdair,

Alasdair McAndrew <amc...@gmail.com> writes:

> I'm still not succeeding in getting multiple accounts to work with
> contexts.
>
> I have two accounts (both gmail), which I'll call Work and Home, with
> directories:
>
> ~/.mail/Work
>
> ~/.mail/Home
>
> Current I have set mu4e-maildir to the directory ~/.mail/Home; that is
> the Home directory, and it works fine.
>
> I know I can't re-set this variable. I understand I can set the
> variable "mu4e-inbox-folder" within each context. So my question is:
> how do I set up the "mu4e-maildir" and the two different values for
> "mu4e-inbox-folder" in such a way that keeps each account within its
> own directory?


I suggest setting =mu4e-maildir= to =~/.mail= and set all the different
maildir variables depending on the context. I do this, and it works
fine. (Although I use the default =~/Maildir= location, with
=~/Maildir/Private= and =~/Maildir/Work= under there, so I don't set
=mu4e-maildir= at all.)


#+BEGIN_SRC emacs-lisp
(setq mu4e-contexts
`(,(make-mu4e-context
:name "Private"

:match-func (lambda (msg)
(when msg
(s-starts-with-p "/Private/"
(mu4e-message-field msg :maildir))))

:vars `((user-mail-address . "st...@example.net")

(mu4e-sent-folder . "/Private/sent")
(mu4e-drafts-folder . "/Private/drafts")
(mu4e-trash-folder . "/Private/trash")
(mu4e-refile-folder . "/Private/Archive")
(mu4e-bookmarks . ,(my4e-bookmarks "Private"))))

,(make-mu4e-context
:name "Work"

:match-func (lambda (msg)
(when msg
(s-starts-with-p "/Work/"
(mu4e-message-field msg :maildir))))
:vars `((user-mail-address . "st...@example.com")

(mu4e-sent-folder . "/Work/sent")
(mu4e-drafts-folder . "/Work/drafts")
(mu4e-trash-folder . "/Work/trash")
(mu4e-refile-folder . "/Work/archive")
(mu4e-sent-messages-behavior . delete)

(mu4e-bookmarks . ,(my4e-bookmarks "Work"))))))
#+END_SRC

FWIW my full setup is here:
https://github.com/stig/dot-files/blob/master/emacs.d/Email.org#mumu4e-setup


> And can the "mu4e-get-mail-command" be set differently for each
> context? I'm using mbsync, and I'd like to use

I used to do this and it did work, to an extent. I suspect it won't work
so well with mu4e's automatic / periodic synch. It was also annoying to
have to wait for a full sync after I changed contexts, so now I just let
mbsync sync mail for both accounts in the background. Because my filters
& bookmarks are set up to the way they are I only see mail related to
the context I'm in. Perhaps that would work for you too?


Stig

Alasdair McAndrew

unread,
Jan 2, 2017, 7:01:37 PM1/2/17
to mu-discuss
Thanks, Stig.  Well, I'm still having problems:
  1. No matter which context I choose, I can only see messages from the "Home" context.  For example: "bu" for unread messages shows me Home messages only no matter what context I choose.
  2. I'm only seeing messages from December 30 and before.
  3.  "Update email & database" produces the error: "error in process sentinel: muserver process received signal 11" which would seem to indicate that something is amiss,but I'm not sure what.   I've tried to follow the instructions at https://github.com/djcb/mu/issues/631 but gdb claims that mu isn't running.
I know that all messages are being properly downloaded, as mutt can find them all.    I've clearly made a hash of my contexts, although I've tried to follow the directions in the manual as well as I can.
    I guess as a stop-gap I could go backwards and try the older mu4e-multi approach, although I know that contexts are preferred as being better integrated into mu4e.
      Anyway, thanks!

      cheers,
      Alasdair

      FWIW, here's the relevant bit of my .emacs (with a few changes!):

      (setq mu4e-maildir "~/.mail")
      (setq mu4e-contexts
          `( ,(make-mu4e-context
                :name "Home"
                :enter-func (lambda () (mu4e-message "Entering Home context"))
                :leave-func (lambda () (mu4e-message "Leaving Home context"))
                ;; we match based on the contact-fields of the message
                :match-func (lambda (msg)
                              (when msg 
                                (mu4e-message-contact-field-matches msg 
                                  :to "home...@gmail.com")))
                :vars '( ( mu4e-get-mail-command  . "mbsync home1234")
        ( mu4e-inbox-folder      . "/home1234/Inbox" )
        ( mu4e-drafts-folder     . "/home1234/[Gmail].Drafts")
        ( mu4e-sent-folder       . "/home1234/[Gmail].Sent Mail")
        ( mu4e-trash-folder      . "/home1234/[Gmail].Trash")
        ( user-mail-address      . "home...@gmail.com"  )
                         ( user-full-name         . "Time Waster" )
                         ( mu4e-compose-signature .
                           (concat
                             "Time Waster\n"
                             "Everything > /dev/null\n"))))
             ,(make-mu4e-context
                :name "Miscellaneous"
                :enter-func (lambda () (mu4e-message "Switch to the miscellaneous context"))
                ;; no leave-func
                ;; we match based on the contact-fields of the message
                :match-func (lambda (msg)
                              (when msg 
                                (mu4e-message-contact-field-matches msg 
                                  :to "work...@gmail.com")))
                :vars '( ( mu4e-get-mail-command  . "mbsync work5678")
        ( mu4e-inbox-folder      . "/work5678/Inbox" )
        ( mu4e-drafts-folder     . "/work5678/[Gmail].Drafts")
        ( mu4e-sent-folder       . "/work5678/[Gmail].Sent Mail")
        ( mu4e-trash-folder      . "/work5678/[Gmail].Trash")
        ( user-mail-address      . "work...@gmail.com" )
                         ( user-full-name         . "Desk Jockey" )
        ))))

      Stig Brautaset

      unread,
      Jan 3, 2017, 6:06:47 AM1/3/17
      to mu-di...@googlegroups.com

      Alasdair McAndrew <amc...@gmail.com> writes:

      > Thanks, Stig. Well, I'm still having problems:
      >
      > 1. No matter which context I choose, I can only see messages from the
      > "Home" context. For example: "bu" for unread messages shows me Home
      > messages only no matter what context I choose.
      > 2. I'm only seeing messages from December 30 and before.
      > 3. "Update email & database" produces the error: "error in process
      > sentinel: muserver process received signal 11" which would seem to indicate
      > that something is amiss,but I'm not sure what. I've tried to follow the
      > instructions at https://github.com/djcb/mu/issues/631 but gdb claims that
      > mu isn't running.

      It sounds like the last issue is key. If mbsync doesn't finish cleanly,
      I'm guessing mu won't index the mailboxes ergo you won't see any new
      messages. (Mu is heavily reliant on index, rather than looking at the
      mailbox if I understand correctly.)

      Perhaps mbsync does not run properly from within emacs (either because
      of issue with path, or because it can't get passwords from keychain,
      depending on how you've configured it?) Here's how to test this:

      1. Set =mu4e-get-mail-command= to "true" in both contexts (or remove
      the setting from your context vars and set it outside)
      2. Stop emacs/mu4e
      3. Run =mbsync -a= outside emacs, to ensure it works
      4. Start emacs/mu4e
      5. Hit "U" in the menu
      6. Enter any of the bookmarks

      If things now work, you should have an avenue for testing. One trick
      I've seen some people use is setting =mu4e-get-mail-command= to
      "mbsync -a || true" to let it run, but not get stuck if it fails. I am
      using GNU coreutils' timeout (gtimeout on a Mac) to kill mbsync after
      60 seconds if it misbehaves.


      If bookmarks *don't* work for you now, perhaps something is wrong with
      the context switching instead. In that case, do you see the context
      switching messages you have configured? ("entering ... " "Leaving...")
      If not, what does this command say? It *should* print the current
      context name to the minibuffer.

      : M-: (mu4e-context-name (mu4e-context-current)) RET

      Try that and switch context, then try it again. If the context names
      change, your context switches is probably not the issue.

      You can also verify this by setting different custom jump commands in
      each context and checking whether they are as you expect after
      changing context. (The config I linked to earlier has examples of
      that.) Another way would be to change bookmarks in the contexts and
      perusing the bookmarks with "B".


      > I know that all messages are being properly downloaded, as mutt can find
      > them all. I've clearly made a hash of my contexts, although I've tried
      > to follow the directions in the manual as well as I can.

      Personally I don't think your contexts are the issue, rather that mu
      is not indexing your messages.

      Stig

      Dirk-Jan C. Binnema

      unread,
      Jan 3, 2017, 10:21:21 AM1/3/17
      to mu-di...@googlegroups.com
      Hi Alisdair,

      On Tuesday Jan 03 2017, Alasdair McAndrew wrote:

      > Thanks, Stig. Well, I'm still having problems:
      >
      > 1. No matter which context I choose, I can only see messages from the
      > "Home" context. For example: "bu" for unread messages shows me Home
      > messages only no matter what context I choose.

      Contexts are just a fancy way to switch between sets of configuration
      variables. If you didn't change your bookmarks ('mu4e-bookmarks')
      between contexts, then e.g., 'bu' they will give you the same results.

      > 2. I'm only seeing messages from December 30 and before.
      > 3. "Update email & database" produces the error: "error in process
      > sentinel: muserver process received signal 11" which would seem to indicate
      > that something is amiss,but I'm not sure what. I've tried to follow the
      > instructions at https://github.com/djcb/mu/issues/631 but gdb claims that
      > mu isn't running.

      The instructions should work, but you should execute them before the
      crash happens. You can click around in mu4e, yet:
      gdb -p `pidof mu`
      does not work? Instead of `pidof mu`, you can also try to get the number
      (the PID) from 'ps u'. What happens if you run 'mu index' from the
      command line?

      I've reopened that issue (631), if you have backtraces, please add them
      there - thanks!

      Kind regards,
      Dirk.

      --
      Dirk-Jan C. Binnema Helsinki, Finland
      e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
      pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

      Alasdair McAndrew

      unread,
      Jan 3, 2017, 8:25:34 PM1/3/17
      to mu-discuss
      Thank you very much.  Well, I got more recent messages by reindexing using mu.  And the idea of having new bookmarks within each context makes sense.  However, given my long history of stuffing things up, it'd be nice to see a full configuration where contexts include bookmarks, mail sending, pretty much everything that might change between accounts.  Are there such examples?

      Thanks again,
      Alasdair

      Dirk-Jan C. Binnema

      unread,
      Jan 4, 2017, 11:10:46 AM1/4/17
      to mu-di...@googlegroups.com
      Hi Alasdair,

      On Wednesday Jan 04 2017, Alasdair McAndrew wrote:

      > Thank you very much. Well, I got more recent messages by reindexing using
      > mu. And the idea of having new bookmarks within each context makes sense.
      > However, given my long history of stuffing things up, it'd be nice to see
      > a full configuration where contexts include bookmarks, mail sending, pretty
      > much everything that might change between accounts. Are there such
      > examples?

      We'll still need to fix that issue with indexing from mu4e; it would be
      very useful if you could produce a backtrace, as mentioned/explained in
      one of the earlier message.

      In fact, if you can produce such a backtrace, I'll return the favour and
      add an example of setting bookmarks in a context definition to the
      manual.

      Kind regards,
      Dirk.

      --
      Dirk-Jan C. Binnema Helsinki, Finland
      e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl

      Stig Brautaset

      unread,
      Jan 4, 2017, 1:06:56 PM1/4/17
      to mu-di...@googlegroups.com

      Dirk-Jan C. Binnema <dj...@djcbsoftware.nl> writes:

      [...]

      > In fact, if you can produce such a backtrace, I'll return the favour and
      > add an example of setting bookmarks in a context definition to the
      > manual.

      In case this is helpful to the OP in the meantime, I do exactly this
      using the following function (though it could be more fully explained I
      suppose):
      https://github.com/stig/dot-files/blob/master/emacs.d/Email.org#bookmarks
      called from my context definition:
      https://github.com/stig/dot-files/blob/master/emacs.d/Email.org#switch-between-work-and-private-contexts

      Stig
      Reply all
      Reply to author
      Forward
      0 new messages