I have been looking at various email setups using different tools within Emacs for the last few months. I looked at various email setups using Gnus, mew, mu4e, wanderlust etc.

While reading one of the setups on some blog, I was trying to setup offlineimap/mbsync. And it requires the name of folders to fetch. On one such blog there was a Perl script to fetch all these folder names automatically. and output them to a file. These folder names can then be used with other configuration scripts to specify which particular folders to fetch.

Now I have finally got a setup which I am staying with and it is working for me. It uses mbsync + mu4e . I have a lot of folders in my mail box as I used to use filters. I was only able to use INBOX and Sent Mails in that configuration, as other folders are a lot. And now I am again looking to find that Perl script.

Does any of you have came across such setup which uses some Perl magic to fetch folders for the configuration?


2 Answers 2


You can use Net::IMAP::Simple perl module/package.
Below please find "version zero" based on the man page.

use strict;
use warnings;
use Net::IMAP::Simple;

# Create the object
my $imap = Net::IMAP::Simple->new('imap.example.com', use_ssl => 1) ||
    die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";

# Log on
    print STDERR "Login failed: " . $imap->errstr . "\n";

# List folders
my @folders   = $imap->mailboxes_subscribed;
foreach my $folder (@folders) {
   print $folder,"\n";
  • Thanks a lot, this works.
    – rajudev
    Commented Feb 7, 2019 at 12:10

Perl? Seriously?

#!/usr/bin/emacs --script

(require 'imap)

(defun imap-get-subscribed-folders (server port user pass)
  (let ((buffer (imap-open server port)))
         (with-current-buffer buffer
           (imap-authenticate user pass)
      (imap-close buffer))))

(mapc #'(lambda (f) (princ f) (terpri))
      (imap-get-subscribed-folders "imap.example.com" nil "user" "password"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.