[php] bepalen van mail encoding

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • marty
  • Registratie: Augustus 2002
  • Laatst online: 27-03-2023
Ik ben nu een mail aan het verwerken die als volgt is ingedeeld:
1
type: multipart
subtype: ALTERNATIVE
encoding: 7bit
1.1
type: text
subtype: PLAIN
encoding: 7bit
1.2
type: text
subtype: HTML
encoding: 7bit
2
type: image
subtype: GIF
encoding: base64

bij 1.2 geeft php bij de encoding aan dat het 7bit is; als ik echter in de source van de email kijk zie ik dit staan:

------=_NextPart_001_005B_01C3672F.F2682060
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

De encoding is dus quoted-printable. Ik kan alleen niet ontdekken waarom php toch denkt dat het 7bit is. Dit is m'n code:

PHP:
1
2
3
4
5
6
7
8
9
10
$encoding = array("7bit", "8bit", "binary", "base64", "quoted-printable", "other");
// [...]
$structure  = imap_fetchstructure($inbox, $x);
$i = 1;
while ($body = imap_fetchbody($inbox, $x, $i))
{
    $structure->parts[$i-1] = imap_bodystruct($inbox, $x, $i);
    // [...]
    echo "encoding: ".$encoding[$structure->parts[$i-1]->encoding]."<br>\n";
}

eigenlijk staat het stukje voor die subparts een loopje verder, maar die is exact hetzelfde

Doe ik iets fout, zit er misschien een bugje in php, of is de mail gewoon dusdanig slordig opgemaakt dat php het daarom niet snapt? het is vrij lastig, want nu ziet die html email er niet meer uit (het is namelijk ook echt quoted-printable)

Acties:
  • 0 Henk 'm!

Verwijderd

marty schreef op 26 augustus 2003 @ 14:28:
------=_NextPart_001_005B_01C3672F.F2682060
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

De encoding is dus quoted-printable. Ik kan alleen niet ontdekken waarom php toch denkt dat het 7bit is. Dit is m'n code:

PHP:
1
2
3
4
5
6
7
8
9
10
$encoding = array("7bit", "8bit", "binary", "base64", "quoted-printable", "other");
// [...]
$structure  = imap_fetchstructure($inbox, $x);
$i = 1;
while ($body = imap_fetchbody($inbox, $x, $i))
{
    $structure->parts[$i-1] = imap_bodystruct($inbox, $x, $i);
    // [...]
    echo "encoding: ".$encoding[$structure->parts[$i-1]->encoding]."<br>\n";
}

eigenlijk staat het stukje voor die subparts een loopje verder, maar die is exact hetzelfde

Doe ik iets fout, zit er misschien een bugje in php
Dat denk ik niet, want ik gebruik ook IMAP om met mail te prutsen :+ en qua encoding heb ik nog nooit problemen gehad (en ik heb heel wat mailtjes gehad).
of is de mail gewoon dusdanig slordig opgemaakt dat php het daarom niet snapt?
als de boundaries goed zijn gedefinieerd en ze staan op de goede plek, is er geen probleem.
het is vrij lastig, want nu ziet die html email er niet meer uit (het is namelijk ook echt quoted-printable)
Miss. overbodig, maar ik zie in het loop-je wat je gepost hebt, geen $i++ of iets dergelijks staan? Ik heb ook (licht) het vermoeden dat php de encoding van 1 of 1.1 echo'ed. Ik zit nu op m'n werk, als je er vanavond nog niet uit bent, dan zal ik even kijken hoe ik dat gedaan heb met encoding en meerdere bodyparts.

Acties:
  • 0 Henk 'm!

  • marty
  • Registratie: Augustus 2002
  • Laatst online: 27-03-2023
Verwijderd schreef op 26 August 2003 @ 14:41:
Miss. overbodig, maar ik zie in het loop-je wat je gepost hebt, geen $i++ of iets dergelijks staan? Ik heb ook (licht) het vermoeden dat php de encoding van 1 of 1.1 echo'ed. Ik zit nu op m'n werk, als je er vanavond nog niet uit bent, dan zal ik even kijken hoe ik dat gedaan heb met encoding en meerdere bodyparts.
marty schreef op 26 August 2003 @ 14:28:
eigenlijk staat het stukje voor die subparts een loopje verder, maar die is exact hetzelfde
:+

