2

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?

rajudev
  • 163
  • 6
  • Finally found the page where the script was present. It was present on this blog explaining the setup of wanderlust for email with Emacs. http://mihai.bazon.net/articles/emacs/wanderlust-email-client – rajudev Feb 08 '19 at 13:11
  • Direct link to the script http://mihai.bazon.net/articles/emacs/wanderlust-email-client/configure-email-folders/gen-folders.pl – rajudev Feb 08 '19 at 13:12

2 Answers2

0

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

#!/usr/bin/perl
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
if(!$imap->login('user','pass')){
    print STDERR "Login failed: " . $imap->errstr . "\n";
    exit(64);
}

# List folders
my @folders   = $imap->mailboxes_subscribed;
foreach my $folder (@folders) {
   print $folder,"\n";
}
AnFi
  • 173
  • 1
  • 11
0

Perl? Seriously?

#!/usr/bin/emacs --script

(require 'imap)

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

(mapc #'(lambda (f) (princ f) (terpri))
      (imap-get-subscribed-folders "imap.example.com" nil "user" "password"))
jch
  • 5,680
  • 22
  • 39