{"id":2168,"date":"2025-01-16T13:13:59","date_gmt":"2025-01-16T18:13:59","guid":{"rendered":"https:\/\/www.unliterate.net\/?p=2168"},"modified":"2025-01-16T13:13:59","modified_gmt":"2025-01-16T18:13:59","slug":"dovecot-out-of-the-box-setup","status":"publish","type":"post","link":"https:\/\/www.unliterate.net\/index.php\/2025\/01\/16\/dovecot-out-of-the-box-setup\/","title":{"rendered":"dovecot &#8211; out of the box setup"},"content":{"rendered":"\n<p>Trying to learn a new programming language is a daunting task. My process is to take programs that I&#8217;ve written before and rewrite them in the target language of choice.<\/p>\n\n\n\n<p>I&#8217;ve got a PHP program that interacts with my IMAP server (<a href=\"https:\/\/github.com\/mjheick\/smart-imap\" target=\"_blank\" rel=\"noreferrer noopener\">smart-imap<\/a>), reads all the messages in the Inbox, takes the localpart of the email address, creates a folder and moves that email into that folder. If the localpart is part of a pre-determined list of email addresses that have been sold off for Spam it&#8217;ll move it to the SPAM folder. If there are no localparts that match the domain name of the server then it drops it into an UNSORTED folder.<\/p>\n\n\n\n<p>Today&#8217;s language of choice is Python, specifically 3.9.21. To do this entire feat without breaking things I need an IMAP server, and dovecot 2.3.16 is going to be the death of me.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Never go in head first&#8230;<\/h2>\n\n\n\n<p>Out of the box it&#8217;s set up for all necessary services, PAM authentication, and <em>should be good to go<\/em>\u00a9.<\/p>\n\n\n\n<p>I create a system user called <em>imaptest<\/em> with a curiously identical password on a Rocky 5.14.0-503 VM. Install dovecot, and launch the service. All goes well. I telnet into <code>localhost:143<\/code>, authenticated, and then immediately got dropped out. <code>\/var\/log\/maillog<\/code> screams the following at me:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Jan 16 11:02:25 rocks dovecot&#91;859]: imap(imaptest)&lt;1368>&lt;pVmW69QrMJzAqAHf>: Error: Namespace '': Mail storage autodetection failed with home=\/home\/imaptest\nJan 16 11:02:25 rocks dovecot&#91;859]: imap(imaptest)&lt;1368>&lt;pVmW69QrMJzAqAHf>: Disconnected: Namespace '': Mail storage autodetection failed with home=\/home\/imaptest in=0 out=416 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0<\/code><\/pre>\n\n\n\n<p>Searching gets me to the first derp: RTFM aka &#8220;Configuration&#8221;. I have to define a <code>mail_location<\/code> in the configuration for dovecot to know where to do its business. editing <code>\/etc\/dovecot\/conf\/10-mail.conf<\/code>, setting <code>mail_location<\/code> to <code>mbox:~\/mail:INBOX=\/var\/mail\/%u<\/code> and restarting dovecot gets me authenticating. I&#8217;m happy. Lets see if other commands will work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lets take a look around?<\/h2>\n\n\n\n<p>After authentication I attempt to <code>select inbox<\/code>, a basic next step in IMAP folder enumerating. This give me a wonky permission error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NO &#91;NOPERM] Permission denied (0.001 + 0.000 secs).<\/code><\/pre>\n\n\n\n<p>and the logs give me a good breadcrumb to follow:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Jan 16 12:48:10 rocks dovecot&#91;1504]: imap(imaptest)&lt;1569>&lt;BmqGZdYrhtwAAAAAAAAAAAAAAAAAAAAB>: Error: fchown(\/home\/imaptest\/mail, group=12(mail)) failed: Operation not permitted (egid=1001(imaptest), group based on \/var\/mail\/imaptest - see http:\/\/wiki2.dovecot.org\/Errors\/ChgrpNoPerm)\n<\/code><\/pre>\n\n\n\n<p>The wiki for <code>ChgrpNoPerm<\/code> tells me dovecot needs to copy files around and maintain groups and perms and it&#8217;s having problems doing all that. To fix this I <em>chose to<\/em> do the following as I felt it was the easiest.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Add <code>dovecot<\/code> to the <code>mail<\/code> group<\/li>\n\n\n\n<li>Add <code>imapuser<\/code> to the <code>mail<\/code> group<\/li>\n\n\n\n<li>Change <code>\/home\/imapuser<\/code> to 0770 and to <code>imaptest:mail<\/code><\/li>\n\n\n\n<li>Restart dovecot<\/li>\n\n\n\n<li>&#8230;<\/li>\n\n\n\n<li>profit<\/li>\n<\/ol>\n\n\n\n<p>I chose the mail group since <code>\/var\/mail\/imaptest<\/code> was set to <code>imaptest:mail<\/code>, and &#8220;in keeping with permissions&#8221; made sense to spread the love around. Following all this my <code>select inbox<\/code> command happily returned data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1 select inbox\n* FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\n* OK &#91;PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft \\*)] Flags permitted.\n* 0 EXISTS\n* 0 RECENT\n* OK &#91;UIDVALIDITY 1737050040] UIDs valid\n* OK &#91;UIDNEXT 1] Predicted next UID\n1 OK &#91;READ-WRITE] Select completed (0.001 + 0.000 + 0.001 secs).<\/code><\/pre>\n\n\n\n<p>Now to see if I can learn this <a href=\"https:\/\/en.wikipedia.org\/wiki\/Python_(programming_language)\" target=\"_blank\" rel=\"noreferrer noopener\">33+ year old language<\/a>&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trying to learn a new programming language is a daunting task. My process is to take programs that I&#8217;ve written before and rewrite them in the target language of choice. I&#8217;ve got a PHP program that interacts with my IMAP server (smart-imap), reads all the messages in the Inbox, takes the localpart of the email [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,20,17],"tags":[],"class_list":["post-2168","post","type-post","status-publish","format-standard","hentry","category-centos","category-geek-instructions","category-linux"],"_links":{"self":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/2168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/comments?post=2168"}],"version-history":[{"count":1,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/2168\/revisions"}],"predecessor-version":[{"id":2169,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/2168\/revisions\/2169"}],"wp:attachment":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/media?parent=2168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/categories?post=2168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/tags?post=2168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}