ik was er al bang voor....maargoed. zal bij deze anders nog even de volledige code geven:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 // message types
$type = array("text", "multipart", "message", "application", "audio", "image", "video", "other");
 // message encodings
$encoding = array("7bit", "8bit", "binary", "base64", "quoted-printable", "other");

$inbox = connect_mailbox();
$total = imap_num_msg($inbox);

if ($total >= 1)
{
    for($x=1; $x<=$total; $x++) 
    {
        $headers    = imap_header($inbox, $x);
        $structure  = imap_fetchstructure($inbox, $x);

        $i = 1;
        echo "<ul>\n";
        while ($body = imap_fetchbody($inbox, $x, $i))
        {
            $structure->parts[$i-1] = imap_bodystruct($inbox, $x, $i);
            echo " <li><u>i: ".$i."</u></li><br>\n";
            echo "type: ".$type[$structure->parts[$i-1]->type]."<br>\n";
            echo "subtype: ".$structure->parts[$i-1]->subtype."<br>\n";
            echo "encoding: ".$encoding[$structure->parts[$i-1]->encoding]."<br>\n";
//          echo "body: ".$body."<br>\n";
            $j = 1;
            while($body = imap_fetchbody($inbox, $x, $i.".".$j))
            {
                if ($j == 1)
                {
                    echo "<ul>";
                    $bla = True;
                }
                $structure->parts[$i-1]->parts[$j-1] = imap_bodystruct($inbox, $x, $i.".".$j);
                echo "<li><u>j: ".$j."</u></li><br>\n";
                echo "type: ".$type[$structure->parts[$i-1]->parts[$j-1]->type]."<br>\n";
                echo "subtype: ".$structure->parts[$i-1]->parts[$j-1]->subtype."<br>\n";
                echo "encoding: ".$encoding[$structure->parts[$i-1]->encoding]."<br>\n";
                echo "body: ".$body."<br>\n";
                $j++;
            }
            if (isset($bla))
                echo "</ul\n";
            unset($bla);
            $i++;
        }
        echo "</ul>\n";
    }
}


dit ziet er misschien een beetje weird uit, maar ik gebruik het dan ook alleen om te testen wat wat doet.

Acties:
  • 0 Henk 'm!

Verwijderd

hehe :+

Ik heb eigenlijk niet de tijd om er op dit moment uitgebreid in te duiken, maar wat ik zo op het eerste oog zie:

PHP:
1
2
3
4
5
6
7
[...]
$structure->parts[$i-1]->parts[$j-1] = imap_bodystruct($inbox, $x, $i.".".$j);
echo "<li><u>j: ".$j."</u></li><br>\n";
echo "type: ".$type[$structure->parts[$i-1]->parts[$j-1]->type]."<br>\n";
echo "subtype: ".$structure->parts[$i-1]->parts[$j-1]->subtype."<br>\n";
echo "encoding: ".$encoding[$structure->parts[$i-1]->encoding]."<br>\n";
[...]


Onderste regel uit bovenstaande stukje is anders dan de twee regels daarboven, in die zin dat het minder diep in de array/object duikt.

PHP:
1
echo "encoding: ".$encoding[$structure->parts[$i-1]->encoding]."<br>\n";


Moet dat niet
PHP:
1
echo "encoding: ".$encoding[$structure->parts[$i-1]->parts[$j-1]->encoding]."<br>\n";


zijn?

:)

Acties:
  • 0 Henk 'm!

  • marty
  • Registratie: Augustus 2002
  • Laatst online: 27-03-2023
jemig, wat een knuppel ben ik 8)7 8)7 8)7
ik keek er nota-bene nog een keer extra naar toen ik het hier pastte.... :/

* marty needs B)

Acties:
  • 0 Henk 'm!

Verwijderd

Pagina: 1