예제 #1
0
 public function getInbox($inboxObj)
 {
     $userId = parent::getUserId();
     if ($userId == false) {
         return "Invalid User";
     }
     // Connect to a user's email account inbox
     $contextio = new ContextIO(CONTEXTIO_KEY, CONTEXTIO_SECRET);
     $inboxParamsArray = array("label" => 0, "folder" => "INBOX", "include_body" => 1, "include_headers" => 0, "offset" => $inboxObj["offset"], "limit" => 50);
     // get the messages
     $apiResponse = $contextio->listMessages($inboxObj["contextio_id"], $inboxParamsArray);
     // get the emails that have been shared by this user.
     $sth = $this->db->prepare("SELECT * FROM Shares WHERE UserId = :userId");
     $sth->execute(array(":userId" => $userId));
     $sharesRows = $sth->fetchAll();
     $response = array();
     $response["Success"] = true;
     $response["ApiResponse"] = $apiResponse->getData();
     $response["Shares"] = $sharesRows;
     return $response;
 }
예제 #2
0
// Include the functions
require '/var/www/html/includes/functions.php';
require '/var/www/html/includes/calendar.php';
require '/var/www/html/includes/handle_sendgrid.php';
require_once '/var/www/html/php-libraries/contextio/class.contextio.php';
$contextIO = new ContextIO(getenv('CONTEXTIO_KEY'), getenv('CONTEXTIO_SECRET'));
$accountId = null;
$r = $contextIO->listAccounts();
foreach ($r->getData() as $account) {
    echo 'Scraping ' . $account['id'] . "\t" . join(", ", $account['email_addresses']) . PHP_EOL;
    if (is_null($accountId)) {
        $accountId = $account['id'];
    }
}
$contextIO->syncSource($accountId);
$r = $contextIO->listMessages($accountId, array('include_body' => true));
foreach ($r->getData() as $message) {
    $msg_id = $message['message_id'];
    $subject = $message['subject'];
    $date_received = date("Y-m-d H:i:s", $message['date_received']);
    $recipient = $message['addresses']['to'][0]['email'];
    $sender_email = $message['addresses']['from']['email'];
    $sender_name = $message['addresses']['from']['name'];
    $constraints_after = NULL;
    $constraints_before = NULL;
    $requested_date = NULL;
    $hours = 0;
    $main_body = '';
    $bodies = $message['body'];
    foreach ($bodies as $body) {
        if ($body['type'] == 'text/plain') {
예제 #3
0
// list your accounts
$r = $contextIO->listAccounts();
foreach ($r->getData() as $account) {
    echo $account['id'] . "\t" . join(", ", $account['email_addresses']) . "\n";
    if (is_null($accountId)) {
        $accountId = $account['id'];
    }
}
if (is_null($accountId)) {
    die;
}
// EXAMPLE 1
// Print the subject line of the last 20 emails sent to with bill@widgets.com
$args = array('to' => '*****@*****.**', 'limit' => 20);
echo "\nGetting last 20 messages exchanged with {$args['to']}\n";
$r = $contextIO->listMessages($accountId, $args);
foreach ($r->getData() as $message) {
    echo "Subject: " . $message['subject'] . "\n";
}
// EXAMPLE 2
// Download all versions of the last 2 attachments exchanged with bill@widgets.com
$saveToDir = dirname(__FILE__) . "/" . mt_rand(100, 999);
mkdir($saveToDir);
$args = array('email' => '*****@*****.**', 'limit' => 2);
echo "\nObtaining list of last two attachments exchanged with {$args['email']}\n";
$r = $contextIO->listFiles($accountId, $args);
foreach ($r->getData() as $document) {
    echo "\nDownloading all versions of document \"" . $document['file_name'] . "\"\n";
    foreach ($document['occurrences'] as $attachment) {
        echo "Downloading attachment '" . $attachment['file_name'] . "' to {$saveToDir} ... ";
        $contextIO->getFileContent($accountId, array('file_id' => $attachment['fileId']), $saveToDir . "/" . $attachment['file_name']);