P
P
Pavel2017-12-07 02:11:00
PHP
Pavel, 2017-12-07 02:11:00

How and how to parse email - format?

Hello!
I get imap mail from Yandex, i.e. from your Yandex mailbox. Some letters come in an interesting way for me in this format:
----ALT--3qTFCBd0ekkfmpv0s6C69hoX0USbWYVW1512581220
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
CgoK
----ALT--3qTFCBd0ekkfmpv0s6C69hoX0USbWYVW1512581220
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
CjxIVE1MPjxCT0RZPjxicj48YnI+PGJyPjwvQk9EWT48L0hUTUw+Cg==
----ALT--3qTFCBd0ekkfmpv0s6C69hoX0USbWYVW1512581220--
How can this be decoded?
I am using imap parsing function.


switch ((int)$encoding) {
# 7BIT
case 0:
$body = $msg_body;
break;
# 8BIT
case 1:
$body = imap_8bit($msg_body);
break;
# BINARY
case 2:
$body = imap_binary($msg_body);
break;
# BASE64
case 3:
$body = imap_base64($msg_body);
break;
# QUOTED-PRINTABLE
case 4:
$body = imap_qprint($msg_body);
break;
# OTHER
case 5:
$body = $msg_body;
break;
# UNKNOWN
default:
$body = $msg_body;
break;
}
return $body;

in a loop, we parse it like this:

$structure = imap_fetchstructure($connection, $num);
$msg = imap_fetchbody($connection, $num, 1, FT_PEEK);

FT_PEEK - so as not to read messages in the mail)))
as a result, at the output I get a letter not decoded imap_fetchbody and I can't figure out what to fasten. Manual parsing - it seems to me not quite right, extracting base64 from a letter (body), which is not clear how it comes.
imap_fetchbody - extracts a part (piece) of the letter.
UPD:
got to the script... solved the problem!
Everything turned out to be not in the reel ... it was in the wires. So, this format can parse imap php, but it must be fed normally. What need to do?
- We look at what part of the body of the letter we need to get, imap_fetchbody, the first part, or 1.1 ... it will not be difficult to write code to receive the letter.
Why exactly? go to the descriptions of the structure of letters, read (left the link below in the comments). You will need two checks, then you will figure it out ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Litvinenko, 2017-12-07
@edli007

Not an expert, but perhaps this line is a clue
this is base64, it says here
The rest is some kind of garbage, maybe some keys or a crooked encoding, not a big specialist in letters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question