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
121 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 108

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 108

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 108

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now