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.yourhost.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 "
  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.             echo "                        <tr>\n",
  164.                  "                            <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",
  165.                  "                            <td class='msgitem'>\n",
  166.                  "                              "(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",
  167.                  "                            </td>\n",
  168.                  "                            <td class='msgitem'>".date('D, M d, Y h:i:s'$msg->header[$mid]['udate'])."</td>\n",
  169.                  "                        </tr>\n",
  170.                  "                        <tr>\n",
  171.                  "                            <td colspan='3' class='msgattach'>\n";
  172.  
  173.             // Show inline parts first
  174.             if (isset($msg->inPid[$mid]&& count($msg->inPid[$mid]> 0)
  175.             {
  176.                 foreach ($msg->inPid[$midas $i => $inid)
  177.                 {
  178.                     echo "                              Inline part: <a href='IMAP.message.php?mid={$mid}&amp;pid={$msg->inPid[$mid][$i]}' target='_blank'>{$msg->inFtype[$mid][$i]} ".$msg->convertBytes($msg->inFsize[$mid][$i])."</a><br />\n";
  179.                 }
  180.             }
  181.  
  182.             // Now the attachments
  183.             if (isset($msg->attachPid[$mid]&& count($msg->attachPid[$mid]> 0)
  184.             {
  185.                 foreach ($msg->attachPid[$midas $i => $aid)
  186.                 {
  187.                     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";
  188.                 }
  189.             }
  190.  
  191.             echo "                            </td>\n",
  192.                  "                        </tr>\n";
  193.  
  194.             // Clean up left over variables
  195.             $msg->unsetParts($mid);
  196.             $msg->unsetHeaders($mid);
  197.         }
  198.     }
  199.     else
  200.     {
  201.         echo "                        <tr>\n",
  202.              "                            <td colspan='3' style='font-size: 30pt; text-align: center; padding: 50px 0px 50px 0px;'>No Messages</td>",
  203.              "                        </tr>\n";
  204.     }
  205.  
  206.     echo "                        <tr>\n",
  207.          "                          <td colspan='3' class='footer'>\n",
  208.          "                              mailbox: {$msg->mailboxInfo['user']}<br />\n";
  209.  
  210.     // getQuota doesn't work for some servers
  211.     if (!PEAR::isError($quota $msg->getQuota()))
  212.     {
  213.         echo "                              Quota: {$quota['STORAGE']['usage']} used of {$quota['STORAGE']['limit']} total\n";
  214.     }
  215.  
  216.     echo "                          </td>\n",
  217.          "                      </tr>\n",
  218.          "                  </table>\n",
  219.          "          </body>\n",
  220.          "      </html>";
  221.  
  222.     // Close the stream
  223.     $msg->close();
  224. ?>

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