a-locally-running-dovecot-in-guix.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!DOCTYPE html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><meta name="keywords" content="GNU, Emacs, Libre Software, Hurd, Guile, Guix" /><meta name="description" content="GNUcode.me is a website focusing on libre software projects, especially the GNU project." /><link type="application/atom+xml" rel="alternate" title="GNUcode.me -- Feed" href="/feed.xml" /><a rel="me" href="https://fosstodon.org/@thegnuguy"></a><link type="text/css" href="css/footer.min.css" rel="stylesheet"></link><link type="text/css" href="css/header.min.css" rel="stylesheet"></link><link type="text/css" href="css/main.min.css" rel="stylesheet"></link><title>A Locally Running Dovecot in Guix — GNUcode.me</title></head><body><header><nav><ul><li><a href="index.html">GNUcode.me</a></li><li><a href="services.html">Services</a></li><li><a href="about.html">About</a></li><li><a href="business-ideas.html">Business-ideas</a></li></ul></nav></header><h1>A Locally Running Dovecot in Guix</h1><main><section class="basic-section-padding"><article><h3>by Joshua Branson — June 08, 2021</h3><div><p>So, I have been wanting to set up a locally running dovecot server for a LONG
  2. time now. Essentially I have an email account at <a href="dismail.de">dismail.de</a>, and
  3. Emacs' <a href="https://www.gnu.org/software/emacs/manual/html_node/gnus/">Gnus</a> is
  4. pretty slow at searching for my emails. I could switch to using mu4e or
  5. notmuch, which ARE BLAZINGLY fast at searching your emails, BUT after listening
  6. to John Wiegley, who is one of the current
  7. <a href="https://www.gnu.org/software/emacs/">Emacs</a> maintainers, talk about how Emacs'
  8. Gnus mode is so cool...I've been using Gnus ever since. Essentially Gnus is a
  9. newsreader. It is a way to handle lots news that is similar to reddit. In
  10. Gnus, after you've read a message, you do not see it again by default. This is
  11. handy, because since you are getting so much email, it's useful to only see
  12. messages that you have not read.</p><p>Emacs's Gnus is actually the best way I've seen at handling LOTS of email,
  13. particularly mailing lists. For example, I am currently subscribed to
  14. <a href="https://lists.gnu.org/mailman/listinfo/guix-devel">guix-devel</a>,
  15. <a href="https://lists.gnu.org/mailman/listinfo/help-guix">help-guix</a>, and
  16. <a href="https://lists.gnu.org/mailman/listinfo/bug-hurd">bug-hurd</a>. With Gnus, I can
  17. open up these email folders and I only see messages that I have not read, AND
  18. the emails are organized by threads NOT date:</p><p><img src="./images/gnus-thread.png" alt="Image" /></p><p>With my cursor on the top of the thread, pressing C-k, will kill the entire
  19. thread. So when I open up this folder again, I will not see that thread. Let's
  20. suppose that I've read all of the messages in that thread &quot;Re: website: A little
  21. help running the website locally&quot;. So that now Gnus looks like this when I open
  22. it up:</p><p><img src="./images/gnus-thread-all-but-one.png" alt="Image" /></p><p>Pressing Shift-A-Shift-T, will pull up the entire thread, so that I can re-read
  23. the whole conversation:</p><p><img src="./images/gnus-thread-all-but-one-reopened.png" alt="Image" /></p><p>Anyway, the main problem that I have had with Gnus (for years...I should have
  24. fixed this a long time ago), is that it is REALLY slow and pretty much not
  25. responsive at searching for my email. I could try to search for my email with
  26. Gnus, but it would typically fail. I guess that something with dismail's
  27. servers are wonky, because I did not have this problem when I had a paid
  28. <a href="fastmail.com">fastmail</a> account.</p><p>So, one solution to continue using Gnus, but have decent searching is to have a
  29. locally running <a href="https://www.dovecot.org/">dovecot</a> server that will serve my
  30. emails. I'll also be querying that local server instead of the remote one.
  31. Sounds plausible. Here's what you need to do:</p><p>First you need to fetch your remote email and put it in a local
  32. <a href="https://en.wikipedia.org/wiki/Maildir">maildir</a>. I prefer
  33. <a href="https://isync.sourceforge.io/mbsync.html">mbsync</a>, because it is what all the
  34. cool kids are doing.</p><p>Here is my <code>~/.mbsyncrc</code></p><pre><code>IMAPAccount dismail
  35. # Address to connect to
  36. Host imap.dismail.de
  37. User jbranso@dismail.de
  38. Pass VERYSECRETPASSWORD
  39. # To store the password in an encrypted file use PassCmd instead of Pass
  40. # PassCmd &quot;gpg2 -q --for-your-eyes-only --no-tty -d ~/.mailpass.gpg&quot;
  41. #
  42. # Use SSL
  43. SSLType IMAPS
  44. CertificateFile /etc/ssl/certs/ca-certificates.crt
  45. IMAPStore dismail-remote
  46. Account dismail
  47. MaildirStore dismail-local
  48. Subfolders Verbatim
  49. # The trailing &quot;/&quot; is important
  50. Path ~/.mail/dismail.de/
  51. Inbox ~/.mail/dismail.de/Inbox
  52. Channel dismail
  53. Master :dismail-remote:
  54. Slave :dismail-local:
  55. # show all folders
  56. Patterns *
  57. # Automatically create missing mailboxes, both locally and on the server
  58. Create Both
  59. # Save the synchronization state files in the relevant directory
  60. SyncState *</code></pre><p><code>mbsync -a</code> running in a cron job, syncs up my email. The config in guix for
  61. that looks like so:</p><pre><code class="language-scheme">(define mbsync-every-5-minutes
  62. ;; The job's action is a shell command.
  63. #~(job &quot;*/5 * * * *&quot; ;Vixie cron syntax
  64. &quot;mbsync -Va&quot;
  65. #:user &quot;joshua&quot;))
  66. ...
  67. (operating-system
  68. ...
  69. (services
  70. (append
  71. (list
  72. (service mcron-service-type
  73. (mcron-configuration
  74. (jobs (list mbsync-every-5-minutes)))))
  75. %desktop-services)))</code></pre><p>Now all we need is the configuration for a locally running dovecot server, which
  76. looks like so:</p><pre><code class="language-scheme">(dovecot-service #:config
  77. (dovecot-configuration
  78. (mail-location &quot;maildir:~/.mail/dismail.de:LAYOUT=fs&quot;)
  79. (listen '(&quot;127.0.0.1&quot;))
  80. ;; I do not need ssl support in a locally running dovecot. :)
  81. (ssl? &quot;no&quot;)
  82. (protocols
  83. (list (protocol-configuration
  84. (name &quot;imap&quot;)
  85. (mail-max-userip-connections 1))))
  86. (services (list
  87. (service-configuration
  88. (kind &quot;imap&quot;)
  89. (client-limit 1)))))</code></pre><p>The bit that really got me confused for a while was that I needed <strong>LAYOUT=fs</strong>
  90. in the mail-location line. Essentially, isync creates a maildir in a slightly
  91. different format than what dovecot expects. Adding in the &quot;LAYOUT=fs&quot; fixes this.</p><p>The last bit is we have to tell Emacs how to connect to the server:</p><pre><code class="language-scheme">(setq
  92. user-mail-address &quot;myemailaccount@dismail.de&quot;
  93. user-full-name &quot;Joshua Branson&quot;)
  94. (setq gnus-secondary-select-methods
  95. '((nnimap &quot;localDismail&quot;
  96. (nnimap-address &quot;localhost&quot;)
  97. (nnimap-stream network)
  98. (nnimap-server-port 143)
  99. )))</code></pre><p>Pretty cool stuff? Right!?</p></div></article></section></main><footer><p>© 2020 Joshua Branson. The text on this site is free culture under the Creative Commons Attribution Share-Alike 4.0 International license.</p><p>This website is build with Haunt, a static site generator written in Guile Scheme. Source code is <a href="https://notabug.org/jbranso/gnucode.me">available.</a></p><p>The color theme of this website is based off of the famous <a href="#3f3f3f" target="_blank">zenburn</a> theme.</p></footer></body>