Hot Koehls
  • Email
  • Feedburner
  • Linkedin
  • Twitter
  • Home
  • About
  • Archives
  • Contact
  • Software
    • S3imple Backup
    • Twitter Feed Archiver
    • FileTime
    • Flickr API Demo
Search
Home» For techies » Get number of message parts in an email using PHP

Get number of message parts in an email using PHP

Posted by Frank - November 14, 2008 - For techies
1

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 “part” 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’ll help flesh it out once this project is done.

Anyway, you can ascertain the total number of parts using the results from the function imap_fetchstructure(). 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’s data. So, this simple call is all you need…

$structure = imap_fetchstructure($mbox, $message_num);
$total_parts = sizeof($structure->parts);
email, php, software development

One comment on “Get number of message parts in an email using PHP”

  1. IanArcher says:
    April 6, 2012 at 4:01 pm

    Thanks alot! This really helped me save the headache of an overflow of coding. Very simple!

Cancel Reply

Categories

  • For entrepreneurs
  • For everyone
  • For techies

Latest Tweets

  • The PA Report - LucasArts' eulogy reminds us of the inhuman cost of game development http://t.co/vVjHkmr9YD
    April 9, 2013 - 2:46 pm
  • Pictures from a developer's life http://t.co/s75fBPTu4v
    April 5, 2013 - 11:44 am
  • Chuck+Norris http://t.co/awBqZ8gncS
    March 7, 2013 - 10:46 pm
  • Google Hacks http://t.co/ZIU2CHcoem
    March 3, 2013 - 1:08 am

Recent Comments

  • Rohitash on Automating SSH or SFTP in scripts
  • kgiFozzkjk on MySQL founder Michael Widenius concerned about sale to Oracle
  • purusjap on Jeff Atwood still wrong about PHP
  • OTHER FUNCTION on Get HTTP status code of cURL call in PHP
  • CounterSpace on Change timezone to GMT in Debian

Recent Posts

  • Display line numbers in WebSVN file detail view
  • It’s dangerous to go alone
  • Create Self-Signed Wildcard SSL Certificate
  • What comes after the yottabyte?
  • Write code like they do in Hollywood
(c) 2012 Frank Koehl. All Rights Reserved.
  • Contact Us
  • Sitemap