MarthaJ Sayers
asked on
PHP and IMAP
I have a question. I am extracting data from email messages using PHP v 5.6.25 using imap.
I know I can extract the header information to determine the content type - i.e.
Content-Type: text/html or Content-Type: text/html.
But I am a bit confused on a point here. Does it return the content-type for each email ??
I know from the PHP manual that it uses the url, but this is for a specific
email address i.e. mymail@what.com.
Can you use the specific email address of the sender for the url ??
The data is contained within a table - it may or may not have html styles i.e. font-size etc. but in both cases within a table. The table structures are a bit different so I need to determine which is which for extracting the data.
Would the
The reason I am asking is the messages can be of two flavors -
1) Message has styling inbedded in table
2) Message does not have styling inbedded in table
ANy help would be appericiated...thank you
I know I can extract the header information to determine the content type - i.e.
Content-Type: text/html or Content-Type: text/html.
But I am a bit confused on a point here. Does it return the content-type for each email ??
I know from the PHP manual that it uses the url, but this is for a specific
email address i.e. mymail@what.com.
Can you use the specific email address of the sender for the url ??
The data is contained within a table - it may or may not have html styles i.e. font-size etc. but in both cases within a table. The table structures are a bit different so I need to determine which is which for extracting the data.
Would the
The reason I am asking is the messages can be of two flavors -
1) Message has styling inbedded in table
2) Message does not have styling inbedded in table
ANy help would be appericiated...thank you
1) But I am a bit confused on a point here. Does it return the content-type for each email ??
Each email containing MIME parts will contain at least one Content-Type header.
Simple text messages may or may not.
2) Tip: Best to use a MIME Parser to parse all your messages. MIME Parsers are indispensable, as there are some many types of MIME messages. Far better to use an exiting MIME Parser, than try to write your own.
MIME Parsers automagickally handle your 2x additional questions.
Each email containing MIME parts will contain at least one Content-Type header.
Simple text messages may or may not.
2) Tip: Best to use a MIME Parser to parse all your messages. MIME Parsers are indispensable, as there are some many types of MIME messages. Far better to use an exiting MIME Parser, than try to write your own.
MIME Parsers automagickally handle your 2x additional questions.
ASKER
David and Scott - thank you both for responding - you both have helped very much and I appericiate it too.
I don't have alot of exprience with this but gaining everyday. I don't have alot of experience with emails but gaining experience everyday.
David -
Your input helped to clarify somethings I wondered about. I am going to research a MIME Parsers - never thought there being one. Thank you. And for the tip.
Scott -
Oh yes, I can get the message body in both cases. I have two function to strip out data.
One without and one with. I just thought there might be a simplier way and am still curcious
about the use of the individuals email address etc.
I don't have alot of exprience with this but gaining everyday. I don't have alot of experience with emails but gaining experience everyday.
David -
Your input helped to clarify somethings I wondered about. I am going to research a MIME Parsers - never thought there being one. Thank you. And for the tip.
Scott -
Oh yes, I can get the message body in both cases. I have two function to strip out data.
One without and one with. I just thought there might be a simplier way and am still curcious
about the use of the individuals email address etc.
David, how does a mime parser distinguish between html with inline styles or html without inline styles?
If that is the case, are you able to create a function to look for "td style=" to find separate what you need?
If so, can you post some small samples of code to work with?
If so, can you post some small samples of code to work with?
ASKER
Scott - Oh yes, I just checked to see if the '<td>' did or did not contain 'style'.
if it did, stripped it out and continued process. Just a little function did the trick.
At that point, the structure of the plain (without style to begin with) and the stripped table have exactly
same structure so that was easy. I lucked out !
However it created a problem with inserting a date in MSSql that was working when I only had the stripped table.
Now that I implemented the plain coding - they both use the same inserting function which now has problem with inserting a date that came from plain table into a datetime column ! Worked fine with just the stripped table. Go figure..fixed one thing....broke another...sigh:)
if it did, stripped it out and continued process. Just a little function did the trick.
At that point, the structure of the plain (without style to begin with) and the stripped table have exactly
same structure so that was easy. I lucked out !
However it created a problem with inserting a date in MSSql that was working when I only had the stripped table.
Now that I implemented the plain coding - they both use the same inserting function which now has problem with inserting a date that came from plain table into a datetime column ! Worked fine with just the stripped table. Go figure..fixed one thing....broke another...sigh:)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good suggestions. I haven't developed programs for maybe the last two years. Just some design for mobile devices - nothing major.
I thought the samething that whitespace might be the culpit. And I think part of it was.
I also had to use the following when inserting into my table.
I am not sure what date format they want i.e. mm/dd/yyyy - haven't got a response on that one from
client yet. I think everything is as I need it now -
Thank you again for your suggestion. I appericiate it !
I thought the samething that whitespace might be the culpit. And I think part of it was.
I also had to use the following when inserting into my table.
I am not sure what date format they want i.e. mm/dd/yyyy - haven't got a response on that one from
client yet. I think everything is as I need it now -
Thank you again for your suggestion. I appericiate it !
(CONVERT(datetime, '$wrkFixedEmailSentDate', 103)),
I am not sure what date format they want
I think what you have should work. The date in sql server will always get stored as yyyy-mm-dd. Of course, you can output it however you want.
Glad you have it going!
ASKER
Thank you both for responding. I just thought there ight be an easier way then what I was doing.
You both were very helpful and your suggestions were informative.
You both were very helpful and your suggestions were informative.
@Scott asked, "David, how does a mime parson distinguish between html with inline styles or html without inline styles?"
By magic... or rather I've looked at the code of several PERL MIME Parsers + they always make my head spin.
Lots of logic to switch between various MIME encoding approaches.
Digging into something like the PERL module MIME::Parser is a good starting point to understand how complex decoding works.
By magic... or rather I've looked at the code of several PERL MIME Parsers + they always make my head spin.
Lots of logic to switch between various MIME encoding approaches.
Digging into something like the PERL module MIME::Parser is a good starting point to understand how complex decoding works.
David, I did not mean literally how does it work as far as the internals, I meant, I don't believe the mime type can distinguish between html with inline css or external. That is my question. If you have used this before, what would you look for to use a mime parser to distinguish between html that has inline css, css in a style tag or no css? Pseudo code?
Are both scenario's consistent in that the format is always the same? if it is you can simply look for a clue like
Open in new window
vsOpen in new window
If you see a td style=, then process one way vs the other.