<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[2260] 2013/codebykat/post-by-email/trunk: Added support for SSL and IMAP</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://gsoc.trac.wordpress.org/changeset/2260">2260</a></dd>
<dt>Author</dt> <dd>codebykat</dd>
<dt>Date</dt> <dd>2013-09-06 08:00:28 +0000 (Fri, 06 Sep 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Added support for SSL and IMAP
Added option to mark messages as read instead of deleting them (IMAP only)</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#2013codebykatpostbyemailtrunkclasspostbyemailadminphp">2013/codebykat/post-by-email/trunk/class-post-by-email-admin.php</a></li>
<li><a href="#2013codebykatpostbyemailtrunkclasspostbyemailphp">2013/codebykat/post-by-email/trunk/class-post-by-email.php</a></li>
<li><a href="#2013codebykatpostbyemailtrunkreadmetxt">2013/codebykat/post-by-email/trunk/readme.txt</a></li>
<li><a href="#2013codebykatpostbyemailtrunkviewsadminphp">2013/codebykat/post-by-email/trunk/views/admin.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#2013codebykatpostbyemailtrunkincludeHordeStreamTempphp">2013/codebykat/post-by-email/trunk/include/Horde/Stream/Temp.php</a></li>
<li><a href="#2013codebykatpostbyemailtrunkincludeHordeStreamphp">2013/codebykat/post-by-email/trunk/include/Horde/Stream.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="2013codebykatpostbyemailtrunkclasspostbyemailadminphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/class-post-by-email-admin.php (2259 => 2260)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/class-post-by-email-admin.php 2013-09-06 08:00:25 UTC (rev 2259)
+++ 2013/codebykat/post-by-email/trunk/class-post-by-email-admin.php    2013-09-06 08:00:28 UTC (rev 2260)
</span><span class="lines">@@ -78,6 +78,9 @@
</span><span class="cx">                  $options['default_email_category'] = '';
</span><span class="cx">          }
</span><span class="cx"> 
</span><ins>+               $options['ssl'] = isset( $input['ssl'] );
+               $options['delete_messages'] = isset( $input['delete_messages'] );
+
</ins><span class="cx">           return $options;
</span><span class="cx">  }
</span><span class="cx"> 
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkclasspostbyemailphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/class-post-by-email.php (2259 => 2260)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/class-post-by-email.php       2013-09-06 08:00:25 UTC (rev 2259)
+++ 2013/codebykat/post-by-email/trunk/class-post-by-email.php  2013-09-06 08:00:28 UTC (rev 2260)
</span><span class="lines">@@ -63,12 +63,15 @@
</span><span class="cx">   *
</span><span class="cx">   * @var      array
</span><span class="cx">   */
</span><del>-       protected $default_options = array(
-               'mailserver_url' => 'mail.example.com',
-               'mailserver_login' => 'login@example.com',
-               'mailserver_pass' => 'password',
-               'mailserver_port' => 110,
-               'default_email_category' => '');
</del><ins>+        protected static $default_options = array(
+               'mailserver_url'                        => 'mail.example.com',
+               'mailserver_login'                      => 'login@example.com',
+               'mailserver_pass'                       => 'password',
+               'mailserver_port'                       => 993,
+               'ssl'                                           => true,
+               'default_email_category'        => '',
+               'delete_messages'                       => false
+       );
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">  * Active connection.
</span><span class="lines">@@ -122,22 +125,22 @@
</span><span class="cx">   */
</span><span class="cx">  public static function activate( $network_wide ) {
</span><span class="cx">          // set up plugin options
</span><del>-               $options = get_option( 'post_by_email_options' );
</del><ins>+                $plugin_options = get_option( 'post_by_email_options' );
</ins><span class="cx"> 
</span><del>-               if( ! $options ) {
-                       $options = $this->default_options;
</del><ins>+                $options = self::$default_options;
</ins><span class="cx"> 
</span><del>-                       // if old global options exist, copy them into plugin options
-                       foreach( array_keys( $this->default_options ) as $optname ) {
-                               if( get_option( $optname ) ) {
-                                       $options[ $optname ] = get_option( $optname );
-                                       //delete_option( $optname );                    
-                               }
</del><ins>+                // if old global options exist, copy them into plugin options
+               foreach( array_keys( self::$default_options ) as $optname ) {
+                       if( isset( $plugin_options[$optname] ) ) {
+                               $options[$optname] = $plugin_options[$optname];
</ins><span class="cx">                   }
</span><del>-
-                       update_option( 'post_by_email_options', $options );
</del><ins>+                        elseif ( get_option( $optname ) ) {
+                               $options[ $optname ] = get_option( $optname );
+                       }
</ins><span class="cx">           }
</span><span class="cx"> 
</span><ins>+               update_option( 'post_by_email_options', $options );
+
</ins><span class="cx">           // if log already exists, this will return false, and that is okay
</span><span class="cx">          add_option( 'post_by_email_log', array(), '', 'no' );
</span><span class="cx"> 
</span><span class="lines">@@ -210,7 +213,7 @@
</span><span class="cx"> 
</span><span class="cx">          // if options aren't set, there's nothing to do, move along
</span><span class="cx">          foreach( array( 'mailserver_url', 'mailserver_login', 'mailserver_pass' ) as $optname ) {
</span><del>-                       if( ! $options[$optname] || $options[$optname] == $this->default_options[$optname] ) {
</del><ins>+                        if( ! $options[$optname] || $options[$optname] == self::$default_options[$optname] ) {
</ins><span class="cx">                           $log_message = __( 'Options not set; skipping.', 'post-by-email' );
</span><span class="cx">                          $this->save_log_message( $log_message );
</span><span class="cx">                          return;
</span><span class="lines">@@ -319,14 +322,13 @@
</span><span class="cx">                  // $log_message .= "\n<p>" . sprintf( __( 'Posted title: %s', 'post-by-email' ), esc_html( $post_title ) ) . '</p>';
</span><span class="cx">                  $log_message .= "<br />" . __( 'Posted:', 'post-by-email') . ' <a href="' . get_permalink( $post_ID ) . '">' . esc_html( $post_title ) . '</a>';
</span><span class="cx"> 
</span><del>-                       $this->save_log_message( $log_message );
-
</del><span class="cx">           } // end foreach
</span><span class="cx"> 
</span><del>-               // delete all processed emails
-               if( ! WP_DEBUG )
-                       $this->delete_messages( $uids );
</del><ins>+                $this->save_log_message( $log_message );
</ins><span class="cx"> 
</span><ins>+               // mark all processed emails as read
+               $this->mark_as_read( $uids, $options['delete_messages'] );
+
</ins><span class="cx">           $this->connection->shutdown();
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -340,21 +342,31 @@
</span><span class="cx">   * @return   object
</span><span class="cx">   */
</span><span class="cx">  protected function open_mailbox_connection( $options ) {
</span><del>-               $pop3 = new Horde_Imap_Client_Socket_Pop3( array( 'username' => $options['mailserver_login'],
-                                                                                                                       'password' => $options['mailserver_pass'],
-                                                                                                                       'hostspec' => $options['mailserver_url'],
-                                                                                                                       'port' => $options['mailserver_port'] ) );
-               $pop3->_setInit( 'authmethod', 'USER' );
</del><ins>+                $connection_options = array( 'username' => $options['mailserver_login'],
+                                                                               'password' => $options['mailserver_pass'],
+                                                                               'hostspec' => $options['mailserver_url'],
+                                                                               'port' => $options['mailserver_port'],
+                                                                               'secure' => $options['ssl'] ? 'ssl' : false
+                                                                       );
</ins><span class="cx"> 
</span><ins>+               if( in_array( $options['mailserver_port'], array( 143, 993 ) ) ) {  // IMAP
+                       $connection = new Horde_Imap_Client_Socket( $connection_options );
+
+               }
+               else {  // POP3
+                       $connection = new Horde_Imap_Client_Socket_Pop3( $connection_options );
+               }
+               $connection->_setInit( 'authmethod', 'USER' );
+
</ins><span class="cx">           try {
</span><del>-                       $pop3->login();
</del><ins>+                        $connection->login();
</ins><span class="cx">           }
</span><span class="cx">          catch( Horde_Imap_Client_Exception $e ) {
</span><span class="cx">                  $this->save_log_message( __( 'An error occurred: ', 'post-by-email') . $e->getMessage() );
</span><span class="cx">                  return false;
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               return $pop3;
</del><ins>+                return $connection;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><span class="lines">@@ -369,11 +381,19 @@
</span><span class="cx">                  return;
</span><span class="cx"> 
</span><span class="cx">          try {
</span><del>-                       $test = $this->connection->search( 'INBOX' );
</del><ins>+                        // POP3 doesn't understand about read/unread messages
+                       if( 'Horde_Imap_Client_Socket_Pop3' == get_class( $this->connection ) ) {
+                               $test = $this->connection->search( 'INBOX' );
+                       }
+                       else {
+                               $search_query = new Horde_Imap_Client_Search_Query();
+                               $search_query->flag( Horde_Imap_Client::FLAG_SEEN, false );
+                               $test = $this->connection->search( 'INBOX', $search_query );
+                       }
</ins><span class="cx">                   $uids = $test['match'];
</span><span class="cx">          }
</span><span class="cx">          catch( Horde_Imap_Client_Exception $e ) {
</span><del>-                       $this->save_log_message( __( 'An error occurred: ', 'post-by-email') . $e->getMessage() );
</del><ins>+                        $this->save_log_message( __( 'An error occurred: ', 'post-by-email' ) . $e->getMessage() );
</ins><span class="cx">                   return false;
</span><span class="cx">          }
</span><span class="cx">          return $uids;
</span><span class="lines">@@ -512,26 +532,31 @@
</span><span class="cx">                  $content = $body->getContents();
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               $content = strip_tags( $content, '<img>' );
</del><ins>+                $content = strip_tags( $content, '<img><p><br><i><b><u><em><strong><strike><font><span><div><style><a>' );
</ins><span class="cx">           $content = trim( $content );
</span><span class="cx"> 
</span><span class="cx">          return $content;
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><del>-        * Delete a list of messages from the server.
</del><ins>+         * Mark a list of messages read on the server.
</ins><span class="cx">    *
</span><span class="cx">   * @since    1.0.0
</span><span class="cx">   *
</span><del>-        * @param    array    UIDs of messages to delete
</del><ins>+         * @param    array    $uids      UIDs of messages that have been processed
+        * @param    bool     $delete    Whether to delete read messages
</ins><span class="cx">    */
</span><del>-       protected function delete_messages( $uids ) {
</del><ins>+        protected function mark_as_read( $uids, $delete=false ) {
</ins><span class="cx">           if( ! $this->connection )
</span><span class="cx">                  return;
</span><span class="cx"> 
</span><ins>+               $flag = Horde_Imap_Client::FLAG_SEEN;
+               if( $delete )
+                       $flag = Horde_Imap_Client::FLAG_DELETED;
+
</ins><span class="cx">           try {
</span><span class="cx">                  $this->connection->store( 'INBOX', array(
</span><del>-                               'add' => array( Horde_Imap_Client::FLAG_DELETED ),
</del><ins>+                                'add' => array( $flag ),
</ins><span class="cx">                           'ids' => $uids
</span><span class="cx">                  ) );
</span><span class="cx">          }
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkincludeHordeStreamTempphp"></a>
<div class="addfile"><h4>Added: 2013/codebykat/post-by-email/trunk/include/Horde/Stream/Temp.php (0 => 2260)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/include/Horde/Stream/Temp.php                         (rev 0)
+++ 2013/codebykat/post-by-email/trunk/include/Horde/Stream/Temp.php    2013-09-06 08:00:28 UTC (rev 2260)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+<?php
+/**
+ * Implementation of Horde_Stream for a PHP temporary stream.
+ *
+ * Copyright 2012-2013 Horde LLC (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.horde.org/licenses/lgpl21.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
+ * @package  Stream
+ */
+class Horde_Stream_Temp extends Horde_Stream
+{
+    /**
+     * Constructor.
+     *
+     * @param array $opts  Additional configuration options:
+     *   - max_memory: (integer) The maximum amount of memory to allocate to
+     *                 the PHP temporary stream.
+     *
+     * @throws Horde_Stream_Exception
+     */
+    public function __construct(array $opts = array())
+    {
+        parent::__construct($opts);
+    }
+
+    /**
+     * @throws Horde_Stream_Exception
+     */
+    protected function _init()
+    {
+        $cmd = 'php://temp';
+        if (isset($opts['max_memory'])) {
+            $cmd .= '/maxmemory:' . intval($opts['max_memory']);
+        }
+
+        if (($this->stream = @fopen($cmd, 'r+')) === false) {
+            throw new Horde_Stream_Exception('Failed to open temporary memory stream.');
+        }
+    }
+
+}
</ins></span></pre></div>
<a id="2013codebykatpostbyemailtrunkincludeHordeStreamphp"></a>
<div class="addfile"><h4>Added: 2013/codebykat/post-by-email/trunk/include/Horde/Stream.php (0 => 2260)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/include/Horde/Stream.php                              (rev 0)
+++ 2013/codebykat/post-by-email/trunk/include/Horde/Stream.php 2013-09-06 08:00:28 UTC (rev 2260)
</span><span class="lines">@@ -0,0 +1,306 @@
</span><ins>+<?php
+/**
+ * Object that adds convenience/utility methods to interacting with PHP
+ * streams.
+ *
+ * Copyright 2012-2013 Horde LLC (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.horde.org/licenses/lgpl21.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
+ * @package  Stream
+ */
+class Horde_Stream implements Serializable
+{
+    /**
+     * Stream resource.
+     *
+     * @var resource
+     */
+    public $stream;
+
+    /**
+     * Configuration parameters.
+     *
+     * @var array
+     */
+    protected $_params;
+
+    /**
+     * Constructor.
+     *
+     * @param array $opts  Configuration options.
+     */
+    public function __construct(array $opts = array())
+    {
+        $this->_params = $opts;
+        $this->_init();
+    }
+
+    /**
+     * Initialization method.
+     */
+    protected function _init()
+    {
+        // Sane default: read-write, 0-length stream.
+        if (!$this->stream) {
+            $this->stream = @fopen('php://temp', 'r+');
+        }
+    }
+
+    /**
+     */
+    public function __clone()
+    {
+        $data = strval($this);
+        $this->stream = null;
+        $this->_init();
+        $this->add($data);
+    }
+
+    /**
+     * @since 1.1.0
+     */
+    public function __toString()
+    {
+        return $this->getString(0);
+    }
+
+    /**
+     * Adds data to the stream.
+     *
+     * @param mixed $data     Data to add to the stream. Can be a resource,
+     *                        Horde_Stream object, or a string(-ish) value.
+     * @param boolean $reset  Reset stream pointer to initial position after
+     *                        adding?
+     */
+    public function add($data, $reset = false)
+    {
+        if ($reset) {
+            $pos = ftell($this->stream);
+        }
+
+        if (is_resource($data)) {
+            $dpos = ftell($data);
+            while (!feof($data)) {
+                fwrite($this->stream, fread($data, 8192));
+            }
+            fseek($data, $dpos);
+        } elseif ($data instanceof Horde_Stream) {
+            $dpos = ftell($data->stream);
+            while (!feof($data->stream)) {
+                fwrite($this->stream, fread($data->stream, 8192));
+            }
+            fseek($data->stream, $dpos);
+        } else {
+            fwrite($this->stream, $data);
+        }
+
+        if ($reset) {
+            fseek($this->stream, $pos);
+        }
+    }
+
+    /**
+     * Returns the length of the data. Does not change the stream position.
+     *
+     * @return integer  Stream size.
+     *
+     * @throws Horde_Stream_Exception
+     */
+    public function length()
+    {
+        $pos = ftell($this->stream);
+
+        if (fseek($this->stream, 0, SEEK_END) == -1) {
+            throw new Horde_Stream_Exception('ERROR');
+        }
+
+        $len = ftell($this->stream);
+
+        if (fseek($this->stream, $pos) == -1) {
+            throw new Horde_Stream_Exception('ERROR');
+        }
+
+        return $len;
+    }
+
+    /**
+     * Stream utility method: get a string up to a certain character (or EOF).
+     *
+     * @oaram string $end  The character to stop reading at.
+     *
+     * @return string  The string up to $end (stream is positioned after the
+     *                 end character(s), all of which are stripped from the
+                       return data).
+     */
+    public function getToChar($end)
+    {
+        $found_end = false;
+        $out = '';
+
+        while (($c = fgetc($this->stream)) !== false) {
+            if ($c == $end) {
+                $found_end = true;
+            } elseif ($found_end) {
+                fseek($this->stream, -1, SEEK_CUR);
+                break;
+            } else {
+                $out .= $c;
+            }
+        }
+
+        return $out;
+    }
+
+    /**
+     * Return the current character without moving the pointer.
+     *
+     * @return string  The current character.
+     */
+    public function peek()
+    {
+        if (($c = fgetc($this->stream)) !== false) {
+            fseek($this->stream, -1, SEEK_CUR);
+        }
+
+        return $c;
+    }
+
+    /**
+     * Search for a character and return its position.
+     *
+     * @param string $char      The character to search for.
+     * @param boolean $reverse  Do a reverse search?
+     * @param boolean $reset    Reset the pointer to the original position?
+     *
+     * @return mixed  The position (integer), or null if character not found.
+     */
+    public function search($char, $reverse = false, $reset = true)
+    {
+        $pos = ftell($this->stream);
+        $found_pos = null;
+
+        if ($reverse) {
+            for ($i = $pos - 1; $i >= 0; --$i) {
+                fseek($this->stream, $i);
+                if (fgetc($this->stream) == $char) {
+                    $found_pos = $i;
+                    break;
+                }
+            }
+        } else {
+            while (($c = fgetc($this->stream)) !== false) {
+                if ($c == $char) {
+                    $found_pos = ftell($this->stream) - 1;
+                    break;
+                }
+            }
+        }
+
+        fseek(
+            $this->stream,
+            $reset || is_null($found_pos) ? $pos : $found_pos
+        );
+
+        return $found_pos;
+    }
+
+    /**
+     * Returns the stream (or a portion of it) as a string.
+     *
+     * @param integer $start  The starting position. If null, starts from the
+     *                        current position. If negative, starts this far
+     *                        back from the current position.
+     * @param integer $end    The ending position. If null, reads the entire
+     *                        stream. If negative, sets ending this far from
+     *                        the end of the stream.
+     *
+     * @return string  A string.
+     */
+    public function getString($start = null, $end = null)
+    {
+        if (!is_null($start) && ($start < 0)) {
+            fseek($this->stream, $start, SEEK_CUR);
+            $start = ftell($this->stream);
+        }
+
+        if (!is_null($end)) {
+            $curr = is_null($start)
+                ? ftell($this->stream)
+                : $start;
+            $end = ($end >= 0)
+                ? $end - $curr + 1
+                : $this->length() - $curr + $end;
+            if ($end < 0) {
+                $end = 0;
+            }
+        }
+
+        return stream_get_contents(
+            $this->stream,
+            is_null($end) ? -1 : $end,
+            is_null($start) ? -1 : $start
+        );
+    }
+
+    /**
+     * Auto-determine the EOL string.
+     *
+     * @since 1.3.0
+     *
+     * @return string  The EOL string, or null if no EOL found.
+     */
+    public function getEOL()
+    {
+        $pos = ftell($this->stream);
+
+        rewind($this->stream);
+        $pos2 = $this->search("\n", false, false);
+        if ($pos2) {
+            fseek($this->stream, -1, SEEK_CUR);
+            $eol = (fgetc($this->stream) == "\r")
+                ? "\r\n"
+                : "\n";
+        } else {
+            $eol = is_null($pos2)
+                ? null
+                : "\n";
+        }
+
+        fseek($this->stream, $pos);
+
+        return $eol;
+    }
+
+    /* Serializable methods. */
+
+    /**
+     */
+    public function serialize()
+    {
+        $this->_params['_pos'] = ftell($this->stream);
+
+        return json_encode(array(
+            strval($this),
+            $this->_params
+        ));
+    }
+
+    /**
+     */
+    public function unserialize($data)
+    {
+        $this->_init();
+
+        $data = json_decode($data, true);
+        $this->add($data[0]);
+        fseek($this->stream, $data[1]['_pos']);
+        unset($data[1]['_pos']);
+        $this->_params = $data[1];
+    }
+
+}
</ins></span></pre></div>
<a id="2013codebykatpostbyemailtrunkreadmetxt"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/readme.txt (2259 => 2260)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/readme.txt    2013-09-06 08:00:25 UTC (rev 2259)
+++ 2013/codebykat/post-by-email/trunk/readme.txt       2013-09-06 08:00:28 UTC (rev 2260)
</span><span class="lines">@@ -42,6 +42,8 @@
</span><span class="cx"> == Changelog ==
</span><span class="cx"> 
</span><span class="cx"> = 1.0.0 =
</span><ins>+* Added SSL and IMAP support.
+* Added option to mark emails "read" instead of deleting them after processing.
</ins><span class="cx"> * Added support for HTML formatted emails.
</span><span class="cx"> * Refactored check_email function.
</span><span class="cx"> * Fixed a bug that caused the log file to behave inconsistently.
</span></span></pre></div>
<a id="2013codebykatpostbyemailtrunkviewsadminphp"></a>
<div class="modfile"><h4>Modified: 2013/codebykat/post-by-email/trunk/views/admin.php (2259 => 2260)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/codebykat/post-by-email/trunk/views/admin.php       2013-09-06 08:00:25 UTC (rev 2259)
+++ 2013/codebykat/post-by-email/trunk/views/admin.php  2013-09-06 08:00:28 UTC (rev 2260)
</span><span class="lines">@@ -38,21 +38,31 @@
</span><span class="cx">                  <tr valign="top">
</span><span class="cx">                          <th scope="row">
</span><span class="cx">                                  <label for="post_by_email_options[mailserver_url]">
</span><del>-                                               <?php _e( 'Mail Server', 'post-by-email' ) ?>
</del><ins>+                                                <?php _e( 'Mail Server', 'post-by-email' ); ?>
</ins><span class="cx">                                   </label>
</span><span class="cx">                          </th>
</span><span class="cx">                          <td>
</span><span class="cx">                                  <input name="post_by_email_options[mailserver_url]" type="text" id="mailserver_url" value="<?php echo esc_attr( $options['mailserver_url'] ); ?>" class="regular-text ltr" />
</span><span class="cx">                                  <label for="post_by_email_options[mailserver_port]">
</span><del>-                                               <?php _e( 'Port', 'post-by-email' ) ?>
</del><ins>+                                                <?php _e( 'Port', 'post-by-email' ); ?>
</ins><span class="cx">                                   </label>
</span><span class="cx">                                  <input name="post_by_email_options[mailserver_port]" type="text" id="mailserver_port" value="<?php echo esc_attr( $options['mailserver_port'] ); ?>" class="small-text" />
</span><span class="cx">                          </td>
</span><span class="cx">                  </tr>
</span><span class="cx">                  <tr valign="top">
</span><span class="cx">                          <th scope="row">
</span><ins>+                                       <label for="post_by_email_options[ssl]">
+                                               <?php _e( 'Always use secure connection (SSL)?', 'post-by-email' ); ?>
+                                       </label>
+                               </th>
+                               <td>
+                                       <input name="post_by_email_options[ssl]" type="checkbox" id="ssl" <?php if( $options['ssl'] ) { echo 'checked="checked"'; } ?> />
+                               </td>
+                       </tr>
+                       <tr valign="top">
+                               <th scope="row">
</ins><span class="cx">                                   <label for="post_by_email_options[mailserver_login]">
</span><del>-                                               <?php _e( 'Login Name', 'post-by-email' ) ?>
</del><ins>+                                                <?php _e( 'Login Name', 'post-by-email' ); ?>
</ins><span class="cx">                                   </label>
</span><span class="cx">                          </th>
</span><span class="cx">                          <td>
</span><span class="lines">@@ -62,7 +72,7 @@
</span><span class="cx">                  <tr valign="top">
</span><span class="cx">                          <th scope="row">
</span><span class="cx">                                  <label for="post_by_email_options[mailserver_pass]">
</span><del>-                                               <?php _e( 'Password', 'post-by-email' ) ?>
</del><ins>+                                                <?php _e( 'Password', 'post-by-email' ); ?>
</ins><span class="cx">                                   </label>
</span><span class="cx">                          </th>
</span><span class="cx">                          <td>
</span><span class="lines">@@ -72,7 +82,7 @@
</span><span class="cx">                  <tr valign="top">
</span><span class="cx">                          <th scope="row">
</span><span class="cx">                                  <label for="post_by_email_options[default_email_category]">
</span><del>-                                               <?php _e( 'Default Mail Category', 'post-by-email' ) ?>
</del><ins>+                                                <?php _e( 'Default Mail Category', 'post-by-email' ); ?>
</ins><span class="cx">                                   </label>
</span><span class="cx">                          </th>
</span><span class="cx">                          <td>
</span><span class="lines">@@ -86,19 +96,29 @@
</span><span class="cx">                                  ?>
</span><span class="cx">                          </td>
</span><span class="cx">                  </tr>
</span><ins>+                       <tr valign="top">
+                               <th scope="row">
+                                       <label for="post_by_email_options[delete_messages]">
+                                               <?php _e( 'Delete messages after posting?', 'post-by-email' ); ?>
+                                       </label>
+                               </th>
+                               <td>
+                                       <input name="post_by_email_options[delete_messages]" type="checkbox" id="delete_messages" <?php if( $options['delete_messages'] ) { echo 'checked="checked"'; } ?> />
+                               </td>
+                       </tr>
</ins><span class="cx">           </table>
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">          <?php submit_button(); ?>
</span><span class="cx">  </form>
</span><span class="cx"> 
</span><del>-       <h3><?php _e( 'Activity Log', 'post-by-email' ) ?></h3>
</del><ins>+        <h3><?php _e( 'Activity Log', 'post-by-email' ); ?></h3>
</ins><span class="cx">   <?php
</span><span class="cx">          $options = get_option( 'post_by_email_options' );
</span><span class="cx">          $log = get_option( 'post_by_email_log' );
</span><span class="cx">  ?>
</span><span class="cx">  <p>
</span><del>-               <?php _e( 'Last checked for new mail:', 'post-by-email' ) ?>
</del><ins>+                <?php _e( 'Last checked for new mail:', 'post-by-email' ); ?>
</ins><span class="cx">           <?php
</span><span class="cx">                  $date_format = get_option( 'date_format' );
</span><span class="cx">                  $time_format = get_option( 'time_format' );
</span><span class="lines">@@ -109,7 +129,7 @@
</span><span class="cx">                  <?php _e( 'Never', 'post-by-email' ); ?>
</span><span class="cx">          <?php endif; ?>
</span><span class="cx">          <br />
</span><del>-               <?php _e( 'Next scheduled check:', 'post-by-email' ) ?>
</del><ins>+                <?php _e( 'Next scheduled check:', 'post-by-email' ); ?>
</ins><span class="cx">           <?php
</span><span class="cx">                  $next = wp_next_scheduled( 'post-by-email-wp-mail.php' );
</span><span class="cx">                  echo get_date_from_gmt( date( 'Y-m-d H:i:s', $next ) , "$date_format, $time_format" );
</span><span class="lines">@@ -117,7 +137,7 @@
</span><span class="cx">  </p>
</span><span class="cx">  <p>
</span><span class="cx">          <a href="<?php echo site_url( 'wp-mail.php' ); ?>" class="button-secondary">
</span><del>-                       <?php _e( 'Check now', 'post-by-email' ) ?>
</del><ins>+                        <?php _e( 'Check now', 'post-by-email' ); ?>
</ins><span class="cx">           </a>
</span><span class="cx">  </p>
</span><span class="cx">  <?php if( $log && sizeof($log) > 0 ) : ?>
</span></span></pre>
</div>
</div>

</body>
</html>