-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
66 lines (49 loc) · 2.94 KB
/
example.php
File metadata and controls
66 lines (49 loc) · 2.94 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
<?php
include_once "PHPimap2array_v2.php";
// create and init the object
////////////////////////////////////////////////////////////////////////////////////
$obj1 = new PHPimap2array_v2();
if ($obj1->init('ssl://outlook.office365.com', 993) === false)
{echo "\ninit() failed: " . $obj1->error . "\n";exit;}
////////////////////////////////////////////////////////////////////////////////////
// FOR OUTLOOK, skip this part if you authenticate with PLAIN Authentication
////////////////////////////////////////////////////////////////////////////////////
// retrieve the bearer token
// XOAUTH2-access to outlook365-accounts works only for work- or school- accounts,
// personal accounts wont work!
////////////////////////////////////////////////////////////////////////////////////
$bearertoken = $obj1->getToken_outlook("client_credentials",
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // client-id
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // client-secret
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // tenant-id
"user@xxxxxxxxxx.onmicrosoft.com"); // user-email
if ($obj1->xoauth2_authenticate($bearertoken) === false)
{echo "\nauthenticate() failed: " . $obj1->error . "\n";exit;}
////////////////////////////////////////////////////////////////////////////////////
// PLAIN authentication, skip this part if you authenticate with OAUTH2
if ($obj1->plain_authenticate('user@mailhost', 'password') === false)
{echo "\nauthenticate() failed: " . $obj1->error . "\n";exit;}
////////////////////////////////////////////////////////////////////////////////////
// select the INBOX folder and retrieve the newest uid
$last_uid = $obj1->select_folder("INBOX");
if ($last_uid == false)
{echo "\nselect INBOX failed: " . $obj1->error . "\n";exit;}
////////////////////////////////////////////////////////////////////////////////////
// retrieve a list of UID (array)
$uid_list = $obj1->uid_list();
////////////////////////////////////////////////////////////////////////////////////
// retrieve the (unfolded) header (string)
$unfolded_header_arr = $obj1->get_unfolded_header_from_uid($uid);
////////////////////////////////////////////////////////////////////////////////////
// retrieve the header in json-format (string)
$convert_header_to_lowercase=true;
$header_json = $obj1->get_header_from_uid_in_json($uid, $convert_header_to_lowercase);
////////////////////////////////////////////////////////////////////////////////////
// retrieve the (unfolded) header with keys (array)
$header_with_key = $obj1->get_header_from_uid_with_key($uid,true);
////////////////////////////////////////////////////////////////////////////////////
// "message_to_array" parses the entire message into an array-structure
$mail_structured = $obj1->message_to_array($last_uid);
echo "\n".$header_json."\n\n";
print_r($mail_structured);
?>