<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hot Koehl &#187; email</title>
	<atom:link href="http://frankkoehl.com/tag/email/feed/" rel="self" type="application/rss+xml" />
	<link>http://frankkoehl.com</link>
	<description>The more you know, the more you don't know</description>
	<lastBuildDate>Mon, 16 Jan 2012 22:52:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Fwd:Vault now open to the public</title>
		<link>http://frankkoehl.com/2009/07/fwdvault-open-to-public/</link>
		<comments>http://frankkoehl.com/2009/07/fwdvault-open-to-public/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 15:49:13 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[For entrepreneurs]]></category>
		<category><![CDATA[For everyone]]></category>
		<category><![CDATA[For techies]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[fwdvault]]></category>
		<category><![CDATA[startups]]></category>

		<guid isPermaLink="false">http://frankkoehl.com/?p=685</guid>
		<description><![CDATA[After eight months of development, Fwd:Vault &#8212; the secure data backup service that operates entirely through email &#8212; is ready and waiting for you. This is a free beta release, so anyone can sign up and use the service totally free of charge. Hit the site to get started: http://fwdvault.com If the description &#8220;Secure data [...]]]></description>
			<content:encoded><![CDATA[<p>After eight months of development, Fwd:Vault &mdash; the secure data backup service that operates entirely through email &mdash; is ready and waiting for you.</p>
<p>This is a free beta release, so anyone can sign up and use the service totally free of charge. Hit the site to get started:</p>
<p><a href="http://fwdvault.com">http://fwdvault.com</a></p>
<p>If the description &#8220;Secure data backups through email&#8221; isn&#8217;t obvious enough, you&#8217;ll find more information on the <a href="https://fwdvault.com/about">About page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://frankkoehl.com/2009/07/fwdvault-open-to-public/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extract email addresses from tags</title>
		<link>http://frankkoehl.com/2009/01/extract-email-addresses-from-tags/</link>
		<comments>http://frankkoehl.com/2009/01/extract-email-addresses-from-tags/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 22:26:15 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[For techies]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[fwdvault]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://frankkoehl.com/?p=309</guid>
		<description><![CDATA[Ran into another cool hurdle today for my Fwd:Vault development. When I grab the message content to archive it in the system, first thing I do is scrub it out to ensure that (a) it displays properly, and (b) there are no misbehaving characters. I grab both plain text and HTML email formats (if present), [...]]]></description>
			<content:encoded><![CDATA[<p>Ran into another cool hurdle today for my <a href="http://fwdvault.com">Fwd:Vault</a> development. When I grab the message content to archive it in the system, first thing I do is scrub it out to ensure that (a) it displays properly, and (b) there are no misbehaving characters. I grab both plain text and HTML email formats (if present), so the scrubbing process is a little different in each case. For the plain text, I take some extra steps to ensure there is no HTML whatsoever. Naturally, at one point this involves a call to PHP&#8217;s ultra-useful <code><a href="http://www.php.net/strip_tags">strip_tags()</a></code> function.</p>
<p>However, in the course of testing today, I realized that when a message is forwarded, sometimes the forward header will encode the email address, which gets stripped when I process the message. Allow me to demonstrate. Here&#8217;s the body an example message that someone might send to Fwd:Vault for safe keeping&#8230;</p>
<pre>---------- Forwarded message ----------
From: "Office Flirt" &lt;flirt@example.com&gt;
Date: Wed, Jan 14, 2009 at 10:14 AM
Subject: Delete those images
To: you@example.com

My boss is sniffing around. I want you to delete those pictures I sent you right away.

Signed,
Office Flirt</pre>
<p>Obviously you&#8217;re tucking this one away in Fwd:Vault to provide a little CYA-insurance when the boss calls you into his office. Good call. Now, before today, this message would come out of the scrubbing process looking like this:</p>
<pre>---------- Forwarded message ----------
<span style="color: #ff0000;"><strong>From: Office Flirt</strong></span>
Date: Wed, Jan 14, 2009 at 10:14 AM
Subject:
To: you@example.com
...</pre>
<p>Look at the bolded red line. The email address is gone. You don&#8217;t have any other copies of it, so your boss doesn&#8217;t believe your story, and you get the blame. You&#8217;re forced to attend one of those god-awful sexual harassment classes. Fail.</p>
<p>So, what happened? Remember, you are looking at the <strong>body</strong> of a message in <strong>plain text</strong>. That &#8220;Forwarded message&#8221; block at the beginning is just part of the body text. So when the text was scrubbed by <code>strip_tags()</code>, the function picked it up as just another tag, which it dutifully removed.</p>
<p>To handle this situation, I came up with a piece of code that will look for email addresses in &#8220;tagged format&#8221; — i.e. surrounded by &lt; and &gt; — and remove the surrounding symbols, leaving us with harmless text.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'some surrounding text'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;/(\&lt;)(.+@[^\(\);:,&lt;&gt;]+\.[a-zA-Z]{2,4})(\&gt;)/&quot;</span><span style="color: #339933;">,</span>
                      <span style="color: #0000ff;">' $2 '</span><span style="color: #339933;">,</span>
                      <span style="color: #000088;">$test</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[\s]+/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$test</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$test</span><span style="color: #339933;">;</span></pre></div></div>

<p>Let&#8217;s break this down. First, we have a regular expression that identifies email addresses: <code>.+@[^\(\);:,&lt;&gt;]+\.[a-zA-Z]{2,4}</code>. This is the same expression set in the example on the <a href="http://www.quanetic.com/Regex">Quanetic Software Regular Expression Tester</a> (an excellent tool). We surround that in parentheses to isolate it as a <strong>subpattern</strong>. Then on either end of the expression, we tack on more regex voodoo to look for tag syntax: <code>(\&lt;)</code> and <code>(\&gt;)</code>. These also get parentheses to identify them as subpatterns. Once its finished, we have an expression that will only match addresses wrapped in tagging structure.</p>
<p>The second argument in <code>preg_replace()</code> is the replacement, or what we should replace any matches with. In this case, we&#8217;ve isolated the address from the tags using subpatterns. So all we need to do is make a single call to the proper reference, which is <code>$2</code>, because its the second set of parentheses in the expression. Confused? You can learn about subpatterns on the PHP manual page for <a href="http://www.php.net/manual/en/function.preg-replace.php"><code>preg_replace()</code></a>.</p>
<p>Note the spaces around the <code>$2</code> in the second argument. Sometimes the address will not have any spaces between the person&#8217;s name and the actual address. This could lead to the address being combined with the name which, in the case of Fwd:Vault, would screw up our search indexing. So we add spaces during the replace, then make a second call to <code>preg_replace()</code> to eliminate extra spaces: <code>$test = preg_replace('/[\s]+/', '', $test);</code>.</p>
<p><strong>Legal Disclaimer:</strong> In case you do end up using Fwd:Vault when it launches, I&#8217;m fairly certain the service wouldn&#8217;t be liable in this silly hypothetical. Just make sure you read the terms before you sign up if you play the field at your office. Sorry to everyone going &#8220;duh&#8221; right now; it&#8217;s a sue-happy world.</p>
<p><strong>Update:</strong> When I went to implement this change today, I discovered that the code was catching newlines (\n or \r) in the crossfire. It was actually due to the second call to <code>preg_replace()</code>, the &#8220;\s&#8221; character class includes not only spaces but line terminators as well. Oops. The revised version looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$body_text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[ ]{2,}/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body_text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://frankkoehl.com/2009/01/extract-email-addresses-from-tags/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get number of message parts in an email using PHP</title>
		<link>http://frankkoehl.com/2008/11/get-number-of-message-parts-in-an-email-using-php/</link>
		<comments>http://frankkoehl.com/2008/11/get-number-of-message-parts-in-an-email-using-php/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 17:49:54 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[For techies]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://frankkoehl.com/?p=137</guid>
		<description><![CDATA[Alright, I admit up front that this is a pretty specific problem, but hopefully some Googlers will find it useful. I recently had need for a small side project to read e-mails. Every e-mail is split up into parts; each &#8220;part&#8221; represents every separate piece of the e-mail. The plain text format, rich text or [...]]]></description>
			<content:encoded><![CDATA[<p>Alright, I admit up front that this is a pretty specific problem, but hopefully some Googlers will find it useful.</p>
<p>I recently had need for a small side project to read e-mails. Every e-mail is split up into parts; each &#8220;part&#8221; represents every separate piece of the e-mail. The plain text format, rich text or HTML formats, and attachments are all sent as parts. Problem is that there is no obvious way to quickly decipher just how many parts you have in a message. The documentation for the imap functions in PHP is also woefully inadequate. Maybe I&#8217;ll help flesh it out once this project is done.</p>
<p>Anyway, you can ascertain the total number of parts using the results from the function <a href="http://us.php.net/manual/en/function.imap-fetchstructure.php">imap_fetchstructure()</a>. The parts array in the returned object contains ALL the parts of the message, including the top level used to construct the rest of the object&#8217;s data. So, this simple call is all you need&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$structure</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imap_fetchstructure</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mbox</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message_num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$total_parts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$structure</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://frankkoehl.com/2008/11/get-number-of-message-parts-in-an-email-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World, now where&#8217;s my e-mail?</title>
		<link>http://frankkoehl.com/2008/03/world-email/</link>
		<comments>http://frankkoehl.com/2008/03/world-email/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 14:46:35 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[For entrepreneurs]]></category>
		<category><![CDATA[For everyone]]></category>
		<category><![CDATA[For techies]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://frankkoehl.com/2008/03/14/world-email/</guid>
		<description><![CDATA[Having just spent several hours doing some basic setup on a new WordPress blog, I can safely agree with the masses that it is indeed an excellent, well-written program. Even the most tech-inept amongst us would likely have no problem getting the software up and running. Which is probably why I had a problem, and [...]]]></description>
			<content:encoded><![CDATA[<p>Having just spent several hours doing some basic setup on a new WordPress blog, I can safely agree with the masses that it is indeed an excellent, well-written program.  Even the most tech-inept amongst us would likely have no problem getting the software up and running.</p>
<p>Which is probably why <em>I</em> had a problem, and it had me initially cursing the name of WordPress.</p>
<p>My e-mail server sits on a different box, which means that I need to configure the e-mail functionality of my site to access this server via <a href="http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol">SMTP</a>.  I&#8217;ve set up countless PHP-based CMS&#8217;s—I <a href="http://www.zen-cart.com">contribute to one</a>, and I&#8217;m in charge of <a href="http://www.classicwines.com">custom-building another</a>—so I know the first thing you always do is consult the manual, both the official one and Google.  Of course, as you can see in <a href="http://www.google.com/search?q=wordpress+configure+email">these search results</a>, I come up with absolutely nada.  There is seemingly nothing in WP documentation about natively configuring the e-mail functions to use a mail server outside of the local box.</p>
<p>Further searching does reveal a <a href="http://mu.wordpress.org/forums/topic.php?id=5443&amp;page">hack up solution</a>, which would suffice since I am pretty well-versed in PHPMailer.  I also came across <a href="http://wordpress.org/extend/plugins/wp-phpmailer/#post-365">two</a> decent <a href="http://wordpress.org/extend/plugins/wp-mail-smtp/#post-2302">plugins</a>; ultimately I decided to go with <strong>WP Mail SMTP</strong>, as it&#8217;s functionality seemed to fit my needs.  The plug-n-play style of the plugins system also made this a far better solution than hacking at the core code.</p>
<p>Which brings me to the reason I&#8217;m explaining all of this: <strong>simple SMTP e-mail configuration should be required in every CMS or CMS-style framework that sends e-mail</strong>, and that&#8217;s pretty much all of them.  Why should users have to traipse across the net looking for a solution to a very common situation? Most hosting packages physically split their hosting and mail services for a menagerie of security and performance reasons.</p>
<p>I&#8217;m betting that a lot of WP users have found themselves in the same boat I did, and handled the issue with a plugin or two. But how many users even realized that what they lacked was SMTP configuration options, and instead simply knew that &#8220;I can&#8217;t send e-mail?&#8221;  At the very least, WP documentation ought to explicitly lay out the e-mail setup, and point users to the available plugin solutions.</p>
<p>In the end, the plugin functionality came through, and honestly did impress me overall.  Plus, during the turmoil, I learned about another great WordPress feature, <a href="http://wordpress.org/extend/kvetch/">the kvetch</a>&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://frankkoehl.com/2008/03/world-email/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

