How do I read Maildir RFC822 messages from the CentOS 7 terminal?

6,239

If you want to read them using a MUA (mail user agent, client software for reading and writing mail) then you just need to use software that supports the Maildir format. Mutt does, for one. Use the -f command line option to tell it which folder to open:

mutt -f Mail/INBOX

mutt -f Mail/otherfolder

Depending on your configuration, Maildir folders might be stored in a different location than ~/Mail such as ~/Maildir. Check your Dovecot configuration or just have a look at your home directory to see where they are.

Another way, arguably better, is to use the fact that Mutt (and other terminal-based MUAs too) support IMAP so you can just tell it to access the mail through your Dovecot server and leave the details of how the folders are stored and arranged to Dovecot. For Mutt, you specify IMAP folders using a special syntax:

mutt -f {username@imap-server}INBOX

Of course if access via IMAP then you don't need to run mutt on the same system as the Dovecot server.

That's if you want to read your mail interactively. But in your other question you gave me the impression that you want to access the individual emails using scripts and automated processing and such.

For that, you should consult the documentation on the Maildir format but essentially it's very simple: each message lives in a separate file so it's very easy to scan the filesystem for messages and pick them out one by one since each if self-contained in one file. There are some tricky details you need to pay attention to if you want to store new mails in a Maildir folder, in order to conform to the Maildir lockless protocol to avoid things like race conditions, but if you're just reading or changing state flags (seen vs. unseen, etc...) then you don't need to worry about that too much.

Share:
6,239

Related videos on Youtube

RabT
Author by

RabT

Updated on September 18, 2022

Comments

  • RabT
    RabT almost 2 years

    In a CentOS 7 server with dovecot, postfix, mailx installed, I have mail configured to be stored in Maildir format.

    How can I use the terminal to access and view the RFC822 messages stored in a user's Maildir inbox? What specific syntax do I use?

    ANSWER

    For people who find this from the search engines, the fix was to write a JavaMail program with public static void main to access the inbox using the same password that does not work with the answer below's suggested mutt -f {username@imap-server}INBOX. The java program can be called from the CentOS 7 terminal. By contrast, the suggestions given in the answer below do not seem to work with the standard configuration of CentOS 7 or of dovecot on CentOS 7. In order for the answer below to actually address the problem, the respondent would need to identify the config parameters required to get it working on CentOS 7. My understanding is that the respondent's suggestions were tested on a different flavor of Linux.

    • waitfor
      waitfor over 6 years
      Have you just tried mutt -f ~/Maildir?.
    • waitfor
      waitfor over 6 years
      By the way, your "ANSWER" is not a complete solution and I really think that you should remove it.
  • Celada
    Celada over 9 years
    mailx is a pretty bare-bones ancient client. No doubt it only supports historical mbox file format, not Maildir or MH or dbox or anything else. There should be no reason why you can't install another MUA, like Mutt, alongside it though.
  • Celada
    Celada over 9 years
    @CodeMed "Mail/INBOX: No such file or directory" clearly indicated that Mail/INBOX does not exist. The path to your Maildir folder must be something else. Again, check your Dovecot configuration (particularily mail_location) or browse around the home directory to find out what it is. Also, Dovecot creates mailboxes on demand the first time they are accessed, so maybe it doesn't exist yet. Also consider accessing the folder through IMAP as detailed in my answer as an alternative, maybe better, way.
  • Celada
    Celada over 9 years
    Re: "mail_location = maildir:~/Maildir"... So... you looked there for your Maildir folders, right? Did it work? As for the password, I wonder if you have even tested that your Dovecot setup works! Have any successfully used any IMAP client with that account? Did you check logs at all to see if Dovecot is telling you why it did not like the password you supplied?
  • Celada
    Celada over 9 years
    @CodeMed this is my last reply to you because it's getting ridiculous. I ask you if you've checked Dovecot logs and you edit Postfix (not Dovecot) logs into the question. I ask you if you've tried accessing the mailbox using Mutt and the proper Maildir folder location and you bizarrely edit in an irrelevant listing of the user's home directory into the question. On top of it all, you report successfully connecting with IMAP with a different client but you apparently have no idea what password you used to make that connection because you are unable to produce the same password for Mutt.
  • RabT
    RabT over 9 years
    Seach engine visitors: please see the answer I posted at the end of my OP above.