[Dovecot] auto-detection of user mailbox type - followup
In http://www.dovecot.org/list/dovecot/2006-December/018253.html
Timo Sirainen wrote
You can still change NAMESPACE_* environments. I don't remember how
exactly now, but you can do eg. "set > /tmp/sets" in the script, see
what it has set and modify them in the script.
in response to my query regarding setting the mail_location in namespaces from a mail_executable script. The purpose of this is to be able to select on a per-user basis whether they're using Maildir or mbox format (I don't want to convert 12000 users all at once, and some users have no need or desire to change formats - they still use mail/elm etc) and also have the UW-IMAP compatibility namespaces to take care of all the clients currently configured with imap server directory = mail/.
This all works, with one small bug left. For reference, here's the gist:
In the dovecot.conf file place the usual namespace directives following the Namespaces wiki:
namespace private {
separator = /
prefix =
inbox = yes
}
#for UW backwards compatibility:
namespace private {
separator = /
prefix = mail/
hidden = yes
}
namespace private {
separator = /
prefix = ~/mail/
hidden = yes
}
namespace private {
separator = /
prefix = ~%u/mail/
hidden = yes
}
define the mail_executable under protocol imap:
mail_executable = /usr/local/dovecot/lbin/imap.sh
and write the imap.sh script:
------start imap.sh--------------------------------------------------- #!/bin/sh
# determine if user is in mbox or Maildir mode # Maildir takes precedence and is identified by the existence of # both a .procmailrc recipe and the Maildir directory. # Without a .procmailrc file, there's no recipe to force delivery in # Maildir format, so any existing Maildir is spurious # The .procmailrc should contain DEFAULT=Maildir/
# Set the absolute path to this script as the mail_executable for # the imap protocol in dovecot.conf.
# It appears that this script is run as the user in their home dir
if [ -f .procmailrc -a -d Maildir ]; then MAIL='maildir:~/Maildir'; export MAIL else MAIL='mbox:~/mail:INBOX=~/.mail'; export MAIL fi
# each namespace defined in the conf file needs to have the mail # location defined which is set in environment vars # NAMESPACE_1 etc
NAMESPACE_1=$MAIL; export NAMESPACE_1 NAMESPACE_2=$MAIL; export NAMESPACE_2 NAMESPACE_3=$MAIL; export NAMESPACE_3 NAMESPACE_4=$MAIL; export NAMESPACE_4
#debugging to see what else we can play with #set >> /tmp/d
exec /usr/local/dovecot/libexec/dovecot/imap
------end imap.sh-----------------------------------------------------
However, it appears that the root dir '~/mail' string is used at some point before the tilde-expansion takes place. I see a literal ~ directory in the users home, with an empty mail directory inside. After that it picks up the proper location and works correctly. I tried a %h and got a literal %h directory. So for now I made a simple workaround by using the absolute path to the home directory:
# use home variable (depends on this script running in users home)
# During startup it seems like ~/mail is interpreted as a string and
# a spurious ~ folder is created, before the ~ is expanded
home=/bin/pwd
if [ -f .procmailrc -a -d Maildir ]; then
MAIL="maildir:$home/Maildir"; export MAIL
else
MAIL="mbox:$home/mail:INBOX=$home/.mail"; export MAIL
fi
Thanks,
John Harper
Senior Systems Administrator Information and Instructional Technology Services University of Toronto Scarborough harper@utsc.utoronto.ca
On Fri, 2007-02-09 at 12:57 -0500, John Harper wrote:
However, it appears that the root dir '~/mail' string is used at some point before the tilde-expansion takes place. I see a literal ~ directory in the users home, with an empty mail directory inside.
Hmm. I thought I had fixed all such cases.
After that it picks up the proper location and works correctly. I tried a %h and got a literal %h directory.
Yea, %h is expanded by master process.
home=
/bin/pwd
if [ -f .procmailrc -a -d Maildir ]; then MAIL="maildir:$home/Maildir"; export MAIL
Wouldn't $HOME work directly?
participants (2)
-
John Harper
-
Timo Sirainen