# [solved] local IMAP server, best way for a single user?

## avx

So after ~15 years of using email, I admit I still don't fully understand everything working behind the scenes and I'd like to request some help.

Currently I'm having various accounts related to my domains (normal webspace in this case, ie no v-/root), plus some gmail, plus work. My provider only offers me a simple webui, which I can use to fool around with spamassassin to decide what's ham and what's spam, but that's it - I can create (imap) folders, but I can't create rules to move messages.

Since I want to be somewhat free in choosing the clients I use, I thought about running a local IMAP server and feeding it via fetch-/procmail/fdm/etc.

I had a quick look at the documentation of courier and dovecot, but I found it to be not quite as easy to understand as I'd like it to be.

Basically, I want something like this:

remote server* -> fetch* -> filter* -> maildirs* -> local imap -> client* -> msmpt/something -> remote server*

Everything with a * is clear to me, but I don't know what best to use for the other stuff, so some help is appreciated.

----------

## Etal

I don't have an internal IMAP server anymore (I just use mutt on the maildir :P) but I've previously set up courier-imap, and it was extremely easy.

All you have to do is edit the config file to set the correct path to maildirs, make it listen only to localhost, and reduce the number of processes. I guess the only tricky part was to make sure your maildirs are in a proper hierarchy for IMAP. (If you don't want to change the actual layout, you can just use a separate directory for imap, with symlinks to the right places.)

For sending, I use msmtp. It's nice because you can use it with different email accounts - it looks at the From address, and matches it to the right SMTP server. You can set it as the "sendmail command" in the email client.

----------

## s_bernstein

I'm having a similar setup like you want to build. For the reason was that I was tired of setting up all my email accounts and email filters on various computers  and notebooks. So now I use getmail to fetch all the mail from the different mail servers (wrote a little script that will scan all user home folder for getmail setup files). Then I user maildrop to sort the mails into different imap folders. For the imap server I use dovecot, but I guess you can use any imap server you want.

I also wrote a little init-script which will insert and remove the cron job to fetch mail every x minutes.

----------

## avx

s_bernstein, would you mind showing me your dovecot-config, maybe I'll understand it better when it's just a simple config and not some of the complex stuff on their homepage.

Mutt & maildirs directly would be nice, but I can't be certain to always have a system in front of me, allowing to use ssh to go back to my server, so once I made sure it's running the way I want it, I think putting something like squirrel/roundcube on top would be rather easy for that situations.

----------

## s_bernstein

Sure, but it's really quite straight forward. The config files for gentoo are well documented and almost self explaining. I didn't do any big changes. These things I changed compared to the default setup:

In dovecot.conf (only support imap and ipv4):

protocols = imap 

listen = *

In conf.d/10-auth.conf (disable plaintext auth and set auth mode):

disable_plaintext_auth = yes

auth_mechanisms = plain login

!include auth-system.conf.ext

In conf.d/10-mail.conf (setup mail folder and privileges):

mail_location = maildir:/var/spool/mail/%u 

mail_privileged_group = mail

In conf.d/10-ssl.conf (Enable ssl):

ssl = yes

ssl_cert = </etc/ssl/dovecot/server_cert.pem

ssl_key = </etc/ssl/dovecot/server_key.pem

But in general, dovecot should run just fine in the defautl config.

----------

## avx

So basically I did just the same as you, except for the mail_privileged_group (for now) and I set the location to be maildir:/%h/%u/.maildir.

For testing, I added the account data (localhost, imap, $user, $pwd) in claws-mail, which according to the log connects successfully, but it doesn't show any mail  :Sad: 

----------

## s_bernstein

You can't have any email in you imap folder unless you receive emails. So, if you do not want to setup a full featured mail server (which will be troublesome for various reasons on a dial-in connection) you now need something to collate your mails from your "real" mail server. I use getmail for this. The thing about getmail is, that you can fetch mails by varoius protocols like imap or pop or fetchmail. You could even fetch multiple accounts on one server with one call of getmail, although I never tried that.

----------

## avx

It's not that the .maildir is empty, I used `fdm` (sort of fetch/proc-mail combined) to fetch some mail from my server and it correctly stored them, ie there are now INBOX/{cur,new,tmp} + some other boxes in the maildir, I can look/read through them via ie `less` - so that should not be the problem.

----------

## s_bernstein

If your content is correct, you - or better dovecot - is lacking the right permissions to read,write and execute on these dirs.

----------

## avx

Don't think so, I already tried `chmod -R 777 ~/.maildir` - no change. Even if that would be the case, shouldn't there be anything related to it in the logs?

Edit, closing claws, reopening it at clicking the inbox gives the following in network-log:  *Quote:*   

> [19:49:56] IMAP4< * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN AUTH=LOGIN] Dovecot ready. 
> 
> * IMAP connection is un-authenticated
> 
> [19:49:56] IMAP4> 1 CAPABILITY 
> ...

 The bold part looks a little strange to me.

For the same action, global log (/var/log/everything/current) just states:  *Quote:*   

> May 30 19:49:56 [dovecot] imap-login: Login: user=<avx>, method=PLAIN, rip=10.0.0.10, lip=10.0.0.10, mpid=9766, secured

 

Doing the same action on an imap account from my provider, the log gives the following:  *Quote:*   

> [19:54:20] IMAP4< * OK Dovecot ready. 
> 
> [19:54:20] IMAP4> 1 STARTTLS 
> 
> [19:54:20] IMAP4< 1 OK Begin TLS negotiation now. 
> ...

 

Edit 2: my ~/.maildir contains all messages which are also in the other account I tried (just filtered to different folders).

----------

## s_bernstein

Seems alright for me up until

 *Quote:*   

> [19:49:56] IMAP4< 4 OK Status completed.

 

After that, your email client is not sending the select to change the currently active imap folder to inbox. Maybe you have to set your email client to look for new emails in that folder or to ceck every folder for new mail? I don't know claws.

Edit:

You could also try to use your imap server with telnet and send the select command by hand to verify your dovecot config.

Edit 2:

You log already showed the problem:

 *Quote:*   

> [19:49:56] IMAP4> 4 STATUS INBOX (MESSAGES UIDNEXT UIDVALIDITY UNSEEN)
> 
> [19:49:56] IMAP4< * STATUS "INBOX" (MESSAGES 0 UIDNEXT 1 UIDVALIDITY 1306725813 UNSEEN 0) 

 

The first line is your mail client asking the server  for status information about the inbox and the second line the response from your server. He's telling your email client that there are 0 old messages and 0 new / unseen messages in this folder. So no action is required. Because your email client is not looking for new messages in other folder, it will stop processing at this point.

----------

## avx

Ah damn, it's just been a typo, had Inbox instead of inbox.

Claws now picks up 'inbox' correctly, now to find out, how to also make the other maildirs available (~/.maildir/{inbox,foo,bar,baz}) since claws doesn't pick them up automatically.

----------

## Etal

For courier-imap, at least, you have to put your other folders as dot-folders, inside your inbox folder. So if your inbox is in ~/Maildir/{cur,new,tmp}, you'd have ~/Maildir/.Sent/{cur,new,tmp}, etc.

----------

## avx

Thank you, that's the hint I needed  :Smile: 

----------

