J-Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a script to migrate imap accounts.
On my source server prefix is empty and separaror is /
On destination server prefix is INBOX. and separator is .

Problem is that source accounts inbox is considered as subfolder and is migrated to destination servers INBOX.INBOX subfolder. How do I migrate that folder to destination accounts inbox? here is the code:

for my $folder ($imap->folders) { $imap->select($folder) or warn "Error: $imap->LastError\n"; #$folder =~ s/INBOX$//g; # If I try this, mail::IMAPClient tri +es to create subfolder and exits. $folder =~ s/^$prefix1/$prefix2/g; $folder =~ s/$sep1/$sep2/g; $imap->migrate( $imap2, "ALL", $folder ) or warn "Error: $imap +->LastError\n"; }

So basically what's happening is that folder /INBOX is migrated to INBOX.INBOX and it should be migrated to INBOX.

Update
I tried to modify $folder with this:

$folder =~ s/INBOX$//g

But then mail::IMAPClient tries to create subfolder and exits.

Replies are listed 'Best First'.
Re: mail::IMAPClient migrating mail to Inbox
by kcott (Archbishop) on Jan 19, 2014 at 09:36 UTC

    G'day J-Monk,

    Welcome to the monastery.

    From the rules you've supplied, "/INBOX is migrated to INBOX.INBOX" is absolutely correct.

    There are no supplied rules where "/INBOX" would become "INBOX".

    There is either something wrong or missing in what you've posted. Please fix whatever that is so we can help you. (You might find "How do I change/delete my post?" helpful with this.)

    One hint. Your blanket use of the 'g' modifier in your regex substitutions suggests you don't really understand what this is for. See "perlre: Modifiers".

    -- Ken

Re: mail::IMAPClient migrating mail to Inbox
by karlgoethebier (Abbot) on Jan 19, 2014 at 11:18 UTC

    Perhaps you should try to print out whats going on?

    print qq($prefix1/n$prefix2/n); print qq($sep1/n$sep2/n); for my $folder ($imap->folders) { print qq(Folders: $folder\n); $imap->select($folder) or warn "Error: $imap->LastError\n"; $folder =~ s/^$prefix1/$prefix2/g; print qq(First substition: $folder\n); $folder =~ s/$sep1/$sep2/g; print qq(Second substition: $folder\n); $imap->migrate( $imap2, "ALL", $folder ) or warn "Error: $imap +->LastError\n"; }

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»