Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How can I change the amount of characters returned for the subject of a message using imap_headers?

Posted on 2014-09-18
5
125 Views
Last Modified: 2014-09-19
I am using imap_headers in a php script as follows:

$headers = imap_headers($mail);
I am then looping through the header of each message using:

for ($n=1; $n<=count($headers); $n++)
      {
}

This is only returning a certain amount of characters from the header, and thus the subject is cut short.
I want to return the full subject for each message.

I understand there is a parameter "subject_length" that can be used in conjunction with imap_headers, but I dont know how to implement it.

can someone help?
0
Comment
Question by:davids355
  • 3
  • 2
5 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40330212
There is no parameter "subject_length" for imap_headers().  According to this user-contributed note: This function will not return a full subject line if it is longer than 25 characters.

So we will need another function, and may have to address the messages one-at-a-time.  This link appears to be useful:
http://www.php.net/manual/en/ref.imap.php#54098

I do not have any test data that I can use, so these are just suggestions based on reading the man pages.
http://www.php.net/manual/en/function.imap-fetch-overview.php and access the "subject" property
http://www.php.net/manual/en/function.imap-fetchheader.php and parse the header
http://www.php.net/manual/en/function.imap-headerinfo.php and access the "subject" property
http://www.php.net/manual/en/function.imap-rfc822-parse-headers.php and examine the object
0
 

Author Closing Comment

by:davids355
ID: 40330735
worked like a charm.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40330915
Thanks for the points.  Just curious - which function did you choose?
0
 

Author Comment

by:davids355
ID: 40332226
I followed this link:

http://www.php.net/manual/en/function.imap-fetch-overview.php

And this is the code I used, basically:

$mbox = imap_open("{imap.example.org:143}INBOX", "username", "password")
     or die("can't connect: " . imap_last_error());

$MC = imap_check($mbox);

// Fetch an overview for all messages in INBOX
$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
foreach ($result as $overview) {
    echo $overview->subject}.'<br>';
}
imap_close($mbox);

Quite handy really because my intention anyway was pretty much to spill out the subject lines one by one, and then also with another loop check for the existence of a particular string within each subject line.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40332326
Excellent, thanks for sharing your experience!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question