By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,107 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,107 IT Pros & Developers. It's quick & easy.

PHP & IMAP forwarding & attachments

P: n/a

Hi, I'm looking to setup an email system that will log into a catchall
account, read to addresses and forward them to a different email address
stored in a MySQL table. I may also allow the users to store these emails in
their own accounts at a future date.

I've got the IMAP checking etc etc working just fine. However this will be
more troublesome if someone includes an attachment. Firstly, the
imap_body($mbox,$num) chucks out loads of gobbledygook[1] at the moment. I
guess this is the real code behind, but how should I forward that? Also, can
I reject any attachments easily?

Thanks

Nick

[1]
/9j/4AAQSkZJRgABAgEBLAEsAAD/7QlMUGhvdG9zaG9wIDMuMAA4QklNA+0KUmVzb2x1dGlvbgAA

AAAQASwAAAABAAEBLAAAAAEAAThCSU0EDRhGWCBHbG9iYWwgTG lnaHRpbmcgQW5nbGUAAAAABAAA

AHg4QklNBBkSRlggR2xvYmFsIEFsdGl0dWRlAAAAAAQAAAAeOE JJTQPzC1ByaW50IEZsYWdzAAAA

CQAAAAAAAAAAAQA4QklNBAoOQ29weXJpZ2h0IEZsYWcAAAAAAQ AAOEJJTScQFEphcGFuZXNlIFBy

aW50IEZsYWdzAAAAAAoAAQAAAAAAAAACOEJJTQP1F0NvbG9yIE hhbGZ0b25lIFNldHRpbmdzAAAA

SAAvZmYAAQBsZmYABgAAAAAAAQAvZmYAAQChmZoABgAAAAAAAQ AyAAAAAQBaAAAABgAAAAAAAQA1

AAAAAQAtAAAABgAAAAAAAThCSU0D+BdDb2xvciBUcmFuc2Zlci BTZXR0aW5ncwAAAHAAAP//

AAAAAQAtAAAABgAAAAAAAThCSU0D+////
Aug 31 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
elyob wrote:
I've got the IMAP checking etc etc working just fine. However this
will be more troublesome if someone includes an attachment. Firstly,
the imap_body($mbox,$num) chucks out loads of gobbledygook[1] at the
moment. I guess this is the real code behind, but how should I
forward that?
You should forward it as is, because it's base64 encoded binary data.
Also, can I reject any attachments easily?


You can analyse each part of the message with the imap_fetchstructure
function, after which it's just a matter of selecting the part you want to
use in the forwarded message with the imap_fetchbody function.
JW


Aug 31 '05 #2

P: n/a

"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:43**********************@news.euronet.nl...
elyob wrote:
I've got the IMAP checking etc etc working just fine. However this
will be more troublesome if someone includes an attachment. Firstly,
the imap_body($mbox,$num) chucks out loads of gobbledygook[1] at the
moment. I guess this is the real code behind, but how should I
forward that?


You should forward it as is, because it's base64 encoded binary data.


Out of interest, what method would you use to forward it? I would like it to
look like it has come from the originator and not showing as forwarded. I
was doing this ..

$body = imap_body($mbox,$i);
imap_mail($toaddress, $subject, $body, 'From: in**@example.com');

.... which doesn't work.

Thanks
Sep 1 '05 #3

P: n/a
elyob wrote:
Out of interest, what method would you use to forward it? I would
like it to look like it has come from the originator and not showing
as forwarded. I was doing this ..

$body = imap_body($mbox,$i);
imap_mail($toaddress, $subject, $body, 'From: in**@example.com');

... which doesn't work.


What you really want is to bounce the message rather then forwarding it.

For this, the function is correct but the header isn't. Use headers like the
following:

$headers = "ReSent-Date: " . strftime("%b %d %Y %H:%M:%S") . "\r\n";
$headers .= "Resent-From: <your email address>\r\n";
$headers .= "Resent-To: <recepient email>\r\n";
$headers .= "ReSent-Subject: <original subject>";

Tip: Look at the source of the IMP package from the Horde project
(http://www.horde.org/) to see how they took care of this.
JW

Sep 1 '05 #4

P: n/a

"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:43**********************@news.euronet.nl...
elyob wrote:
Out of interest, what method would you use to forward it? I would
like it to look like it has come from the originator and not showing
as forwarded. I was doing this ..

$body = imap_body($mbox,$i);
imap_mail($toaddress, $subject, $body, 'From: in**@example.com');

... which doesn't work.


What you really want is to bounce the message rather then forwarding it.

For this, the function is correct but the header isn't. Use headers like
the following:

$headers = "ReSent-Date: " . strftime("%b %d %Y %H:%M:%S") . "\r\n";
$headers .= "Resent-From: <your email address>\r\n";
$headers .= "Resent-To: <recepient email>\r\n";
$headers .= "ReSent-Subject: <original subject>";

Tip: Look at the source of the IMP package from the Horde project
(http://www.horde.org/) to see how they took care of this.


Thanks, that's a very lateral thinking way of doing it. I like it! I'll play
with it next week.

Many thanks, again!

Nick
Sep 2 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.