PHP Classes
elePHPant
Icontem

Great example, need a little help

Recommend this page to a friend!

      POP3 e-mail client  >  POP3 e-mail client package blog  >  How Can PHP Read Emai...  >  All threads  >  Great example, need a little help  >  (Un) Subscribe thread alerts  
Subject:Great example, need a little help
Summary:how can i rename the attachments based on email headers?
Messages:4
Author:Drew Riley
Date:2014-05-16 15:29:00
Update:2014-05-17 18:06:53
 

  1. Great example, need a little help   Reply   Report abuse  
Drew Riley - 2014-05-16 15:29:00
So let's start with saying i'm a php novice.

But i'm looking though the code and it looks like it process the "save attachments" before it processes the headers.

What I'm hoping to accomplish is to name the attachments dynamically based on the email subject

The point is to be able to refer later to the attachment from a script.

So say the subject of the email was "test123" and the attachment was "photo.jpg", I need the attachment saved to be named test123.photo.jpg

I am just too amateur to get it working, although I tried for a good 3 hours or so.

Could I entice you to write a wrapper script that I could run that would open a mail box, save the attachments based on the email subjects?



  2. Re: Great example, need a little help   Reply   Report abuse  
Manuel Lemos - 2014-05-16 20:06:13 - In reply to message 1 from Drew Riley
You can use the MIME parser class to decode messages and save attachments to wherever you want using the SaveBody parameter.

If you need to preserve the original attachment file names, you can set the use_part_file_names class variable to true.

  3. Re: Great example, need a little help   Reply   Report abuse  
Drew Riley - 2014-05-16 20:19:19 - In reply to message 2 from Manuel Lemos
Hi Thanks for your reply. Yes I have this already doing that.

The attachments are being saved to my folder as the original names.
But I want to change the name of them to the subject line of the email.

example;

email: subject "test" attachment "photo.jpg"

> save attachment as "test.photo.jpg"

  4. Re: Great example, need a little help   Reply   Report abuse  
Manuel Lemos - 2014-05-17 18:06:53 - In reply to message 3 from Drew Riley
That is a very specific customization. Although you could override the GetPartFileName function in an eventual sub-class, that was not really the purpose of redefining the name of message parts.

What I suggest that you add some post-processing code to traverse the list of message parts and implement whatever is your custom part renaming logic.