Mail_IMAP
[ class tree: Mail_IMAP ] [ index: Mail_IMAP ] [ all elements ]

Mail_IMAP Inbox

  1. <?php
  2.  
  3.     /**
  4.      * Demonstrates how to set-up a basic inbox using Mail_IMAP.
  5.      * See {@link connect} for extended documentation on
  6.      * how to set the connection URI.
  7.      *
  8.      * @author      Richard York <richy@smilingsouls.net>
  9.      * @copyright   (c) Copyright 2004, Richard York, All Rights Reserved.
  10.      * @package     Mail_IMAP
  11.      * @subpackage  examples
  12.      **
  13.     */
  14.  
  15.     require_once 'Mail/IMAP.php';
  16.  
  17.     // Set up class, initiate a mailbox connection
  18.     $msg =new Mail_IMAP();
  19.  
  20.     // Open up a mail connection
  21.     // pop3://user:pass@mail.example.com:110/INBOX#notls
  22.     // Use an existing imap resource stream, or provide a URI abstraction.
  23.     //
  24.     // If you are unsure of the URI syntax to use here,
  25.     // use the Mail_IMAP_connection_wizard to find the right URI.
  26.     // Or see docs for Mail_IMAP::connect
  27.     //
  28.     // This argument must also be set in MAIL_IMAP.message.php.
  29.     if (PEAR::isError($msg->connect('imap://user:pass@mail.someserver.net:143/INBOX'))) {
  30.         echo "<span style='font-weight: bold;'>Error:</span> Unable to build a connection.";
  31.     }
  32.  
  33.     // Retrieve message count
  34.     $msgcount $msg->messageCount();
  35.  
  36.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  37.         <html>
  38.             <head>
  39.                 <title> Mail_IMAP Inbox </title>
  40.                 <style type='text/css' media='screen'>
  41.                     *
  42.                     {
  43.                         font-family: Arial;
  44.                     }
  45.  
  46.                     a:hover
  47.                     {
  48.                         border: 1px solid olive;
  49.                         background: greenyellow;
  50.                         color: black;
  51.                         text-decoration: none;
  52.                     }
  53.  
  54.                     table.msg, td.msghead, td.footer, #inboxheader, td.msgcount
  55.                     {
  56.                         border: 1px solid black;
  57.                     }
  58.  
  59.                     table.msg
  60.                     {
  61.                         width: 100%;
  62.                         background: aliceblue;
  63.                     }
  64.  
  65.                     td.msgattach
  66.                     {
  67.                         font-size: 8pt;
  68.                         text-decoration: none;
  69.                         padding: 5px;
  70.                     }
  71.  
  72.                     td.msgattach a
  73.                     {
  74.                         color: darkgreen;
  75.                     }
  76.  
  77.                     td.msghead, td.footer, td.msgitem
  78.                     {
  79.                         padding: 5px;
  80.                         font-weight: bold;
  81.                     }
  82.                     td.msghead
  83.                     {
  84.                         font-size: 14pt;
  85.                         background: palegreen;
  86.                     }
  87.  
  88.                     td.footer
  89.                     {
  90.                         font-size: 8pt;
  91.                         text-align: right;
  92.                         background: palegreen;
  93.                     }
  94.  
  95.                     td.msgcount
  96.                     {
  97.                         background: skyblue;
  98.                         font-size: 14pt;
  99.                     }
  100.  
  101.                     #inboxheader
  102.                     {
  103.                         font-size: 25pt;
  104.                         vertical-align: top;
  105.                         padding: 10px;
  106.                         background: palegreen;
  107.                     }
  108.  
  109.                 </style>
  110.             </head>
  111.             <body>
  112.                 <table class='msg'>
  113.                     <tr>
  114.                         <td id='inboxheader'>
  115.                             Mail_IMAP
  116.                         </td>
  117.                         <td colspan='2' class='msghead'>
  118.                             Unread messages are <span style='font-weight: bold; color: green;'>GREEN</span><br />
  119.                             Read messages are <span style='font-weight: bold; color: black;'>BLACK</span><br />
  120.                             <span style='font-size: 8pt;'>If you are using an IMAP-protocol based mail server, POP3 doesn't remember flag settings.</span>
  121.                         </td>
  122.                     </tr>
  123.                     <tr>
  124.                         <td colspan='3' class='msgcount'>
  125.                             {$msg->mailboxInfo['folder']}: ($msgcount) messages total.
  126.                         </td>
  127.                     </tr>
  128.                     <tr>
  129.                         <td class='msghead'>
  130.                             subject
  131.                         </td>
  132.                         <td class='msghead'>
  133.                             from
  134.                         </td>
  135.                         <td class='msghead'>
  136.                             received
  137.                         </td>
  138.                     </tr>\n";
  139.  
  140.     if ($msgcount > 0)
  141.     {
  142.         /*
  143.          * Each message of a mailbox is numbered offset from 1
  144.          * Create the $mid (message id) and recursively gather
  145.          * message information.
  146.         */
  147.         for ($mid = 1; $mid <= $msgcount$mid++)
  148.         {
  149.             // Get the default part id
  150.             $pid $msg->getDefaultPid($mid);
  151.  
  152.             // Parse header information
  153.             $msg->getHeaders($mid$pid);
  154.  
  155.             $style ((isset($msg->header[$mid]['Recent']&& $msg->header[$mid]['Recent'== 'N'|| (isset($msg->header[$mid]['Unseen']&& $msg->header[$mid]['Unseen'== 'U'))'green' 'black';
  156.  
  157.             // Parse inline/attachment information specific to this part id
  158.             //
  159.             // See member variables begining with in or attach for
  160.             // available information
  161.             $msg->getParts($mid$pid);
  162.  
  163.             if (!isset($msg->header[$mid]['subject']|| empty($msg->header[$mid]['subject']))
  164.             {
  165.                 $msg->header[$mid]['subject'"<span style='font-style: italic;'>no subject provided</a>";
  166.             }
  167.  
  168.             echo "                        <tr>\n",
  169.                  "                            <td class='msgitem'><a href='IMAP.message.php?mid={$mid}&amp;pid={$pid}' target='_blank' style='color: {$style};'>{$msg->header[$mid]['subject']}</a></td>\n",
  170.                  "                            <td class='msgitem'>\n",
  171.                  "                              "(isset($msg->header[$mid]['from_personal'][0]&& !empty($msg->header[$mid]['from_personal'][0]))'<span title="'.$msg->header[$mid]['from'][0].'">'.$msg->header[$mid]['from_personal'][0]."</span>" $msg->header[$mid]['from'][0]"\n",
  172.                  "                            </td>\n",
  173.                  "                            <td class='msgitem'>".date('D, M d, Y h:i:s'$msg->header[$mid]['udate'])."</td>\n",
  174.                  "                        </tr>\n",
  175.                  "                        <tr>\n",
  176.                  "                            <td colspan='3' class='msgattach'>\n";
  177.  
  178.             // Show inline parts first
  179.             if (isset($msg->inPid[$mid]&& count($msg->inPid[$mid]> 0)
  180.             {
  181.                 foreach ($msg->inPid[$midas $i => $inid)
  182.                 {
  183.                     echo "                              Inline part: <a href='IMAP.message.php?mid={$mid}&amp;pid={$msg->inPid[$mid][$i]}' target='_blank'>{$msg->inFname[$mid][$i]} {$msg->inFtype[$mid][$i]} ".$msg->convertBytes($msg->inFsize[$mid][$i])."</a><br />\n";
  184.                 }
  185.             }
  186.  
  187.             // Now the attachments
  188.             if (isset($msg->attachPid[$mid]&& count($msg->attachPid[$mid]> 0)
  189.             {
  190.                 foreach ($msg->attachPid[$midas $i => $aid)
  191.                 {
  192.                     echo "                              Attachment: <a href='IMAP.message.php?mid={$mid}&amp;pid={$msg->attachPid[$mid][$i]}' target='_blank'>{$msg->attachFname[$mid][$i]} {$msg->attachFtype[$mid][$i]} ".$msg->convertBytes($msg->attachFsize[$mid][$i])."</a><br />\n";
  193.                 }
  194.             }
  195.  
  196.             echo "                            </td>\n",
  197.                  "                        </tr>\n";
  198.  
  199.             // Clean up left over variables
  200.             $msg->unsetParts($mid);
  201.             $msg->unsetHeaders($mid);
  202.         }
  203.     }
  204.     else
  205.     {
  206.         echo "                        <tr>\n",
  207.              "                            <td colspan='3' style='font-size: 30pt; text-align: center; padding: 50px 0px 50px 0px;'>No Messages</td>",
  208.              "                        </tr>\n";
  209.     }
  210.  
  211.     echo "                        <tr>\n",
  212.          "                          <td colspan='3' class='footer'>\n",
  213.          "                              mailbox: {$msg->mailboxInfo['user']}<br />\n";
  214.  
  215.     // getQuota doesn't work for some servers
  216.     if (!PEAR::isError($quota $msg->getQuota()))
  217.     {
  218.         echo "                              Quota: {$quota['STORAGE']['usage']} used of {$quota['STORAGE']['limit']} total\n";
  219.     }
  220.  
  221.     echo "                          </td>\n",
  222.          "                      </tr>\n",
  223.          "                  </table>\n",
  224.          "          </body>\n",
  225.          "      </html>";
  226.          
  227.     // Close the stream
  228.     $msg->close();
  229. ?>

Documentation generated on Mon, 11 Mar 2019 10:15:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.