-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathemail.php
More file actions
97 lines (74 loc) · 2.37 KB
/
email.php
File metadata and controls
97 lines (74 loc) · 2.37 KB
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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(0);
$cp_src = "{mail.servidororigem.com:143/novalidate-cert}";
$cp_dst = "{mail.servidordestino.com}";
$ls_emails['conta01@example.com'] = 'Senha0x1';
$ls_emails['conta02@example.com'] = 'Senha0x2';
$ls_emails['conta03@example.com'] = 'Senha0x3';
$ls_emails['conta04@example.com'] = 'Senha0x4';
foreach($ls_emails as $account => $password){
$src_mbox = imap_open($cp_src, $account, $password);
$dest_mbox = imap_open($cp_dst, $account, $password);
$list = imap_list ( $src_mbox , $cp_src , "*" );
pre("Migration account $account from $cp_src to $cp_dst");
foreach($list as $mbox){
pre("WORKING IN ".$mbox);
$mbox = imap_utf7_encode($mbox);
$cbox = str_replace($cp_src, $cp_dst, $mbox);
imap_createmailbox($dest_mbox, $cbox );
$current_box = imap_open($cbox, $account, $password);
$current_src = imap_open($mbox, $account, $password);
$status = imap_status($current_src, $mbox, SA_ALL);
$msgs = imap_sort($current_src, SORTDATE, 1, SE_UID);
foreach ($msgs as $msguid) {
$i = imap_msgno($current_src, $msguid);
$headers = imap_headerinfo($current_src, $i);
if(!is_object($headers))
continue;
$Unseen = (trim($headers->Unseen) != "");
$Flagged = (trim($headers->Flagged) != "");
$Answered = (trim($headers->Answered) != "");
$Deleted = (trim($headers->Deleted) != "");
$Draft = (trim($headers->Draft) != "");
$MailDate = $headers->MailDate;
$options = "";
if( !$Unseen ){
$options .='\\Seen ';
}
if( $Flagged ){
$options .='\\Flagged ';
}
if( $Answered ){
$options .='\\Answered ';
}
if( $Deleted ){
$options .='\\Deleted ';
}
if( $Draft ){
$options .='\\Draft ';
}
$check = imap_check($current_src);
pre( "Msg Count before append: ". $check->Nmsgs);
$contents = imap_fetchheader($current_src, $i) . "\r\n" . imap_body($current_src, $i, FT_PEEK);
$result = imap_append($current_box, $cbox, $contents, $options, date('d-M-Y H:i:s O', $headers->udate));
if( $result ){
imap_delete($current_src, $i);
imap_expunge($current_src);
}
var_dump($result);
$check = imap_check($current_src);
pre("Msg Count after append: ". $check->Nmsgs);
}
}
}
function pre($str, $bol=false){
echo '<pre>';
print_r($str);
echo '</pre>';
if($bol)
exit;
return;
}
?>