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
131 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 110

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 110

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 110

Expert Comment

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

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

707 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