-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstclass2imap.pm
1500 lines (1184 loc) · 66.6 KB
/
firstclass2imap.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package firstclass2imap;
use warnings;
use strict;
use DBI;
use Data::Dumper;
use File::Copy;
use File::Basename;
use YAML::Tiny;
use Email::Send;
use Mail::Message;
use Mail::Box::Manager;
use Mail::IMAPClient;
use MIME::Base64;
use MIME::Types;
use List::Compare;
use Date::Parse;
use Date::Manip;
my $from_date_string = '';
my $to_date_string = '';
my $dry_run = 0;
my $destination_sync = 1;
my $destination_folder_deletion = 0;
my $destination_email_deletion = 0;
my $debug_imap = 0;
my $to_imaps = 1;
my $to_authuser = 'admin';
my $to_authuser_password = 'password';
my $rcvdDir = "/home/migrate/Maildir/.ba_rcvd_1/";
my $timeout = 300;
my $searchString = "BA Migrate Script 1: ";
my $max_export_script_size = 20000;
my $migrate_user = "migrate";
my $migrate_password = "migrate";
my $migrate_email_address = 'migrate@[127.0.0.1]';
my $fc_admin_email_address = '[email protected]';
my $fromhost = '192.168.1.24';
my $migratehost = '127.0.0.1';
my $tohost = 'imap.gmail.com';
my $fc_timezone = 'EST';
sub initialize {
my ($instance, $local_from_date_string, $local_to_date_string) = @_;
# Create a YAML file
my $yaml = YAML::Tiny->new;
# Open the config
$yaml = YAML::Tiny->read('migration.cfg');
$from_date_string = $local_from_date_string;
$to_date_string = $local_to_date_string;
$dry_run = $yaml->[0]->{dry_run};
$destination_sync = $yaml->[0]->{destination_sync};
$destination_folder_deletion = $yaml->[0]->{destination_folder_deletion};
$destination_email_deletion = $yaml->[0]->{destination_email_deletion};
$debug_imap = $yaml->[0]->{debug_imap};
$to_imaps = $yaml->[0]->{to_imaps};
$to_authuser = $yaml->[0]->{to_authuser};
$to_authuser_password = $yaml->[0]->{to_authuser_password};
$rcvdDir = $yaml->[0]->{mailDir} . ".ba_rcvd_$instance/";
$timeout = $yaml->[0]->{timeout};
$searchString = $yaml->[0]->{searchString} . " $instance: ";
$max_export_script_size = $yaml->[0]->{max_export_script_size};
$migrate_user = $yaml->[0]->{migrate_user} . $instance;
$migrate_password = $yaml->[0]->{migrate_password} . $instance;
$fc_admin_email_address = $yaml->[0]->{fc_admin_email_address};
$fromhost = $yaml->[0]->{fromhost};
$tohost = $yaml->[0]->{tohost};
$fc_timezone = $yaml->[0]->{fc_timezone};
}
sub migrate_folder_structure {
my ( $fromuser, $fromfolder, $touser, $topassword, $recursive ) = @_;
print print_timestamp() . " : Start Migrating Folder Structure for Account: $fromuser with Destination Folder Deletion: " . ( $destination_folder_deletion ? "Enabled\n" : "Disabled\n" );
my ( $fc_total_folders, $imap_created_folders, $imap_deleted_folders, $imap_total_folders ) = ( 0, 0, 0, 0 );
my $starttime = time();
my $lasttime = $starttime;
my $elapsed_time = "";
my $imap = create_imap_client( $tohost, $touser, $topassword );
if ( $imap->LastError ) {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Connection to the destination imap server failed with the following error.\n";
print print_timestamp() . " : " . $imap->LastError . "\n";
print print_timestamp() . " : Failed to Migrate Folder Structure for Account: $fromuser\n";
return 0;
}
$imap->logout;
my @from_folders_list;
my ( $successful, $fc_folder_exists ) = fc_folder_exists( $fromuser, $fromfolder );
if ( !$successful ) {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Failed to Determine Whether Folder: $fromfolder exists in Account: $fromuser\n";
print print_timestamp() . " : Failed to Migrate Folder Structure for Account: $fromuser\n";
return 0;
}
if ( !$fc_folder_exists ) {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Folder: $fromfolder does NOT exist in Account: $fromuser\n";
print print_timestamp() . " : Failed to Migrate Folder Structure for Account: $fromuser\n";
return 0;
}
push( @from_folders_list, $fromfolder );
if ($recursive) {
my ( $failed, @temp_from_folders ) = get_fixed_fc_subfolders( $fromuser, $fromfolder );
if ($failed) {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Failed to get subfolders for Account: $fromuser\n";
print print_timestamp() . " : Failed to Migrate Folder Structure for Account: $fromuser\n";
return 0;
}
push( @from_folders_list, @temp_from_folders );
}
# this code is capable of removing folders from the list of folders to be migrated
# we don't really need this now but the code will be kept in case of future need
# @from_folders_list = grep(!/^mailbox$/i, @from_folders_list);
my (@from_folders_list_converted);
foreach my $from_folder (@from_folders_list) {
push( @from_folders_list_converted, convert_folder_names_fc_to_imap($from_folder) );
}
my (@to_folders_list) = get_imap_folders_list( $tohost, $touser, $topassword );
if ( !@to_folders_list ) {
print print_timestamp() . " : Failed to get list of destination folders for Account: $touser\n";
print print_timestamp() . " : Failed to Migrate Folder Structure for Account: $fromuser\n";
return 0;
}
my ($lc) = List::Compare->new( '-i', \@from_folders_list_converted, \@to_folders_list );
$imap = create_imap_client( $tohost, $touser, $topassword );
foreach my $imap_folder ( sort( { lc($a) cmp lc($b) } $lc->get_Lonly ) ) {
print print_timestamp() . " : Creating Folder: $imap_folder\n";
if ($dry_run) { next; }
if ( $imap->create($imap_folder) ) {
$imap_created_folders++;
print print_timestamp() . " : Created Folder: $imap_folder\n";
}
else {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Failed to Create Folder: $imap_folder\n";
print print_timestamp() . " : Failed to Migrate Folder Structure for Account: $fromuser\n";
return 0;
}
}
if ($destination_folder_deletion) {
foreach my $imap_folder ( sort( { lc($b) cmp lc($a) } $lc->get_Ronly ) ) {
print print_timestamp() . " : Deleting Folder: $imap_folder\n";
if ($dry_run) { next; }
if ( $imap->delete($imap_folder) ) {
$imap_deleted_folders++;
print print_timestamp() . " : Deleted Folder: $imap_folder\n";
}
else {
print print_timestamp() . " : Failed to Delete Folder: $imap_folder\n";
}
}
}
$imap->logout;
$fc_total_folders = @from_folders_list;
@to_folders_list = get_imap_folders_list( $tohost, $touser, $topassword );
$imap_total_folders = @to_folders_list;
$lc = List::Compare->new( '-i', \@from_folders_list_converted, \@to_folders_list );
my @missed_folders = $lc->get_Lonly;
my $missed_folders_count = @missed_folders;
print print_timestamp() . " : Sync Report for $fromuser\'s Folder Structure: \n";
print "\t\t\t FC \t IMAP\n";
print "Created Folders: \t\t " . $imap_created_folders . "\n";
print "Deleted Folders: \t\t " . $imap_deleted_folders . "\n";
print "Total Folders: \t\t " . $fc_total_folders . "\t " . $imap_total_folders . "\n";
if ($missed_folders_count) {
print $missed_folders_count . " FirstClass folder(s) did NOT successfully migrate to destination\n";
}
else {
print "All of FirstClass's folder structure has successfully been migrated to destination\n";
}
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Finished Migrating Folder Structure for Account: $fromuser in $elapsed_time\n";
return ( 1, $fc_total_folders, $imap_total_folders, \@missed_folders );
}
sub migrate_folders {
my ( $fromuser, $fromfolder, $touser, $topassword, $recursive, $force_update_all_email ) = @_;
print print_timestamp() . " : Start Migrating Folders for Account: $fromuser\n";
my $starttime = time();
my $lasttime = $starttime;
my $elapsed_time = "";
my ( $account_missed_fcuids_count, $dir_account_skip, $dir_account_append, $dir_account_delete, $dir_account_update, $dir_account_total_fcuids ) = ( 0, 0, 0, 0, 0, 0 );
my ( $imap_account_skip, $imap_account_append, $imap_account_delete, $imap_account_update, $imap_account_total_fcuids ) = ( 0, 0, 0, 0, 0 );
my ( $account_total_size, $account_total_size_to_be_migrated ) = ( 0, 0 );
my %missed_fcuids;
my $imap = create_imap_client( $tohost, $touser, $topassword );
if ( $imap->LastError ) {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Connection to the destination imap server failed with the following error.\n";
print print_timestamp() . " : " . $imap->LastError . "\n";
print print_timestamp() . " : Failed to Migrate Folders for Account: $fromuser\n";
return ( 0, $dir_account_total_fcuids, $imap_account_total_fcuids );
}
$imap->logout;
my @from_folders_list;
my ( $successful, $fc_folder_exists ) = fc_folder_exists( $fromuser, $fromfolder );
if ( !$successful ) {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Failed to Determine Whether Folder: $fromfolder exists in Account: $fromuser\n";
print print_timestamp() . " : Failed to Migrate Folders for Account: $fromuser\n";
return ( 0, $dir_account_total_fcuids, $imap_account_total_fcuids );
}
if ( !$fc_folder_exists ) {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Folder: $fromfolder does NOT exist in Account: $fromuser\n";
print print_timestamp() . " : Failed to Migrate Folders for Account: $fromuser\n";
return ( 0, $dir_account_total_fcuids, $imap_account_total_fcuids );
}
push( @from_folders_list, $fromfolder );
if ($recursive) {
my ( $failed, @temp_from_folders ) = get_fixed_fc_subfolders( $fromuser, $fromfolder );
if ($failed) {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Failed to get subfolders for Account: $fromuser\n";
print print_timestamp() . " : Failed to Migrate Folders for Account: $fromuser\n";
return ( 0, $dir_account_total_fcuids, $imap_account_total_fcuids );
}
push( @from_folders_list, @temp_from_folders );
}
# this code is capable of removing folders from the list of folders to be migrated
# we don't really need this now but the code will be kept in case of future need
# @from_folders_list = grep(!/^mailbox$/i, @from_folders_list);
( $elapsed_time, $lasttime ) = elapsed_time($lasttime);
print print_timestamp() . " : Elapsed Time: $elapsed_time\n";
foreach my $fc_folder (@from_folders_list) {
my $imap_folder = convert_folder_names_fc_to_imap($fc_folder);
print print_timestamp() . " : Start Migrating Folder: $imap_folder with Destination Email Deletion: " . ( $destination_email_deletion ? "Enabled\n" : "Disabled\n" );
my ( $folder_missed_fcuids_count, $dir_folder_skip, $dir_folder_append, $dir_folder_delete, $dir_folder_update, $dir_folder_total_fcuids ) = ( 0, 0, 0, 0, 0, 0 );
my ( $imap_folder_skip, $imap_folder_append, $imap_folder_delete, $imap_folder_update, $imap_folder_total_fcuids ) = ( 0, 0, 0, 0, 0 );
# create a list @imap_fcuid_list of FC-UNIQUE-ID's and Message-ID's for
# each message in user's destination IMAP folder
my $imap_fcuid_msgid = {};
if ( $destination_sync ) {
$imap_fcuid_msgid = get_imap_fcuid_msgid_hash( $tohost, $touser, $topassword, $imap_folder );
}
my ( $successful, $export_filter_date_ranges, $days_skipped, $folder_total_size, $folder_total_size_to_be_migrated, $sync_fcuids ) =
get_export_filter_date_ranges( $max_export_script_size, $fromuser, $fc_folder, $tohost, $touser, $topassword, $imap_folder, $imap_fcuid_msgid, $force_update_all_email );
if ( !$successful ) {
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Failed to Migrate Folders for Account: $fromuser\n";
return ( 0, $dir_account_total_fcuids, $imap_account_total_fcuids );
}
$account_total_size += $folder_total_size;
$account_total_size_to_be_migrated += $folder_total_size_to_be_migrated;
my @dir_fcuids = ();
foreach my $fcuid ( keys(%$sync_fcuids) ) {
$dir_folder_skip++ if ( $sync_fcuids->{$fcuid}->{'action'} eq "skip" );
$dir_folder_append++ if ( $sync_fcuids->{$fcuid}->{'action'} eq "append" );
$dir_folder_delete++ if ( $sync_fcuids->{$fcuid}->{'action'} eq "delete" );
$dir_folder_update++ if ( $sync_fcuids->{$fcuid}->{'action'} eq "update" );
push( @dir_fcuids, $fcuid );
}
$dir_folder_total_fcuids = $dir_folder_skip + $dir_folder_append + $dir_folder_update;
if ( $dir_folder_append || $dir_folder_delete || $dir_folder_update ) {
# Make sure all email in the migrate account's inbox is deleted
print print_timestamp() . " : Deleting all email from the temporary $migrate_user account.\n";
my $mgr = Mail::Box::Manager->new;
my $pop_mailbox = $mgr->open( type => 'pop3', username => $migrate_user, password => $migrate_password, server_name => $fromhost );
foreach my $msgid ( $pop_mailbox->messageIds ) {
my $msg = $pop_mailbox->find($msgid);
$msg->delete;
print ".";
}
my ($pop_mailbox_size) = $pop_mailbox->size || 0;
$pop_mailbox->close( write => 'NEVER' );
print "\n" . print_timestamp() . " : Finished Deleting all email from the temporary $migrate_user account.\n";
if ( $pop_mailbox_size == 0 ) {
my $attachments = {};
foreach my $daterange (@$export_filter_date_ranges) {
my ( $startdate, $enddate, $size ) = @$daterange;
print print_timestamp() . " : Start populating the migrate's inbox with email from Folder: \"$imap_folder\" for Date Range: \"$startdate\" to \"$enddate\" with Size: $size KB.\n";
my ( $matching_file_arrived, $matching_filename ) = request_ba_import_script( $fromuser, $fc_folder, $startdate, $enddate );
if ( !$matching_file_arrived ) {
print print_timestamp() . " : Did NOT receive the emailed results of the request_ba_import_script.\n";
next;
}
else {
my ( $content_type, $processed_ba_import_script );
( $content_type, $processed_ba_import_script, $attachments ) = process_ba_import_script($matching_filename);
my ($ba_script_subject) = $searchString . "Processed Import Script for User: $fromuser for Folder: $fc_folder for Date Range: $startdate - $enddate";
email_to_batch_admin( $ba_script_subject, $processed_ba_import_script, $content_type );
my ( $matching_file_arrived, $matching_filename ) = wait_for_matching_file_arrival( $rcvdDir, $searchString, $timeout );
if ( !$matching_file_arrived ) {
print print_timestamp() . " : Did NOT receive the completion notice for populating the migrate's inbox with email from Folder: \"$imap_folder\" for Date Range: \"$startdate\" to \"$enddate\" with Size: $size KB.\n";
next;
}
else {
print print_timestamp() . " : Finished populating the migrate's inbox with email from Folder: \"$imap_folder\" for Date Range: \"$startdate\" to \"$enddate\" with Size: $size KB.\n";
}
}
}
print print_timestamp() . " : Start syncing email.\n";
( $imap_folder_skip, $imap_folder_append, $imap_folder_delete, $imap_folder_update ) = dir_imap_sync( $fromuser, $tohost, $touser, $topassword, $imap_folder, $sync_fcuids, $imap_fcuid_msgid, $attachments );
print print_timestamp() . " : Finished syncing email.\n";
}
}
if ( $destination_sync ) {
my $imap = create_imap_client( $tohost, $touser, $topassword );
$imap->select($imap_folder);
my @uids = ();
my @fetch_response = $imap->fetch( '1:*', 'flags' );
foreach my $line (@fetch_response) {
if ( $line =~ /UID\s+(\d+)/i ) {
push( @uids, $1 );
}
}
my @imap_fcuids = ();
foreach my $uid ( @uids ) {
if ( $imap->get_header($uid, "FC-UNIQUE-ID") ) {
push( @imap_fcuids, $imap->get_header($uid, "FC-UNIQUE-ID") );
$imap_folder_total_fcuids++;
}
}
$imap->logout;
my ($lc) = List::Compare->new( \@dir_fcuids, \@imap_fcuids );
$folder_missed_fcuids_count = $lc->get_Lonly;
my @folder_missed_fcuids = ();
foreach my $fcuid ( $lc->get_Lonly ) {
if ( $sync_fcuids->{$fcuid}->{'datetime'} ne "" ) {
# chat transcripts in First Class are handled strangely by batch admin commands which causes the migration process to
# expect them to be migrated but the actual migration is impossible
# batch admin dir command lists a chat transcript as a leaf item but in the dir command's summary it seems that it might be seeing it as a folder
# batch admin export command does not include chat transcripts at all for some reason which is why it is impossible for them to be migrated
# the following line of code allows the migration report to ignore the chat transcripts so we can report 100% successful migration
# this is done here because the only way to test for a chat transcript is to see if it's subject line matches "Private Chat transcript"
# since other legitimate items might have that subject line I decided to attempt the migration first and then ignore any unsuccessfully migrated items with "Private Chat transcript" as the subject line
if ( $sync_fcuids->{$fcuid}->{'subject'} eq "Private Chat transcript" ) { next; }
push( @folder_missed_fcuids, $sync_fcuids->{$fcuid} );
}
}
if (@folder_missed_fcuids) { $missed_fcuids{$fc_folder} = \@folder_missed_fcuids; }
}
else {
$imap_folder_total_fcuids = $imap_folder_append;
}
$account_missed_fcuids_count += $folder_missed_fcuids_count;
$dir_account_skip += $dir_folder_skip;
$dir_account_append += $dir_folder_append;
$dir_account_delete += $dir_folder_delete;
$dir_account_update += $dir_folder_update;
$dir_account_total_fcuids += $dir_folder_total_fcuids;
$imap_account_skip += $imap_folder_skip;
$imap_account_append += $imap_folder_append;
$imap_account_delete += $imap_folder_delete;
$imap_account_update += $imap_folder_update;
$imap_account_total_fcuids += $imap_folder_total_fcuids;
print print_timestamp() . " : Sync Report for $fromuser\'s \"$imap_folder\" folder: \n";
print "Total size of Folder: \"$imap_folder\" content is: $folder_total_size KB.\n";
print "Total size of Folder: \"$imap_folder\" content to be migrated is: $folder_total_size_to_be_migrated KB.\n";
print "\t\t\tFC-DIR \t IMAP\n";
print "Skip: \t\t\t $dir_folder_skip\n";
print "Append: \t\t $dir_folder_append \t $imap_folder_append\n";
print "Delete: \t\t $dir_folder_delete \t $imap_folder_delete\n";
print "Update: \t\t $dir_folder_update \t $imap_folder_update\n";
print "Total FC-UID's: \t $dir_folder_total_fcuids \t $imap_folder_total_fcuids\n";
if ($folder_missed_fcuids_count) {
print $folder_missed_fcuids_count . " FC-UNIQUE-ID('s) in FC's folder did NOT successfully migrate to the destination folder.\n";
}
foreach my $daterange (@$days_skipped) {
my ( $skippeddate, $size ) = @$daterange;
print "Skipped email in Folder: \"$imap_folder\" from: $skippeddate because the size $size KB is too large.\n";
}
print "End of Report for $fromuser\'s \"$imap_folder\" folder.\n";
( $elapsed_time, $lasttime ) = elapsed_time($lasttime);
print print_timestamp() . " : Finished Migrating Folder: $imap_folder in $elapsed_time\n";
}
print print_timestamp() . " : Sync Report for all of $fromuser\'s folders: \n";
print "Total size of $fromuser\'s account is: $account_total_size KB.\n";
print "Total size of $fromuser\'s account content to be migrated is: $account_total_size_to_be_migrated KB.\n";
print "\t\t\tFC-DIR \t IMAP\n";
print "Skip: \t\t\t $dir_account_skip \n";
print "Append: \t\t $dir_account_append \t $imap_account_append\n";
print "Delete: \t\t $dir_account_delete \t $imap_account_delete\n";
print "Update: \t\t $dir_account_update \t $imap_account_update\n";
print "Total FC-UID's: \t $dir_account_total_fcuids \t $imap_account_total_fcuids\n";
if ($account_missed_fcuids_count) {
print $account_missed_fcuids_count . " FC-UNIQUE-ID('s) in FC's account did NOT successfully migrate to the destination account.\n";
}
print "End of Report for all of $fromuser\'s folders.\n";
( $elapsed_time, $lasttime ) = elapsed_time($starttime);
print print_timestamp() . " : Finished Migrating Folders for Account: $fromuser in $elapsed_time\n";
return ( 1, $dir_account_total_fcuids, $imap_account_total_fcuids, \%missed_fcuids );
}
sub dir_imap_sync {
my ( $fromuser, $tohost, $touser, $topassword, $imap_folder, $sync_fcuids, $imap_fcuid_msgid, $attachments ) = @_;
my ( $imap_folder_skip, $imap_folder_append, $imap_folder_delete, $imap_folder_update ) = ( 0, 0, 0, 0 );
my $imap = create_imap_client( $tohost, $touser, $topassword );
$imap->select($imap_folder);
my $mgr = Mail::Box::Manager->new;
my $pop_mailbox = $mgr->open( type => 'pop3', username => $migrate_user, password => $migrate_password, server_name => $fromhost );
my (%pop_fcuids_msgids_hash);
foreach my $msgid ( $pop_mailbox->messageIds ) {
my $msg = $pop_mailbox->find($msgid);
if ( $msg->get('FC-UNIQUE-ID') ) {
$pop_fcuids_msgids_hash{ $msg->get('FC-UNIQUE-ID') }{'msgid'} = $msgid;
$pop_fcuids_msgids_hash{ $msg->get('FC-UNIQUE-ID') }{'date'} = $msg->get('Date');
}
}
# it is important that email is sorted in ascending datetime order because some email systems expect email to be added in chronological order for email to be
# grouped into conversations or threads
foreach my $fcuid ( sort { str2time( $sync_fcuids->{$a}->{'datetime'} ) <=> str2time( $sync_fcuids->{$b}->{'datetime'} ) } ( keys(%$sync_fcuids) ) ) {
my $fcuid_msgid = '<fc.' . $fcuid . '[email protected]>';
$fcuid_msgid =~ s/[:\-\|]//g;
if ( $sync_fcuids->{$fcuid}->{'action'} eq "delete" ) {
print print_timestamp() . " : IMAP Deleting from Folder: \"$imap_folder\" \t Email: " . $fcuid . "\t" . $sync_fcuids->{$fcuid}->{'datetime'} . "\n";
if ($dry_run) { next; }
my @msgs = $imap->search("HEADER FC-UNIQUE-ID $fcuid");
if ( @msgs ) {
print print_timestamp() . " : IMAP Found email with FC-UNIQUE-ID: $fcuid\n";
my $delete_count = $imap->delete_message(@msgs);
$imap->expunge();
$imap_folder_delete += $delete_count;
print print_timestamp() . " : IMAP Deleted from Folder: \"$imap_folder\" \t $delete_count email with FC-UNIQUE-ID: $fcuid\n";
}
}
if ( $sync_fcuids->{$fcuid}->{'action'} eq "append" ) {
print print_timestamp() . " : IMAP Appending to Folder: \"$imap_folder\" \t Email: " . $fcuid . "\t" . $sync_fcuids->{$fcuid}->{'datetime'} . "\n";
if ($dry_run) { next; }
if ( defined( $pop_fcuids_msgids_hash{$fcuid} ) && $pop_mailbox->find( $pop_fcuids_msgids_hash{$fcuid}{"msgid"} ) ) {
my $pop_msg = $pop_mailbox->find( $pop_fcuids_msgids_hash{$fcuid}{"msgid"} );
my $pop_head = $pop_msg->head();
my $pop_field_msgid = $pop_head->get('Message-ID');
$pop_field_msgid->unfoldedBody( $fcuid_msgid );
my $pop_msg_string = $pop_msg->string;
# First Class's POP3 implementation truncates the name of any email attachment if the attachment's name length exceeds 31 characters
# the following 'if' block makes sure that all email attachments are properly named
foreach my $attachment_number ( keys %{ $attachments->{$fcuid} } ) {
my $attachment_name = qq|$attachments->{ $fcuid }{ $attachment_number }|;
# At some point when First Class generates the import script and emails the script
# to the migration server some of the attachments lose their appropriate mime types
# the following code makes sure the best available mime type is chosen
my ( $mediatype, $encoding ) = MIME::Types::by_suffix($attachment_name);
if ( $mediatype eq "" ) {
if ( ( $pop_msg_string =~ /Content-Type:\s*(\S*)\s*name="$attachment_number"/ ) && ( $1 ne "" ) ) {
$mediatype = $1;
}
else {
$mediatype = "application/octet-stream";
}
}
# the MIME::Type module returns "x-msword" for ".doc" attachments but destination won't recognize that and
# put the appropriate icon next to the attachment so we substitute "msword" for "x-msword"
$mediatype =~ s/\/x-msword$/\/msword/g;
if ( $pop_msg_string =~ s/Content-Type:\s*(\S*)\s*name="$attachment_number"(.*)/Content-Type: $mediatype; "$attachment_name"$2/g ) {
$pop_msg_string =~ s/(Content-Disposition:.*filename=")$attachment_number"/$1$attachment_name"/g;
}
}
my $datetime = new Date::Manip::Date;
$datetime->parse( $sync_fcuids->{$fcuid}->{'datetime'} );
$datetime->convert('GMT');
if ( $imap->append_string( "$imap_folder", $pop_msg_string, '\Seen', $datetime->printf('%d-%b-%Y %T %z') ) ) {
$imap_folder_append++;
print print_timestamp() . " : IMAP Appended to Folder: \"$imap_folder\" \t Email: " . $fcuid . "\t" . $sync_fcuids->{$fcuid}->{'datetime'} . "\n";
}
else {
print print_timestamp() . " : IMAP Failed to Append to Folder: \"$imap_folder\" \t Email: " . $fcuid . "\t" . $sync_fcuids->{$fcuid}->{'datetime'} . "\n";
}
}
}
if ( $sync_fcuids->{$fcuid}->{'action'} eq "update" ) {
my $imap_fcuid_datetime = defined( $imap_fcuid_msgid->{$fcuid}->{'datetime'} ) ? $imap_fcuid_msgid->{$fcuid}->{'datetime'} : '';
print print_timestamp() . " : IMAP Updating in Folder: \"$imap_folder\" \t Email: " . $fcuid . "\t" . $sync_fcuids->{$fcuid}->{'datetime'} . "\t" . $imap_fcuid_datetime . "\n";
if ($dry_run) { next; }
if ( defined( $pop_fcuids_msgids_hash{$fcuid} ) && $pop_mailbox->find( $pop_fcuids_msgids_hash{$fcuid}{"msgid"} ) ) {
my @msgs = $imap->search("HEADER FC-UNIQUE-ID $fcuid");
if ( @msgs ) {
print print_timestamp() . " : IMAP Found email with FC-UNIQUE-ID: $fcuid\n";
my $delete_count = $imap->delete_message(@msgs);
$imap->expunge();
print print_timestamp() . " : IMAP Deleted from Folder: \"$imap_folder\" \t $delete_count email with FC-UNIQUE-ID: $fcuid\n";
}
my $pop_msg = $pop_mailbox->find( $pop_fcuids_msgids_hash{$fcuid}{"msgid"} );
my $pop_head = $pop_msg->head();
my $pop_field_msgid = $pop_head->get('Message-ID');
$pop_field_msgid->unfoldedBody( $fcuid_msgid );
my $pop_msg_string = $pop_msg->string;
# First Class's POP3 implementation truncates the name of any email attachment if the attachment's name length exceeds 31 characters
# the following 'if' block makes sure that all email attachments are properly named
foreach my $attachment_number ( keys %{ $attachments->{$fcuid} } ) {
my $attachment_name = qq|$attachments->{ $fcuid }{ $attachment_number }|;
# At some point when First Class generates the import script and emails the script
# to the migration server some of the attachments lose their appropriate mime types
# the following code makes sure the best available mime type is chosen
my ( $mediatype, $encoding ) = MIME::Types::by_suffix($attachment_name);
if ( $mediatype eq "" ) {
if ( ( $pop_msg_string =~ /Content-Type:\s*(\S*)\s*name="$attachment_number"/ ) && ( $1 ne "" ) ) {
$mediatype = $1;
}
else {
$mediatype = "application/octet-stream";
}
}
# the MIME::Type module returns "x-msword" for ".doc" attachments but destination won't recognize that and
# put the appropriate icon next to the attachment so we substitute "msword" for "x-msword"
$mediatype =~ s/\/x-msword$/\/msword/g;
if ( $pop_msg_string =~ s/Content-Type:\s*(\S*)\s*name="$attachment_number"(.*)/Content-Type: $mediatype; "$attachment_name"$2/g ) {
$pop_msg_string =~ s/(Content-Disposition:.*filename=")$attachment_number"/$1$attachment_name"/g;
}
}
my $datetime = new Date::Manip::Date;
$datetime->parse( $sync_fcuids->{$fcuid}->{'datetime'} );
$datetime->convert('GMT');
if ( $imap->append_string( "$imap_folder", $pop_msg_string, '\Seen', $datetime->printf('%d-%b-%Y %T %z') ) ) {
$imap_folder_update++;
print print_timestamp() . " : IMAP Updated in Folder: \"$imap_folder\" \t Email: " . $fcuid . "\t" . $sync_fcuids->{$fcuid}->{'datetime'} . "\t" . $imap_fcuid_datetime . "\n";
}
else {
print print_timestamp() . " : IMAP Failed to Update in Folder: \"$imap_folder\" \t Email: " . $fcuid . "\t" . $sync_fcuids->{$fcuid}->{'datetime'} . "\t" . $imap_fcuid_datetime . "\n";
}
}
}
}
$pop_mailbox->close;
return ( $imap_folder_skip, $imap_folder_append, $imap_folder_delete, $imap_folder_update );
}
#---------------------------Actual Processing of Batch Admin Scripts-----------------------------------
sub fc_folder_exists {
my ( $fromuser, $fromfolder ) = @_;
my ($ba_script_subject) = $searchString . "Does User: $fromuser Folder: $fromfolder exist?";
my @ba_script_body = "REPLY\n";
push( @ba_script_body, "IF OBJECT DESKTOP $fromuser \"$fromfolder\" EXISTS\n" );
push( @ba_script_body, "\tWRITE $fromfolder EXISTS: True\nELSE\n\tWRITE $fromfolder EXISTS: False\nENDIF\n" );
email_to_batch_admin( $ba_script_subject, \@ba_script_body );
my ( $matching_file_arrived, $matching_filename ) = wait_for_matching_file_arrival( $rcvdDir, $searchString, $timeout );
if ($matching_file_arrived) {
open( FH, $matching_filename );
my @exists = <FH>;
close(FH);
if ( grep( /$fromfolder EXISTS: True/, @exists ) ) {
return ( 1, 1 );
}
else {
return ( 1, 0 );
}
}
else {
return ( 0, 0 );
}
}
sub convert_folder_names_fc_to_imap {
my ($fc_folder) = @_;
$fc_folder =~ s/:\s+/:/; # remove leading whitespace in a first class folder's name since destination folder names don't allow for it
$fc_folder =~ s/^\s+//; # remove leading whitespace in a first class folder's name since destination folder names don't allow for it
$fc_folder =~ s/\s+:/:/; # remove trailing whitespace in a first class folder's name since destination folder names don't allow for it
$fc_folder =~ s/\s+$//; # remove trailing whitespace in a first class folder's name since destination folder names don't allow for it
$fc_folder =~ s/\s{2,}/ /g; # this just collapses multiple whitespace characters down to a single space since some (or all) imap doesn't like multiple spaces in a folder name
$fc_folder =~ s/&/&-/g; # enables &'s to be used in folder names
$fc_folder =~ s/\//\\/g;
$fc_folder =~ s/:/\//g; # First Class uses ':' in a folder path but destination uses '/' so we make the conversion here
$fc_folder =~ s/\/\\/\//g;
# $fc_folder =~ s/\\/\\\\/g;
$fc_folder =~ s/\?/\|/g;
# FC folder 'Mailbox' maps to imap folder 'INBOX'
$fc_folder =~ s/^.*?(?=\/)|.*/INBOX/; # replace the first folder name with "INBOX"
# FC folder subfolder 'Mailbox:AAA' maps to imap folder 'AAA' a subfolder of root
# FC folder subfolder 'Mailbox:AAA:BBB' maps to imap folder 'AAA/BBB'
$fc_folder =~ s/^INBOX\///i;
return $fc_folder;
}
sub get_fixed_fc_subfolders {
my ( $fromuser, $fromfolder ) = @_;
my %item_names;
my %aliases;
my @folders;
my $failed = 0;
my ($ba_script_subject) = $searchString . "DIR of User: $fromuser Folder: $fromfolder";
my @ba_script_body = "REPLY\n";
push( @ba_script_body, "DIR DESKTOP $fromuser \"$fromfolder\" +lbpsdr\n" );
email_to_batch_admin( $ba_script_subject, \@ba_script_body );
my ( $matching_file_arrived, $matching_filename ) = wait_for_matching_file_arrival( $rcvdDir, $searchString, $timeout );
if ($matching_file_arrived) {
# print print_timestamp() . " : Found: $matching_filename\n";
open( FH, $matching_filename );
my @dir = <FH>;
close(FH);
@ba_script_body = "REPLY\n";
foreach my $dir (@dir) {
if ( ( $dir =~ /\[B:(\d+)\]/ ) && ( $1 ne "" ) ) {
push( @ba_script_body, "WRITE FC-INDEX: $1\n" );
push( @ba_script_body, "get properties byindex $1 desktop $fromuser \"$fromfolder\" 1020\n" );
}
}
email_to_batch_admin( $ba_script_subject, \@ba_script_body );
my ( $matching_file_arrived, $matching_filename ) = wait_for_matching_file_arrival( $rcvdDir, $searchString, $timeout );
if ($matching_file_arrived) {
open( FH, $matching_filename );
while (<FH>) {
if ( (/FC-INDEX: (\d+)/) && ( $1 ne "" ) ) {
my $idx = $1;
if ( ( <FH> =~ /1020 \d+ \"\[.*\] $fromuser.*\"/i ) ) {
$aliases{$idx} = 0;
}
else {
$aliases{$idx} = 1;
}
}
}
close(FH);
}
else {
print print_timestamp() . " : Failed to Get Aliases Report for $fromuser\'s Folder: $fromfolder\n";
$failed = 1;
return $failed;
}
foreach my $dir (@dir) {
if ( ( $dir =~ /\[(\w):(\d+)\] "(.*)" ".*".*/ ) && ( $1 ne "" ) && ( $2 ne "" ) && ( $3 ne "" ) ) {
my $item_index = $2;
my $original_item_name = $3;
my $item_name = $3;
if ( ( $1 eq "B" ) && !$aliases{$item_index} ) {
# if a First Class folder has a ':' in its name then batch admin scripts will get messed up since First Class uses the ':' in a folder's path
# the same way destination uses the '/' in a folder's path so we substitute the ':' with a '|' and rename the First Class folder
# destination does not allow a ':' in its folder names anyway so this fixes that too
$item_name =~ s/:/\|/g;
# if a First Class folder has a '"' in its name then batch admin scripts will get messed up so we substitute '"' with a ''' and rename the First Class folder
# destination does not allow a '"' in its folder names anyway so this fixes that too
$item_name =~ s/"/'/g;
# the following code makes sure that all folder names at a given level in a First Class mailbox are unique
my $temp_item_name = $item_name;
$temp_item_name =~ s/([\^.$|()\[\]])/\\$1/g;
if ( grep( /^$temp_item_name$/i, values(%item_names) ) ) {
my $i = 1;
while ( grep( /^$temp_item_name$i$/i, values(%item_names) ) ) {
$i++;
}
$item_name .= $i;
}
if ( $item_name ne $original_item_name ) {
my ($ba_script_subject) = $searchString . "Rename: $fromuser Folder: $fromfolder:$original_item_name to $fromfolder:$item_name";
my @ba_script_body = "REPLY\n";
push( @ba_script_body, "PUT PROPERTIES BYINDEX $item_index DESKTOP $fromuser \"$fromfolder\" 1017 0 \"$item_name\"\n" );
email_to_batch_admin( $ba_script_subject, \@ba_script_body );
my ( $matching_file_arrived, $matching_filename ) = wait_for_matching_file_arrival( $rcvdDir, $searchString, $timeout );
if ($matching_file_arrived) {
open( FH, $matching_filename );
my @renamed_results = <FH>;
close(FH);
if ( grep( /error/i, @renamed_results ) ) {
print print_timestamp() . " : Failed to Rename $fromuser\'s Folder: $fromfolder:$original_item_name to $fromfolder:$item_name\n";
$failed = 1;
return $failed;
}
else {
print print_timestamp() . " : Renamed $fromuser\'s Folder: $fromfolder:$original_item_name to $fromfolder:$item_name\n";
}
}
else {
print print_timestamp() . " : Failed to Detemine if Renaming $fromuser\'s Folder: $fromfolder:$3 to $fromfolder:$item_name was successful\n";
$failed = 1;
return $failed;
}
}
}
$item_names{$item_index} = $item_name;
}
}
}
else {
print print_timestamp() . " : Failed to Get DIR Report for $fromuser\'s Folder: $fromfolder\n";
$failed = 1;
return ($failed);
}
foreach my $idx ( keys(%item_names) ) {
if ( exists( $aliases{$idx} ) && ( $aliases{$idx} == 0 ) ) {
push( @folders, "$fromfolder:" . $item_names{$idx} );
}
}
my @subfolders;
foreach my $folder (@folders) {
my ( $temp_failed, @temp_subfolders ) = get_fixed_fc_subfolders( $fromuser, $folder );
if ($temp_failed) {
$failed = $temp_failed;
}
push( @subfolders, @temp_subfolders );
}
push( @folders, @subfolders );
return ( $failed, sort( { lc($a) cmp lc($b) } @folders ) );
}
sub request_ba_import_script {
my ( $fromuser, $fromfolder, $startdate, $enddate ) = @_;
my ($ba_script_subject) = $searchString . "Request Import Script for User: $fromuser for Folder: $fromfolder for Date Range: $startdate - $enddate";
my @ba_script_body = "";
# the following Batch Admin command returns an import script for the user's folder
# this import script will only import a specified number of days worth of email
# in order to not overwhelm the servers which would basically prevent us from migrating
if ( $enddate eq "" ) {
push( @ba_script_body, "SETEXPORTFILTERS MODIFIED AFTER $startdate 00:00:00 +d\n" );
}
else {
push( @ba_script_body, "SETEXPORTFILTERS MODIFIED BEFORE $enddate 00:00:00 MODIFIED AFTER $startdate 00:00:00 +d\n" );
}
push( @ba_script_body, "EXPORT DESKTOP $fromuser \"$fromfolder\"\n" );
email_to_batch_admin( $ba_script_subject, \@ba_script_body );
my ( $matching_file_arrived, $matching_filename ) = wait_for_matching_file_arrival( $rcvdDir, $searchString, $timeout );
return ( $matching_file_arrived, $matching_filename );
}
sub process_ba_import_script {
my ($filename) = @_;
my @msg;
my $is_body = 0;
my $content_type = "";
my $boundary = "";
my $is_item = 0;
my @item;
my $is_sent_item = 0;
my $last_cc_index = -1;
my @internet_header_buffer;
my %attachments = ();
my %attachment_names = ();
my $uploaded_file_name = "";
my $keep = 0;
my $subject = "";
my $fc_unique_id = "";
my $fcuid = "";
open( FH, $filename );
foreach my $line (<FH>) {
if ( !$is_body ) {
if ( ( $content_type eq "" ) && ( $line =~ /Content-Type: .*/ ) ) {
$content_type = $line . "\n";
if ( ( $line =~ /Content-Type: .*boundary="(.+)"/ ) && ( $1 ne "" ) ) {
$boundary = $1;
}
if ( $boundary eq "" ) {
$is_body = 1;
}
next;
}
if ( ( $boundary ne "" ) && ( $line =~ /(.*?)($boundary)/ ) ) {
$is_body = 1;
push( @msg, "MIME-Version: 1.0\n" );
push( @msg, "This is a multi-part message in MIME format.\n" );
push( @msg, $line );
}
}
else {
$line =~ s/<ObjDesc>/DESKTOP $migrate_user \"Mailbox\"/;
if ( $line =~ /^\/\/ This script was generated by FirstClass Server/ ) {
push( @msg, "REPLY\n" );
}
if ( $line =~ /^\/\/ Reference: (-?\d{2,}:\S+$)/ ) {
$is_item = 1;
$fc_unique_id = $1;
}
if ( $line =~ /^New Relative ".*" ".*" ".*" \w+ \d+ -?\d+ -?\d+ -?\d*\s?.*-U\+S/ ) {
$is_sent_item = 1;
}
if ( $line =~ /^New Relative "(.*)" "(.*)" "(.*)" (\w+) \d+ -?\d+ -?\d+ -?\d*\s?(.*-U)/ ) {
$keep = 1;
$line = "New Relative \"$1\" \"$2\" \"$3\" Message 23032 0 0 0 $5+R\n";
$subject = $3;
if ( $4 eq "Document" ) {
$subject = $2;
$line = "New Relative \"$1\" \"$2\" \"$2\" Message 23032 0 0 0 $5+R\n";
push( @item, $line );
push( @item, "Put Previous 8 \"Document from First Class <noreply\@noreply.com>\" -V\n" );
push( @item, "Put Previous 4 0 \"Document from First Class <noreply\@noreply.com>\" -V\n" );
next;
}
if ( $4 eq "FCF" ) {
$subject = $2;
$uploaded_file_name = $2;
push( @item, $line );
push( @item, "Put Previous 8 \"Uploaded File from First Class <noreply\@noreply.com>\" -V\n" );
push( @item, "Put Previous 4 0 \"Uploaded File from First Class <noreply\@noreply.com>\" -V\n" );
next;
}
}
### I commented the following out on 12/10/08 to wait until i got the problems again so i can work on this more
### This next stuff tries to address an issue with To and CC fields
### Sometimes there is a long address without an @ symbol which causes First Class to choke on import
### The only problem is the following code messes normal To CC fields up so something needs to get fixed
# make sure any To/CC addresses have an @ symbol in them
### if ( $line !~ /^Put Previous [45] \d+ ".*\@.*"/ ) {
### $line =~ s/(^Put Previous [45] \d+ ")(.*)(".*)/$1$2\@$3/;
### }
if ( $line =~ /^Put Previous 8120 .*/ ) { next; }
# if there are any BCC addresses in a sent email we need to change them to CC addresses because otherwise they will get lost
# this means we have to keep track of the count of original CC addresses so we can index the BCC addresses correctly
if ( $is_sent_item && ( $line =~ /^Put Previous 5 (\d+) ".*" -V/ ) ) { $last_cc_index = $1; }
if ( $is_sent_item && ( $line =~ /^Put Previous 14 \d+ "\s*(.*)" -V/ ) ) {
$line = "Put Previous 5 " . ++$last_cc_index . " \"$1\" -V\n";
}
if ( ( $line =~ /^(Upload Previous ".+?")/ ) && ( $uploaded_file_name ne "" ) ) {
$line = $1 . " \"$uploaded_file_name\"\n";
}
# First Class's POP3 implementation truncates the name of any email attachment if the attachment's name length exceeds 31 characters
# the following 'if' block makes sure that all email attachment names are captured so they can be used later to fix the names
if ( $line =~ /^Upload Previous "(.+)" "(.+)"/ ) {
$attachment_names{$1} = $2;
$line = "Upload Previous \"$1\"\n";
}
# save the internet headers for later clean up
if ( $line =~ /^Put Previous 8014.0 0 "(.*)"/ ) {
push( @internet_header_buffer, $1 );
next;
}
if ( $line =~ /^Put Properties Previous 1018 14 (.*)$/ ) {
$fcuid = $fc_unique_id . "|" . $1;
# First Class's POP3 implementation truncates the name of any email attachment if the attachment's name length exceeds 31 characters
# this saves the email attachment names for later so they can be used later to fix the names
foreach my $attachment_number ( keys(%attachment_names) ) {
$attachments{$fcuid}{$attachment_number} = $attachment_names{$attachment_number};
}
push( @item, "Put Previous 8120 7 1252 8140 0 8141 0 8126 $1 9 \"$subject\"\n\n" );