Źródło:
Komentarze (0)
| | źródło pochodzi od: sympozjon Opis: Klasa dekoduje załączniki Mime. Inaczej mówiąc możesz dzięki niej przetwarzać praktycznie wszystkie załączniki. Język: php |
cl
ass MimeDecode {
var
$attachments;
var
$text_version;
# This accepts the body of a message (in Array
form, split on n) and the
# MIME encoded boundary.
# This
returns a two dimensional array, with the
'ContentType', 'filename',
#
'ContentTypeEncoding' and the attachment 'data' for each indexed
# attachment.
function MimeDecode(
$body,
$boundary) {
$attach_no = -
1;
while (
list(,
$line) =
each(
$body) ) {
$line =
trim(
$line);
if (
strstr(
$line,
"--$boundary") ) {
$this->attachments[
'number'] = ++
$attach_no;
continue;
}
if ( !
$this->attachments[
$attach_no][
'ContentType'] &&
preg_match(
"/^Content-Type: ([w-/]*);?(.*)?/",
$line,
$matches) ) {
$this->attachments[
$attach_no][
'ContentType'] =
trim(
$matches[
1]);
if (
$matches[
2] &&
preg_match(
"/name="(.*)"/i",
$matches[
2],
$new_match)) {
if (!
$this->attachments[
$attach_no][
'filename'])
$this->attachments[
$attach_no ][
'filename']=
trim(
$new_match[
1]);
}
continue;
}
if ( !
$this->attachments[
$attach_no][
'filename'] &&
preg_match(
"/name="(.*)"/i",
$line,
$matches) ) {
$this->attachments[
$attach_no][
'filename'] =
trim(
$matches[
1]);
continue;
}
if ( !
$this->attachments[
$attach_no][
'ContentTransferEncoding'] &&
preg_match(
"/^Content-Transfer-Encoding: (.*)/",
$line,
$matches) ) {
$this->attachments[
$attach_no][
'ContentTransferEncoding'] =
trim(
$matches[
1]);
continue;
}
if ( !
$line && !
$this->attachments[
$attach_no][
'data'] ) {
$data[
0] = "";
while ( list (,
$line) =
each(
$body) ) {
$line =
trim(
$line);
$line =
preg_replace(
"/< */? *HTML *>/i", "",
$line);
if (
strstr(
$line,
$boundary)) {
prev(
$body);
break;
}
array_push(
$data,
$line.
"n");
}
# Decode attachment data be
fore leaving...
# B
ase
64 encoded messages...
if ( !
strcasecmp(
$this->attachments[
$attach_no][
'ContentTransferEncoding'],
"base64") ) {
$this->attachments[
$attach_no][
'data'][
0] = "";
foreach (
$data as $line)
array_push(
$this->attachments[
$attach_no][
'data'], b
ase
64_decode(
$line));
# Quoted-Printable encoded messages
}
else if ( !
strcasecmp(
$this->attachments[
$attach_no][
'ContentTransferEncoding'],
"quoted-printable") ) {
$this->attachments[
$attach_no][
'data'][
0] = "";
foreach (
$data as $line)
array_push(
$this->attachments[
$attach_no][
'data'], quoted_printable_decode(
$line));
#
7 or
8 bit
"encoding"
}
else if ( !
strcasecmp(
$this->attachments[
$attach_no][
'ContentTransferEncoding'], "7bit") || !strcasecmp($this->attachments[$attach_no]['ContentTransferEncoding'], "8bit") ) {
$this->attachments[
$attach_no][
'data'] =
$data;
# defualt to just dumping the data
}
else {
$this->attachments[
$attach_no][
'data'] =
$data;
}
$data = NULL;
continue;
}
} # end
foreach
} # end MimeDecode
}
</body>
</html>
powrótTagi do źródła:
Dekodowanie Mime, mail, php
Nikt jeszcze nie skomentował tego źródła.