I have the following:
if($emails) {
$output = '';
rsort($emails);
foreach($emails as $email_number) {
foreach ([1,2] as $option) {
$structure = imap_fetchstructure($inbox, $email_number);
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,$option));
$regex = '#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#';
preg_match_all($regex, $message, $links);
foreach ($links[0] AS $link) {
$output .= $link.'<br>';
}
}}
echo $output;
}
This works okay except some links contain � and some contain a small empty quare box.
If I don't use quoted_printable_decode(imap_fetchbody($inbox,$email_number,$option))
Then some links contain =3D.
I can' seem to figure out how to get this right.
I have also tried:
$structure = imap_fetchstructure($inbox, $email_number, FT_UID);
if($structure->encoding == "4"){
$message = base64_decode(imap_fetchbody($inbox, imap_msgno($inbox, $email_number), $option));
} elseif ($structure->encoding == "3") {
$message = imap_qprint(map_fetchbody($inbox, imap_msgno($inbox, $email_number), $option));
} else {
$message = imap_fetchbody($inbox,$email_number,$option);
}
I simply cannot figure out how to do this.