{"id":235,"date":"2008-11-10T17:26:12","date_gmt":"2008-11-10T23:26:12","guid":{"rendered":"http:\/\/mcguyverofbeer.com\/?p=235"},"modified":"2008-11-10T17:26:12","modified_gmt":"2008-11-10T23:26:12","slug":"migrating-e-smith-sme-mail-servers-to-qmailvpopmaildovecot","status":"publish","type":"post","link":"https:\/\/www.scottharvanek.com\/?p=235","title":{"rendered":"Migrating e-smith (SME) mail servers to Qmail\/vpopmail\/Dovecot"},"content":{"rendered":"<p>Recently I&#8217;ve had to migrate some mail servers from old aging SMI E-Smith boxes to newer CentOS boxes running a mixture of Qmail + Vpopmail + Dovecot.\u00c2\u00a0 Now this write up is not going to cover the inital qmail\/vpopmail\/dovecot setup so, if that&#8217;s what you&#8217;re looking for&#8230; Sorry you haven&#8217;t found it.<\/p>\n<p>The primary problem is that the older E-Smith boxes store mail in the following manner:<\/p>\n<p>\/home\/e-smith\/files\/user\/USERNAME\/Maildir<\/p>\n<p>*AND*<\/p>\n<p>\/home\/e-smith\/files\/user\/USERNAME\/Mail<\/p>\n<p>All your folders and such are kept in the &#8216;Mail&#8217; folder while all your new mail \/ inbox is kept in the &#8216;Maildir&#8217; folder.\u00c2\u00a0 Why they did this&#8230; I don&#8217;t know.<\/p>\n<p>Anyways, here are the scripts:<\/p>\n<p>maildir_to_dovecot.sh &#8211; This script rsyncs the old data over and then renames it to .Folder.subfolder.etc.<\/p>\n<p><code><br \/>\n#!\/bin\/sh<br \/>\n##########################################################<br \/>\n#<br \/>\n# Acquire inputs<br \/>\n#<br \/>\n########################################################## <\/code><\/p>\n<p>mailbox=$1<br \/>\noldhost=&#8221;$2&#8243;<br \/>\ndomain=&#8221;$3&#8243;<\/p>\n<p>##########################################################<br \/>\n#<br \/>\n# If we don&#8217;t have all arguments bail out(tm)<br \/>\n#<br \/>\n##########################################################<\/p>\n<p>if [ -z &#8220;$1&#8221; ]; then<br \/>\necho &#8220;Usage: $0 user mail.host.tld host.tld&#8221;<br \/>\nexit<br \/>\nfi<\/p>\n<p>##########################################################<br \/>\n#<br \/>\n# Rsync the old data, add bwlimit = 150 for pulling from a T1<br \/>\n# This leaves some headroom for them.<br \/>\n#<br \/>\n##########################################################<\/p>\n<p>rsync -av rsync:\/\/$oldhost\/home\/e-smith\/files\/users\/$mailbox \/home\/vpopmail\/domains\/$domain\/$mailbox<\/p>\n<p>##########################################################<br \/>\n#<br \/>\n# Change to the rsync&#8217;d directory and remove all symlinks<br \/>\n#<br \/>\n##########################################################<\/p>\n<p>cd \/home\/vpopmail\/domains\/$domain\/$mailbox<br \/>\ncd $mailbox<br \/>\nls -aFd \\.* | grep \\\/ | awk -F\\\/ &#8216;{print &#8220;rm -rf \\&#8221;&#8221;$1&#8243;\\&#8221;&#8221;}&#8217; | sh<\/p>\n<p>TMP=\/tmp\/$$.tmp<br \/>\n#<br \/>\n# Look for directories this deep or shallower:<br \/>\nc=20<br \/>\n#<br \/>\n# Recursively start there and go up:<br \/>\nwhile [ $c -gt 0 ]; do<br \/>\n#<br \/>\n# Find all directories at level $c that aren&#8217;t \/cur, \/new, or \/tmp, or \/.something<br \/>\n#<br \/>\nfind  . -nowarn -type d -not -name cur -not -name new -not -name tmp -mindepth $c -not -name &#8216;.*&#8217; &gt; $TMP<br \/>\n#<br \/>\n# Process each line&#8230;<br \/>\n#<br \/>\nwhile read i; do<br \/>\n#<br \/>\n# Convert every starting dot to nothing<br \/>\n# Convert every &#8220;\/&#8221; to a &#8220;.&#8221;<br \/>\nj=`echo $i | sed -e &#8216;s\/ \/\\\\ \/&#8217; | sed -e &#8216;s:^\\.\/::&#8217; | sed -e &#8216;s:\/:.:g&#8217;`<br \/>\n# Move old to new<br \/>\nmv -v &#8220;$i&#8221; &#8220;.$j&#8221;<br \/>\ndone &lt; $TMP<br \/>\n#<br \/>\n# Up one level and repeat until level 0<br \/>\n#<br \/>\nc=`expr $c &#8211; 1`<br \/>\ndone<br \/>\nrm -f $TMP<\/p>\n<p>##########################################################<br \/>\n#<br \/>\n# Change jump out of the rsync&#8217;d directory and move everything<br \/>\n# to the new Maildir<br \/>\n#<br \/>\n##########################################################<\/p>\n<p>cd ..<br \/>\nls -AF $mailbox | grep \\\/ | awk -F\\\/ &#8216;{print &#8220;mv \\&#8221;&#8216;$mailbox&#8217;\/&#8221;$1&#8243;\\&#8221; Maildir\/&#8221;}&#8217; | sh<\/p>\n<p>##########################################################<br \/>\n#<br \/>\n# Create subscriptions in the new maildir for IMAP<br \/>\n#<br \/>\n##########################################################<\/p>\n<p>cd Maildir<br \/>\nls -AFd .* | grep \\\/ | sed -e &#8220;s\/\\(.\\)\\(.*\\)\\\/\/\\2\/g&#8221; &gt; subscriptions<\/p>\n<p>##########################################################<br \/>\n#<br \/>\n# Jump out and set permissions recursively<br \/>\n#<br \/>\n##########################################################<\/p>\n<p>cd ..<br \/>\nchown -R vpopmail:vchkpw *<\/p>\n<p><!--more--><\/p>\n<p>Now, we&#8217;ve moved everything over and rebuilt the directory structure along with the subscriptions file.\u00c2\u00a0 The issue here now is that all folders appear as a subfolder of &#8216;Mail&#8217;<\/p>\n<p>To fix that I quickly wrote up fixmaildir.sh which is the following:<br \/>\n<code><br \/>\nmv .Maildir\/cur\/* cur\/<br \/>\nmv .Maildir\/new\/* new\/<br \/>\nTMP=\/tmp\/$$.tmp<br \/>\nfind  . -nowarn -type d -not -name cur -not -name new -not -name tmp -not -name .Mail -not -name .Maildir -mindepth 1 -name '.Mail*' &gt; $TMP<br \/>\n#<br \/>\n# Process each line...<br \/>\n#<br \/>\nwhile read i; do<br \/>\n#<br \/>\n# Convert every starting dot to nothing<br \/>\n# Convert every \"\/\" to a \".\"<br \/>\nj=`echo $i | sed -e 's\/.Mail\/\/g'`<br \/>\n# Move old to new<br \/>\nmv -v \"$i\" \"$j\"<br \/>\ndone &lt; $TMP<br \/>\nrm -rf .Maildir<br \/>\nrm -rf .Mail<br \/>\nls -AFd .* | grep \\\/ | sed -e \"s\/\\(.\\)\\(.*\\)\\\/\/\\2\/g\" &gt; subscriptions<\/code><\/p>\n<p>This will move the folders out from under Mail and to the top level.\u00c2\u00a0 This should be executed from *inside* the users &#8216;Maildir&#8217; (\/home\/vpopmail\/domains\/DOMAIN.TLD\/USER\/Maildir).<\/p>\n<p>Done!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I&#8217;ve had to migrate some mail servers from old aging SMI E-Smith boxes to newer CentOS boxes running a mixture of Qmail + Vpopmail + Dovecot.\u00c2\u00a0 Now this write up is not going to cover the inital qmail\/vpopmail\/dovecot setup &hellip; <a href=\"https:\/\/www.scottharvanek.com\/?p=235\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-opensource"],"_links":{"self":[{"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=235"}],"version-history":[{"count":2,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":237,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/posts\/235\/revisions\/237"}],"wp:attachment":[{"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}