| Line 190... | 
            Line 190... | 
          
          
            | 190 | 
                  warn "\t\t$folder not found in target and could not create it\n";
  | 
            190 | 
                  warn "\t\t$folder not found in target and could not create it\n";
  | 
          
          
            | 191 | 
               }
  | 
            191 | 
               }
  | 
          
          
            | 192 | 
               return $numMessages;
  | 
            192 | 
               return $numMessages;
  | 
          
          
            | 193 | 
            }
  | 
            193 | 
            }
  | 
          
          
            | 194 | 
             
  | 
            194 | 
             
  | 
          
          
            | - | 
               | 
            195 | 
            # this is an alternative to maintaining the hierarchy of the original system.
  | 
          
          
            | - | 
               | 
            196 | 
            # instead, it will take 
  | 
          
          
            | - | 
               | 
            197 | 
             
  | 
          
          
            | - | 
               | 
            198 | 
            sub processFolderByDate {
  | 
          
          
            | - | 
               | 
            199 | 
               my ( $sourceAccount, $targetAccount, $folder, $targetFormat, $dateBefore, $sourceDelimiter, $targetDelimiter, $deleteOnSuccess ) = @_;
  | 
          
          
            | - | 
               | 
            200 | 
               my $numMessages = 0;
  | 
          
          
            | - | 
               | 
            201 | 
               $sourceAccount->expunge_mailbox( $folder ); # clean it up so we don't copy deleted messages
  | 
          
          
            | - | 
               | 
            202 | 
               $sourceAccount->select( $folder ) or die "Could not connect to folder $folder\n"; # move into the correct folder for the source
  | 
          
          
            | - | 
               | 
            203 | 
               my @ids = $sourceAccount->search_sent_before( $dateBefore ); # use sent_before to get the sent date from message
  | 
          
          
            | - | 
               | 
            204 | 
            #   print join( "\n\t\t\t", @ids ) . "\n";
  | 
          
          
            | - | 
               | 
            205 | 
               return 0 unless @ids; # we have nothing to copy, so exit
  | 
          
          
            | - | 
               | 
            206 | 
             
  | 
          
          
            | - | 
               | 
            207 | 
               if ( $sourceDelimiter ne $targetDelimiter ) { # different delimiters, so we have to change them in the folder def
  | 
          
          
            | - | 
               | 
            208 | 
                  # they may contain meta chars, so escape them. We can use \Q \E in the pattern to match, but the 
  | 
          
          
            | - | 
               | 
            209 | 
                  # second part of the s/// will substitute literal EXCEPT for the delimiter and the dollar sign
  | 
          
          
            | - | 
               | 
            210 | 
                  # I'm escaping the double quote (what I'm using for the delimiter) "just in case" but I'm not doing
  | 
          
          
            | - | 
               | 
            211 | 
                  # the dollar sign, so this will fail, fail, fail if there is an issue there.
  | 
          
          
            | - | 
               | 
            212 | 
                  my $escapedTargetDelimiter = $targetDelimiter eq '"' ? '\\' .  $targetDelimiter : $targetDelimiter;
  | 
          
          
            | - | 
               | 
            213 | 
                  $folder =~ s"\Q$sourceDelimiter\E"$escapedTargetDelimiter"g;
  | 
          
          
            | - | 
               | 
            214 | 
               }
  | 
          
          
            | - | 
               | 
            215 | 
               if ( $targetAccount->select( $folder ) || &makeFolder( $targetAccount, $folder, $targetDelimiter ) ) {
  | 
          
          
            | - | 
               | 
            216 | 
                  foreach my $id ( @ids ) {
  | 
          
          
            | - | 
               | 
            217 | 
                     my @flags = $sourceAccount->msg_flags( $id );
  | 
          
          
            | - | 
               | 
            218 | 
                     my $message = $sourceAccount->get( $id ) or die $sourceAccount->errstr;
  | 
          
          
            | - | 
               | 
            219 | 
                     if ( $targetAccount->put( $folder, $message, @flags ) ) {
  | 
          
          
            | - | 
               | 
            220 | 
                        $sourceAccount->delete( $id ) if ( $deleteOnSuccess ) ;
  | 
          
          
            | - | 
               | 
            221 | 
                        $numMessages++;
  | 
          
          
            | - | 
               | 
            222 | 
                     } else {
  | 
          
          
            | - | 
               | 
            223 | 
                        die "Could not write to target, aborting\n$targetAccount->errstr\n";
  | 
          
          
            | - | 
               | 
            224 | 
                     }
  | 
          
          
            | - | 
               | 
            225 | 
                  }
  | 
          
          
            | - | 
               | 
            226 | 
               } else {
  | 
          
          
            | - | 
               | 
            227 | 
                  warn "\t\t$folder not found in target and could not create it\n";
  | 
          
          
            | - | 
               | 
            228 | 
               }
  | 
          
          
            | - | 
               | 
            229 | 
             
  | 
          
          
            | - | 
               | 
            230 | 
             
  | 
          
          
            | - | 
               | 
            231 | 
               return $numMessages;
  | 
          
          
            | - | 
               | 
            232 | 
            }
  | 
          
          
            | - | 
               | 
            233 | 
             
  | 
          
          
            | 195 | 
            #
  | 
            234 | 
            #
  | 
          
          
            | 196 | 
            # main processing loop to handle one account
  | 
            235 | 
            # main processing loop to handle one account
  | 
          
          
            | 197 | 
            #
  | 
            236 | 
            #
  | 
          
          
            | 198 | 
            sub processAccount {
  | 
            237 | 
            sub processAccount {
  | 
          
          
            | 199 | 
               my ( $source, $target, $age, $ignore, $deleteOnSuccess, $deleteEmptyFolders ) = @_;
  | 
            238 | 
               my ( $source, $target, $age, $ignore, $deleteOnSuccess, $deleteEmptyFolders, $hierarchy ) = @_;
  | 
          
          
            | - | 
               | 
            239 | 
               $heirarchy = '' unless $hierarchy;
  | 
          
          
            | 200 | 
               
  | 
            240 | 
               
  | 
          
          
            | 201 | 
               my $date = getDate( $age );
  | 
            241 | 
               my $date = getDate( $age );
  | 
          
          
            | 202 | 
               print "\t" . ( $deleteOnSuccess ? 'Moving' : 'Copying' ) . " all messages before $date\n";
  | 
            242 | 
               print "\t" . ( $deleteOnSuccess ? 'Moving' : 'Copying' ) . " all messages before $date\n";
  | 
          
          
            | 203 | 
               
  | 
            243 | 
               
  | 
          
          
            | 204 | 
               # open and log into both source and target, and get the separator used
  | 
            244 | 
               # open and log into both source and target, and get the separator used
  | 
          
          
            | Line 214... | 
            Line 254... | 
          
          
            | 214 | 
               my $folderList = $$source{'folders'};
  | 
            254 | 
               my $folderList = $$source{'folders'};
  | 
          
          
            | 215 | 
               my $count = 0; # count the number of messages processed
  | 
            255 | 
               my $count = 0; # count the number of messages processed
  | 
          
          
            | 216 | 
               my $processedCount = 0; # count the number of folders processed
  | 
            256 | 
               my $processedCount = 0; # count the number of folders processed
  | 
          
          
            | 217 | 
               foreach my $folder ( @$folderList ) {
  | 
            257 | 
               foreach my $folder ( @$folderList ) {
  | 
          
          
            | 218 | 
                  print "\t$folder";
  | 
            258 | 
                  print "\t$folder";
  | 
          
          
            | - | 
               | 
            259 | 
                  my $messages;
  | 
          
          
            | - | 
               | 
            260 | 
                  if ( $heirarchy ) {
  | 
          
          
            | - | 
               | 
            261 | 
                     $messages = &processFolderByDate( $sourceAccount, $targetAccount, $folder, $hierarchy, $date, $$source{'separator'}, $$target{'separator'}, $deleteOnSuccess );
  | 
          
          
            | - | 
               | 
            262 | 
                  } else {
  | 
          
          
            | 219 | 
                  my $messages = &processFolder( $sourceAccount, $targetAccount, $folder, $date, $$source{'separator'}, $$target{'separator'}, $deleteOnSuccess );
  | 
            263 | 
                     $messages = &processFolder( $sourceAccount, $targetAccount, $folder, $date, $$source{'separator'}, $$target{'separator'}, $deleteOnSuccess );
  | 
          
          
            | - | 
               | 
            264 | 
                  }
  | 
          
          
            | 220 | 
                  $sourceAccount->expunge_mailbox( $folder );
  | 
            265 | 
                  $sourceAccount->expunge_mailbox( $folder );
  | 
          
          
            | 221 | 
                  # delete folder if empty and client has requested it.
  | 
            266 | 
                  # delete folder if empty and client has requested it.
  | 
          
          
            | 222 | 
                  &deleteAFolder( $sourceAccount, $folder, $$source{'separator'}, $$source{'systemfolder'} ) if ( $deleteEmptyFolders );
  | 
            267 | 
                  &deleteAFolder( $sourceAccount, $folder, $$source{'separator'}, $$source{'systemfolder'} ) if ( $deleteEmptyFolders );
  | 
          
          
            | 223 | 
                  print "\n\t\t$messages processed\n";
  | 
            268 | 
                  print "\n\t\t$messages processed\n";
  | 
          
          
            | 224 | 
                  $count += $messages;
  | 
            269 | 
                  $count += $messages;
  |