Email Code

  Home arrow Email Code arrow Search Mime Email Structure
EMAIL CODE

Search Mime Email Structure
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2005-01-03

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    A function that searches a mime email structure for certain arguments passed in a sql type syntax and returns an array of the part numbers that fulfilled all the arguments. Useful for finding the body text of emails. See the extended description for details.

    By : ethilien

    imap_searchstruct

    imap_searchstruct -- Search the structure of a mime email message for a query string and return an array of the mime-parts that match all the criteria.

    Description
    array imap_searchstruct ( array struct, string query )

    This will search the structure of a mail message as returned by the function imap_fetchstructure, and return an array of the parts that match all the query arguments. The returned array of parts are intended for use in imap_fetchbody function.

    Example 1. imap_searchstruct() example
    <?php
    // Include the imap_fetchstruct.php file to add support for the function.
    include (imap_searchstruct.php);

    // Set up the server vars
    $server = "mail.example.com";
    $user = "example@example.com";
    $password = "password";

    // Initialize the mailserver connection.
    $mserver = imap_open ("{" . $server . ":110/pop3}INBOX", $user, $password);
    $nmsgs = imap_num_msg ($mserver);
    for ($i = 1; $i <= $nmsgs; $i++)
    {
    // Fetch the structure for each message.
    $struct = imap_fetchstructure ($mserver, $i);

    // Perform the search. This query will return all the body text of an email.
    $parts = imap_searchstruct ($struct, "type = '0' & subtype = 'plain' & disposition != 'attachment'");

    // Fetch and echo the content of the first mime-part in the $parts array.
    $body = imap_fetchbody ($mserver, $i, $parts[0]);
    echo ($body);
    }

    // Cloes the mailserver connection.
    imap_close ($mserver);
    ?>

    Click to Download File



    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Email Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    EMAIL CODE ARTICLES

    - Basic Ajax contact form
    - Random validation image
    - tinySendMail
    - SaferMail 0.7
    - Smtp Auth Email Script
    - Search Mime Email Structure
    - PHP Text / HTML Email with Attachments 2.1
    - Simple way to send mail wih one attached Doc...
    - Generic POP3 Class
    - PHP Text / HTML Email with Unlimited Attachm...
    - Another SendMail
    - email with attachment
    - Get Email Addresses from Strings
    - EmailCode
    - Email Validation - Gone Wild

    Developer Shed Affiliates

     



    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap