/**
  * Retrieve Message Headers List from Server
  *
  * @method getMessageList
  *
  * @param {integer} headerCount - the number of records to retrieve
  * @param {array} offset and optional parameters
  * 		- offset => (opts[:offset] || 0)
  * 	    - messageIds => opts[:messageIds]
  * 	    - isUnread => opts[:isUnread]
  * 	    - isFavorite => opts[:isFavorite]
  * 	    - type => opts[:type]
  * 	    - keyword => opts[:keyword]
  * 	    - isIncoming => opts[:isIncoming]
  *
  * @return {Response} Returns Response object
  * @throws ServiceException if API request was not successful.
  */
 public function getMessageList($headerCount, $opts)
 {
     // Get OAuth token
     $token = $this->getSessionConsentToken('MIM');
     $immnSrvc = new IMMNService($this->base_url, $token);
     $offset = isset($opts['offset']) ? $opts['offset'] : '0';
     if ($offset == '') {
         $offset = '0';
     }
     // This could be sent as blank.
     $msgIds_array = array();
     if (isset($opts['messageIds'])) {
         $msgIds = $opts['messageIds'];
         if (strstr($msgIds, ",")) {
             $msgIds_array = explode(",", $msgIds);
         } else {
             array_push($msgIds_array, $msgIds);
         }
     }
     $isUnread = isset($opts['isUnread']) ? $opts['isUnread'] : null;
     $type = isset($opts['type']) ? $opts['type'] : null;
     $keyword = isset($opts['keyword']) ? $opts['keyword'] : null;
     $isIncoming = isset($opts['isIncoming']) ? $opts['isIncoming'] : null;
     $isFavorite = isset($opts['isFavorite']) ? $opts['isFavorite'] : null;
     // getMessageList($limit, $offset, $msgIds=null,$isUnread=null, $type=null, $keyword=null, $isIncoming=null, $isFav=null, $raw_response = false)
     return $immnSrvc->getMessageList($headerCount, $offset, $msgIds_array, $isUnread, $type, $keyword, $isIncoming, $isFavorite, true);
 }
Example #2
0
    // Specify the address to where the message is sent.
    $addr = array('ENTER VALUE!');
    // Send a test message.
    $response = $immnSrvc->sendMessage($addr, 'Text', 'Subject');
    echo "msgId: " . $response . "\n";
} catch (ServiceException $se) {
    echo $se->getErrorResponse();
}
/* This try/catch block tests the getMessageList method.*/
try {
    // Enter the number of messages to include in the list.
    $limit = 'ENTER VALUE!';
    // Enter the offset to the first message.
    $offset = 'ENTER VALUE!';
    // Send the request to get the message list.
    $msgList = $immnSrvc->getMessageList($limit, $offset);
    echo "total: " . $msgList->getTotal() . "\n";
} catch (ServiceException $se) {
    echo $se->getErrorResponse();
}
/* This try/catch block tests the getMessage method. */
try {
    // Specify the id of the message to retrieve.
    $msgId = 'ENTER VALUE!';
    // Send the request to get the message.
    $msg = $immnSrvc->getMessage($msgId);
    echo "msgId: " . $msg->getMessageId() . "\n";
} catch (ServiceException $se) {
    echo $se->getErrorResponse();
}
/* This try/catch block tests the getMessageContent method. */
 public function handleGetMsgList()
 {
     $vnames = array('getMessageList', 'favorite', 'unread', 'incoming', 'keyword');
     $this->copyToSession($vnames);
     if (!isset($_SESSION['getMessageList'])) {
         return;
     }
     try {
         /* unset checkboxes */
         if (!isset($_REQUEST['favorite'])) {
             unset($_SESSION['favorite']);
         }
         if (!isset($_REQUEST['unread'])) {
             unset($_SESSION['unread']);
         }
         if (!isset($_REQUEST['incoming'])) {
             unset($_SESSION['incoming']);
         }
         $limit = 5;
         /* TODO: move to config */
         $offset = 0;
         /* TODO: move to config */
         $msgIds = null;
         $type = null;
         $fvt = isset($_SESSION['favorite']) ? $_SESSION['favorite'] : null;
         $unread = isset($_SESSION['unread']) ? $_SESSION['unread'] : null;
         $incoming = isset($_SESSION['incoming']) ? $_SESSION['incoming'] : null;
         $keyword = isset($_SESSION['keyword']) ? $_SESSION['keyword'] : null;
         $immnSrvc = new IMMNService($this->apiFQDN, $this->getSessionToken());
         $this->clearSession(array('getMessageList'));
         $msgList = $immnSrvc->getMessageList($limit, $offset, $msgIds, $unread, $type, $keyword, $incoming, $fvt);
         $this->results[C_GET_MSG_LIST] = $msgList;
     } catch (Exception $e) {
         $this->errors[C_GET_MSG_LIST] = $e->getMessage();
         $this->clearSession(array('getMessageList'));
     }
 }
session_start();
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/../lib/IMMN/IMMNService.php';
require_once __DIR__ . '/../lib/Util/Util.php';
use Att\Api\IMMN\IMMNService;
use Att\Api\Util\Util;
$arr = null;
try {
    envinit();
    $immnSrvc = new IMMNService(getFqdn(), getSessionToken());
    /* TODO: move to config */
    $limit = 5;
    $offset = 0;
    $msgIds = null;
    $type = null;
    $fvt = isset($_POST['favorite']) ? $_POST['favorite'] : null;
    $unread = isset($_POST['unread']) ? true : false;
    $incoming = isset($_POST['incoming']) ? true : false;
    $keyword = $_POST['keyword'];
    $msgList = $immnSrvc->getMessageList($limit, $offset, $msgIds, $unread, $type, $keyword, $incoming, $fvt);
    $msgValues = array();
    $msgs = $msgList->getMessages();
    foreach ($msgs as $msg) {
        $msgValues[] = Util::convertNulls(array($msg->getMessageId(), $msg->getFrom(), $msg->getRecipients(), $msg->getText(), $msg->getTimeStamp(), $msg->isFavorite(), $msg->isUnread(), $msg->isIncoming(), $msg->getMessageType()));
    }
    $arr = array('success' => true, 'tables' => array(array('caption' => 'Details:', 'headers' => array('Limit', 'Offset', 'Total', 'Cache Status', 'Failed Messages', 'State'), 'values' => array(array($msgList->getLimit(), $msgList->getOffset(), $msgList->getTotal(), $msgList->getCacheStatus(), $msgList->getFailedMessages(), $msgList->getState()))), array('caption' => 'Messages:', 'headers' => array('Message ID', 'From', 'Recipients', 'Text', 'Timestamp', 'Favorite', 'Unread', 'Incoming', 'Type'), 'values' => $msgValues)));
} catch (Exception $e) {
    $arr = array('success' => false, 'text' => $e->getMessage());
}
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */