Tweaking theh context system: modeline and maildir selection

20 views
Skip to first unread message

Eduardo Mercovich

unread,
Feb 17, 2017, 3:05:29 PM2/17/17
to mu-discuss
Dear all.

I migrated to the context system and it works wonderfully.
However, a few details are still elluding me.

* Current context focus in the modeline
I customized my modeline a long time ago and that means that I
don't see the context there. How do I show that info? Or, what is
the variable that must be shown?

+ Select by to: OR maildir:
With some lists (like this one), the to: field is not enough to
define the context, but the Maildir is the right one. I assume
this is a pretty common case, but let's check... So how can the
to: and -if not present- the maildir can be specified as criteria
to select the context?

As always, thank you very much. :)

Best...

--
Eduardo Mercovich

Donde se cruzan tus talentos
con las necesidades del mundo,
ahí está tu vocación.
(Anónimo)

Josiah Schwab

unread,
Feb 17, 2017, 3:26:02 PM2/17/17
to mu-di...@googlegroups.com
Hi Eduardo,

> + Select by to: OR maildir:
> With some lists (like this one), the to: field is not enough to define
> the context, but the Maildir is the right one. I assume this is a
> pretty common case, but let's check... So how can the to: and -if not
> present- the maildir can be specified as criteria to select the
> context?

I always select based on maildir and never on to, because at least for
me that already correctly handles all cases. If that doesn't work for
you, then you can simply combine those two kinds of tests.

So using the example match-funcs shown at

https://www.djcbsoftware.nl/code/mu/mu4e/Contexts-example.html

and combining them with an or, would give something like

:match-func (lambda (msg)
(when msg
(or
(mu4e-message-contact-field-matches msg :to "ader...@miskatonic.example.com")
(string= (mu4e-message-field msg :maildir) "/cycling"))))

Hope that helps,
Josiah

Eduardo Mercovich

unread,
Feb 17, 2017, 3:40:36 PM2/17/17
to mu-di...@googlegroups.com
Hi Josiah.

>> + Select by to: OR maildir: [...]

> I always select based on maildir and never on to, because at
> least for me that already correctly handles all cases.

Ah, I see... it seems quite right.

> If that doesn't work for you, then you can simply combine those
> two kinds of tests [...] combining them with an or, would give
> something like
> :match-func (lambda (msg)
> (when msg
> (or
> (mu4e-message-contact-field-matches msg :to
> "ader...@miskatonic.example.com")
> (string= (mu4e-message-field msg :maildir)
> "/cycling"))))

Thanks a lot. :)

I will try first to use maildir only and see what happens. If I
catch something that it doesn't, I'll test the combination.
In any case, I'll report back.

Thank you very much.
Replies like yours make a pleasure to participate in communities
like this one. :)

Best regards...

Eduardo Mercovich

unread,
Feb 17, 2017, 4:25:58 PM2/17/17
to mu-di...@googlegroups.com
Hi Josiah.

[...]

> I always select based on maildir [...]
> So using the example match-funcs shown at
> https://www.djcbsoftware.nl/code/mu/mu4e/Contexts-example.html
> and combining them with an or, would give something like
> :match-func (lambda (msg)
> (when msg
> (or
> (mu4e-message-contact-field-matches msg :to
> "ader...@miskatonic.example.com")
> (string= (mu4e-message-field msg :maildir)
> "/cycling"))))

I'm surely doing something wrong here...
This is the relevant region I have in the context section:

--8<---------------cut here---------------start------------->8---
(make-mu4e-context
:name "edumerco"
:enter-func (lambda () (mu4e-message "contexto >>>
edumerco"))
:leave-func (lambda () (mu4e-message "saliendo de
edumerco"))
;; we match based on the contact-fields of the message
:match-func (lambda (msg)
(when msg
(string= (mu4e-message-field msg
:maildir) "/edumerco")
))
:vars '( ( user-mail-address .
"edu...@mercovich.net" )
( user-full-name . "Eduardo Mercovich"
)
;; variables follows...
))
--8<---------------cut here---------------end--------------->8---

This is repeated for each context, changing of course the names,
text, maildir and variables.

I checked this against your text and djcb's documentation and it
seems ok, also there is no error when I ask to evaluate this
block. However now it asks for contexts on each reply!

What am I doing wrong? Is there some syntactic glitch? May the
problem be elsewhere?
mu4e-context-policy is set to pick-first.

Thanks a lot...

Josiah Schwab

unread,
Feb 17, 2017, 5:12:42 PM2/17/17
to mu-di...@googlegroups.com
Hi Eduardo,

> This is the relevant region I have in the context section:
>
> --8<---------------cut here---------------start------------->8---
> (make-mu4e-context
> :name "edumerco"
> :enter-func (lambda () (mu4e-message "contexto >>>
> edumerco"))
> :leave-func (lambda () (mu4e-message "saliendo de
> edumerco"))
> ;; we match based on the contact-fields of the message
> :match-func (lambda (msg)
> (when msg (string=
> (mu4e-message-field msg :maildir) "/edumerco")
> ))
> :vars '( ( user-mail-address .
> "edu...@mercovich.net" )
> ( user-full-name . "Eduardo Mercovich"
> )
> ;; variables follows...
> ))
> --8<---------------cut here---------------end--------------->8---
>
> This is repeated for each context, changing of course the names, text,
> maildir and variables.

I'm assuming you elided the setq, backticks, etc.

> I checked this against your text and djcb's documentation and it seems
> ok, also there is no error when I ask to evaluate this block. However
> now it asks for contexts on each reply!
>
> What am I doing wrong? Is there some syntactic glitch? May the problem
> be elsewhere?

I realized I don't know how your mail is organized. My maildirs have
lots of sub-folders, for example your message was in

Maildir: /personal/Lists.mu

so the match-func I use in my config compares against first part of the
maildir instead of trying for an exact match.

:match-func (lambda (msg)
(when msg
(string-match-p "^/personal" (mu4e-message-field msg :maildir))))

The match-func in the manual would require that the maildir be exactly
"/edumerco", which maybe it is not.

Perhaps that sort of thing is the source of your issue.

Hope that helps,
Josiah

Eduardo Mercovich

unread,
Feb 17, 2017, 5:29:23 PM2/17/17
to mu-di...@googlegroups.com
Hi Josiah.

>> [...]
> I'm assuming you elided the setq, backticks, etc.

Yes.

>> [...] What am I doing wrong? Is there some syntactic glitch?
>> May the problem be elsewhere?

> I realized I don't know how your mail is organized. My maildirs
> have
> lots of sub-folders, for example your message was in
> Maildir: /personal/Lists.mu

Yes it is. The structure is:

Maildir
\account1
\inbox
\drafts
\todos
\trash
\account2
\inbox
\drafts
\todos
\trash
\account3
\inbox
\drafts
\todos
\trash
\account...

And so on.

> so the match-func I use in my config compares against first part
> of the
> maildir instead of trying for an exact match.
> :match-func (lambda (msg)
> (when msg
> (string-match-p "^/personal"
> (mu4e-message-field msg :maildir))))
> The match-func in the manual would require that the maildir be
> exactly
> "/edumerco", which maybe it is not.
> Perhaps that sort of thing is the source of your issue.

You nailed it exactly. :)
I changed the expression and now it works flawlessly.

Thank you very much in my name and all those future newbies like
me.
If you ever came to Argentina mail me, you'll have a invite to a
real argentinean asado. :D

Best regards...
Reply all
Reply to author
Forward
0 new messages