?
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
Medium Priority
?
135 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
[X]
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
  • 3
  • 2
5 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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 111

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

801 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