-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.php
More file actions
80 lines (64 loc) · 2.1 KB
/
main.php
File metadata and controls
80 lines (64 loc) · 2.1 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
<?PHP
require_once "Imap.php";
require_once "html2text.php";
require_once "CommentExtractor.php";
$mailbox = 'imap.mail.yahoo.com';
$username = '****@yahoo.com';
$password = '****';
$encryption = 'ssl'; // or ssl or ''
$srcFolder = "UnReadTasks";
$moveToFolder = "ReadedTasks";
// ===================================
// connect to mail server
// ===================================
// open connection
$imap = new Imap ( $mailbox, $username, $password, $encryption );
// stop on error
if ($imap->isConnected () === false)
die ( $imap->getError () );
// =========================================================
// do validaiton of folder
// ========================================================
if (! $imap->haveFolder ( $srcFolder )) {
die ( "folder '$srcFolder' is not exiting in mail" );
}
if (! $imap->haveFolder ( $moveToFolder )) {
die ( "folder '$moveToFolder' is not exiting in mail" );
}
// ===============================
// select folder Inbox
// ==============================
$imap->selectFolder ( $srcFolder );
// =======================================
// fetch all messages in the current folder
// =======================================
$emails = $imap->getMessages ();
// start loop 1
foreach ( $emails as $message ) {
$email_body = $message ['body'];
$email_from = $message ['from'] ['email'];
$email_uid = $message ['uid'];
$email_subject = $message ['subject'];
$email_date = $message ['date'];
$taskId = extractTaskIdFromEmailSubject ( $email_subject );
if ($taskId == NIL) {
continue;
}
$plainEmailBody = $email_body;
if ($message ['html']) {
$plainEmailBody = convert_html_to_text ( $email_body );
}
$comment = extractCommmentFromTextEmailBody ( $plainEmailBody );
echo ">>>>>>>>>>>>>>>>eamil header>>>>>>>>>>>>\n";
print $taskId . "\n";
print $email_from . "\n";
print $email_uid . "\n";
print $email_subject . "\n";
print $email_date . "\n";
echo ">>>>>>>>>>>>>>>>eamil end>>>>>>>>>>>>\n";
// ===============================
// insert DB
// ==============================
// move to another folder
$imap->moveMessage ( $message ['id'], $moveToFolder );
}//end loop 1