Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
use warnings; use strict; use Data::Dumper; use Mail::MboxParser; use Mail::IMAPClient; my $base_dir = ".thunderbird/profile_path/Mail/Local Folders/"; my $imap_server = "localhost"; my $imap_user = "username"; my $imap_pass = "password"; my $parseropts = { enable_cache => 0, enable_grep => 0, cache_file_name => 'cache-file', }; my $skip_deleted = 1; my $imap = Mail::IMAPClient->new( Server => $imap_server, User => $imap_user, Password => $imap_pass, ) or die "Cannot connect to $imap_server as $imap_user: $@"; parse_dir($base_dir); sub parse_dir { my $dir = shift; opendir my $dir_h, $dir or die "Unable to opendir $dir: $!\n"; print "Reading directory $dir\n"; ##Dirty, probably IMAP-server dependent stuff. #This stuff is for dovecot. my $temp_dir = $dir; $temp_dir =~ s!\.sbd!!g; $temp_dir =~ s!^$base_dir!!; $temp_dir =~ s!^/!!; $temp_dir =~ s!/!.!g; print "Making dir $temp_dir\n"; $imap->create($temp_dir); foreach my $directory (grep /\.sbd$/, readdir $dir_h) { parse_dir($dir."/".$directory); } seekdir($dir_h, 0); foreach my $mail_file (grep !/^\./, grep !/(\.html|\.sbd|\.msf +|\.dat)$/, readdir $dir_h) { my $mf = $dir."/".$mail_file; $mf =~ s!//+!/!g; print "Going to parse $mf\n"; my $mb = Mail::MboxParser->new($mf, decode => 'ALL', parseropts => $parsero +pts); for my $msg ($mb->get_messages) { #Skip deleted messages... my $folder_name = $temp_dir.".".$mail_file; $folder_name =~ s!//+!/!g; unless($skip_deleted and (hex($msg->header->{" +x-mozilla-status"}) & 0x0008)) { print "Appending msg " . $msg->header- +>{subject} . " to $folder_name\n"; $folder_name =~ s/^\.//; $imap->create($folder_name) or warn "unable to create $fol +der_name: $@\n"; unless($imap->append_string($folder_na +me, $msg)) { warn "Couldn't append " . $msg +->header->{subject} . " to $folder_name: $@\n"; warn "Skipping\n"; next; } } else { warn "Skipping " . $msg->header->{subj +ect} . " - deleted message\n"; } } } closedir($dir_h); }

In reply to Mirror/Copy Mozilla thunderbird emails to IMAP server by davis

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (4)
    As of 2018-05-27 00:16 GMT
    Find Nodes?
      Voting Booth?