Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Mark messages as read

by davis (Vicar)
on Jun 11, 2008 at 09:40 UTC ( #691423=note: print w/replies, xml ) Need Help??

in reply to Mark messages as read
in thread Mirror/Copy Mozilla thunderbird emails to IMAP server

Yep, fair enough. I think I may have actually ended up doing something like this in the final version. Thanks for the patch!

Replies are listed 'Best First'.
Re^2: Mark messages as read
by Anonymous Monk on Mar 25, 2014 at 14:25 UTC

    Had some horror to migrate my old Thunderbird archive to IMAP.. found this script. I have made some additions to this code:

    - replace '.' (dots) by '_' in folder names

    - subscribe to the folders !

    - create (final) dir on other location

    - appended a base target folder

    use warnings; use strict; use Data::Dumper; use Mail::MboxParser; use Mail::IMAPClient; my $base_dir = ".thunderbird/profile_path/Mail/Local Folders/"; my $base_target = "INBOX"; 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!^$base_dir!$base_target!; $temp_dir =~ s!\.sbd!!g; $temp_dir =~ s!/+!/!g; $temp_dir =~ s!\.+!_!g; $temp_dir =~ s!^/!!; $temp_dir =~ s!/ *!.!g; if ($temp_dir ne $base_target) { print "================================= Making dir $temp_dir\ +n"; $imap->create($temp_dir) or warn "(A) unable to create $temp_dir: $@\n" +; $imap->subscribe($temp_dir) or warn "(A) subscribe to $temp_dir: $@\n"; print "\n"; } 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|\.d +at)$/, readdir $dir_h) { my $mf = $dir."/".$mail_file; print "Going to parse $mf\n"; my $mb = Mail::MboxParser->new($mf, + decode => 'ALL', + parseropts => $parseropts); my $folder_name = $temp_dir.".".$mail_file; $folder_name =~ s!/+!/!g; $folder_name =~ s!\.+!_!g; $folder_name =~ s!^/!!; $folder_name =~ s!/ *!.!g; print "================================= Making dir $folder_na +me\n"; $imap->create($folder_name) or warn "(B) unable to create $folder_name: $@ +\n"; $imap->subscribe($folder_name) or warn "(B) subscribe to $folder_name: $@\n"; for my $msg ($mb->get_messages) { #Skip deleted messages... unless($skip_deleted and (hex($msg->header->{"x-mozilla-st +atus"}) & 0x0008)) { print "Appending msg " . $msg->header->{subject} . " t +o $folder_name\n"; unless($imap->append_string($folder_name, $msg, '\Seen +')) { warn "Couldn't append " . $msg->header +->{subject} . " to $folder_name: $@\n"; warn "Skipping\n"; next; } } else { warn "Skipping " . $msg->header->{subject} . " - delet +ed message\n"; } } } closedir($dir_h); }

      Ended up adding more checks, edits etc..

      I'll post the most important ones: in stead of for my $msg ($mb->get_messages) use:

      for (0 .. $mb->nmsgs - 1) { my $msg = $mb->get_message($_);
      This because I missed messages with the 'for' loop!

      Large mails ended in errors, I ended up editing the, altering Maxappendstringlength to 1024**20 in stead of 1024**2

      Also had some headaches with Character coding of foldernames.. IMAP doesn't support a lot..

      If you'dd like the whole code I created, let me know..

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://691423]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2017-06-27 07:55 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (600 votes). Check out past polls.