PDA

View Full Version : IMAP body formatting


LuiePL
02-08-2007, 11:25 AM
I'm developing a web based email application for my website, and right now I'm working on getting on the "read" portion up and working. I would like it to only display the actual text of the message that was typed. It also repeats the message. Below is an example of it.





--0-70050447-1167043329=:89022
Content-Type: text/plain; charset=iso-8859-7
Content-Transfer-Encoding: quoted-printable

Yes I do agree Merry Christmas to all members. Have a safe and Health New Y=
ear.=0A =0AHoward Roun Jr.=0ASenior Dispatcher Southern New Jersey=0ANJ801=
=0AEast Coast Radio NJ801=0A=0A=0A=0A----- Original Message ----=0AFrom: EC=
RN Operations =0ATo: [email]=0ASe=
nt: Monday, December 25, 2006 12:37:33 AM=0ASubject: Merry Christmas=0A=0A=
=0AOn behalf of the Administration of East Coast / 1st Responder Radio we=
=A2d like to wish all our members a Safe and Merry Christmas to you and you=
r families along with a Happy and Healthy New Year!=0A =0AAdministration / =
Operations=0AEast Coast Radio Network - Philadelphia=0AA Division of the 1s=
t Responder Radio Network=0A"We're in Command"=0A[email]=
m=0A =0Ahttp://www.eastcoast911.com=0Ahttp://www.1stResponder.com=0A=0A____=
______________________________________________=0ADo You Yahoo!?=0ATired of =
spam? Yahoo! Mail has the best spam protection around =0Ahttp://mail.yahoo=
.com
--0-70050447-1167043329=:89022
Content-Type: text/html; charset=iso-8859-7
Content-Transfer-Encoding: quoted-printable

=0AYes I do agree Merry Christmas to all me=
mbers. Have a safe and Health New Year. =0AHoward Roun Jr.=0ASenior Di=
spatcher Southern New Jersey=0ANJ801=0AEast Coast Radio=
NJ801=0A=0A----- Origina=
l Message ----From: ECRN Operations <[email]>=
To: [email]Sent: Monday, December 25, 2006 12:37:33 AM=
Subject: Merry Christmas=0A=0A=0A=0A=0A=0AOn behalf of the Admin=
istration of East Coast / 1st Responder Radio we=A2d like to wis=
h all our members a Safe and Merry Christmas to you and your families along=
with a Happy and Healthy New Year!=0A =0A=0AAdmini=
stration / Operations=0AEast=
Coast Radio Network - Philadelphia=0AA Division of the 1st=
Responder Radio Network=0A"We're in Command"=0AOperationsateastcoast911.com=0A=
&nb=
sp;=0Ahttp://www.eastcoast911.com=0Ahttp://www.1stR=
esponder.com =0A =
________________________________=
__________________Do You Yahoo!?Tired of spam? Yahoo! Mail has the=
best spam protection around http://mail.yahoo.com
--0-70050447-1167043329=:89022--

chump2877
02-08-2007, 03:07 PM
Here is a function that I used once upon a time to do just that -- return the text of a given message...$mbox is the IMAP resource stream and $id is the message number:

// Get mail message content function

function getMessageContent($mbox,$id)
{

// Get content of text message.

$mid = $id;

$struct = imap_fetchstructure($mbox,$mid);

$parts = $struct->parts;
$i = 0;

if (!$parts)
{
/* Simple message, only 1 piece */
$attachment = array(); /* No attachments */
$content = imap_body($mbox, $mid);
}
else
{
/* Complicated message, multiple parts */

$endwhile = false;

$stack = array(); /* Stack while parsing message */
$content = ""; /* Content of message */
$attachment = array(); /* Attachments */

while (!$endwhile)
{
if (!$parts[$i])
{
if (count($stack) > 0)
{
$parts = $stack[count($stack)-1]["p"];
$i = $stack[count($stack)-1]["i"] + 1;
array_pop($stack);
}
else
{
$endwhile = true;
}
}

if (!$endwhile)
{
/* Create message part first (example '1.2.3') */
$partstring = "";
foreach ($stack as $s)
{
$partstring .= ($s["i"]+1) . ".";
}
$partstring .= ($i+1);

if (strtoupper($parts[$i]->disposition) == "ATTACHMENT") { /* Attachment */
$attachment[] = array("filename" => $parts[$i]->parameters[0]->value,
"filedata" => imap_fetchbody($mbox, $mid, $partstring));
}
elseif (strtoupper($parts[$i]->subtype) == "PLAIN")
{ /* Message */
$content .= imap_fetchbody($mbox, $mid, $partstring);
}
}

if ($parts[$i]->parts)
{
$stack[] = array("p" => $parts, "i" => $i);
$parts = $parts[$i]->parts;
$i = 0;
}
else
{
$i++;
}
} /* while */
} /* complicated message */

// Convert quoted-printable characters in text content

$Body_text = quoted_printable_decode($content);
return $Body_text;

}

LuiePL
02-08-2007, 03:36 PM
Ok, I threw that code in and it did a pretty good job. I just have to figure out a way for it to format it so its a little more aesthetically pleasing. See below:

Hi Luie, I'd be happy to help you with your license application. The attached form covers the information I would need. Fees for a repeater with mobiles and control stations with antennas under 20' would be: $175 to MRFAC for frequency coordination $160 to FCC for 10 year license fee $100 to Badger Towers for application preparation and filing Thanks, Carl -----Original Message----- From: Luie Lugo Sent: Monday, October 16, 2006 4:29 PM To: Subject: Frequency Licensing My group is interested in licensing 451.9000 in Philadelphia. We have used this frequency in that past, however we have not renewed the frequency, and need to license it. Luie PA370 - Webmaster East Coast Radio Network - Philadelphia A Division of the 1st Responder Radio Network "We're in Command"

chump2877
02-08-2007, 03:47 PM
$message = nl2br(getMessageContent($mbox,$id));
echo $message;

LuiePL
02-09-2007, 05:24 AM
I should have remebered that, I just had a brain fart. Thanks again for your help.