note 125468 added to function.imap-fetchbody
| From: | jab_creations.yahoo.com via php-notes | Date: | Wed, 28 Oct 2020 03:08:41 +0000 |
| Subject: | note 125468 added to function.imap-fetchbody | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-215660@lists.php.net to get a copy of this message | ||
The third parameter, the section parameter is not properly documented and I've seen a dozen or
two developers in my research to figure this issue out come to hopeless conclusions. It's
critical to understand that various email providers (e.g. AOL, Gmail, Microsoft, Yahoo and client
programs like Thunderbird and...yes, the five thousand versions of Outlook) do NOT follow some
"standard".
- Unlike JavaScript and how PHP normally function all index numbers start at 1, NOT 0.
- Your third/section parameter will be a whole number if there is not a second 'parts'
array (I am NOT using classes here).
- If the 'parts' array contains a 'parts' subarray you will have floating-point
numbers (e.g. 1.1 or 2.1 instead of 1 or 2). If you have two parts in the 'parts' subarray
you will have something such as 1.1 and 1.2 or 2.1 and 2.2 - REMEMBER: these vary by provider and
there is no "STANDARD" as this is a PHP-specific issue!
- None, some or all 'parts' arrays may be singular or contain child 'parts'
subarrays, this is completely dynamic and may NOT be consistent from even the same provider!
The following presumes you have a $mail_connection and know which $email_number number you're
working with:
<?php
$i = 0;//Level 1 part references.
$j = 0;//Level 2 part references.
$mail_message_structure = json_decode(json_encode(imap_fetchstructure($mail_connection,
$email_number)), true);//Convert AWAY from class style.
while ($i < count($mail_message_structure['parts']))
{
if (isset($mail_message_structure['parts'][$i]['parts']))
{//Multiple, contains secondary 'parts' array.
while ($j < count($mail_message_structure['parts'][$i]['parts']))
{
//Remove subjectivity of "Png/PNG/png" with always lower-case.
$mail_message_structure['parts'][$i]['parts'][$j]['subtype'] =
strtolower($mail_message_structure['parts'][$i]['parts'][$j]['subtype']);
$mail_message_structure['parts'][$i]['parts'][$j]['id_imap_fetchbody']
= ($i + 1).'.'.($j + 1);
echo '<p>'.$i.': multi, '.$j.'
'.$mail_message_structure['parts'][$i]['parts'][$j]['subtype'].':
'.($i + 1).'.'.($j + 1).'</p>';
$j++;
}
}
else
{//Single, first level.
//Remove subjectivity of "Png/PNG/png" with always lower-case.
$mail_message_structure['parts'][$i]['subtype'] =
strtolower($mail_message_structure['parts'][$i]['subtype']);
$mail_message_structure['parts'][$i]['id_imap_fetchbody'] = ($i + 1);
echo '<p>'.$i.': single:
'.$mail_message_structure['parts'][$i]['subtype'].': '.($i +
1).'</p>';
}
$i++;
}
?>
Now that we can actually understand HOW to access specific PARTS of the email body it is a simple
manner to iterate over the structure array:
<?php
foreach ($mail_message_structure['parts'] as $k4 => $v4)
{
if (isset($v4['parts']))
{
foreach ($v4['parts'] as $k5 => $v5) {mail_imap_body($mail_connection,
$email_number, $v5);}//echo '<div>MULTI:
'.$v5['id_imap_fetchbody'].';
<pre>'.htmlspecialchars(print_r($v4['parts'],1)).'</pre></div>';
}
else {mail_imap_body($mail_connection, $email_number, $v4);}//echo '<div>SINGLE:
'.$v4['id_imap_fetchbody'].'<pre>'.htmlspecialchars(print_r($v4,1)).'</pre></div>';
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.174 (proxied: 185.245.86.116)
----
Manual Page -- http://php.net/manual/en/function.imap-fetchbody.php
Edit -- https://master.php.net/note/edit/125468
Del: integrated -- https://master.php.net/note/delete/125468/integrated
Del: useless -- https://master.php.net/note/delete/125468/useless
Del: bad code -- https://master.php.net/note/delete/125468/bad+code
Del: spam -- https://master.php.net/note/delete/125468/spam
Del: non-english -- https://master.php.net/note/delete/125468/non-english
Del: in docs -- https://master.php.net/note/delete/125468/in+docs
Del: other reasons-- https://master.php.net/note/delete/125468
Reject -- https://master.php.net/note/reject/125468
Search -- https://master.php.net/manage/user-notes.php