title: Proper way to decode incoming email subject (utf 8)
body: <p>I'm trying to pipe my incoming mails to a PHP script so I can store them in a database and other things. I'm using the class <a href="http://www.phpclasses.org/browse/package/3169/download/zip.html" rel="noreferrer"><em>MIME E-mail message parser</em> (registration required)</a> although I don't think that's important.</p>
  
  <p>I have a problem with email subjects. It works fine when the title is in English but if the subject uses non-latin Characters I get something like</p>
  
  <pre><code>=?UTF-8?B?2KLYstmF2KfbjNi0?=
  </code></pre>
  
  <p>for a title like 
  یک دو سه </p>
  
  <p>I decode the subject like this:</p>
  
  <pre><code>  $subject  = str_replace('=?UTF-8?B?' , '' , $subject);
    $subject  = str_replace('?=' , '' , $subject);      
    $subject = base64_decode($subject); 
  </code></pre>
  
  <p>It works fine with short subjects with like 10-15 characters but with a longer title I get half of the original title with something like ��� at the end.</p>
  
  <p>If the title is even longer, like 30 characters, I get nothing. Am I doing this right?</p>