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
117 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now