Author: Jim Winstead (jimwins) Committer: GitHub (web-flow) Pusher: jimwins Date: 2024-08-29T18:13:50-07:00
Commit: https://github.com/php/web-news/commit/97a6be661d70e32b4e7121f041a5bd349f7c3af0 Raw diff: https://github.com/php/web-news/commit/97a6be661d70e32b4e7121f041a5bd349f7c3af0.diff Do some very simple handling of text/html-only messages (fixes #23) (#25) Just a little light cleanup, we can do more if we find more examples where this isn't enough. Changed paths: M article.php Diff: diff --git a/article.php b/article.php index a2f0fa5..f9ece34 100644 --- a/article.php +++ b/article.php @@ -116,6 +116,29 @@ echo " <blockquote>\n"; echo " <pre>\n"; +/* + * If there was no text part of the message, see what we can do about creating + * one from a text/html part, or just inject a note that there was no text to + * avoid further errors. + */ +if (!array_key_exists('text', $mail)) { + if (array_key_exists('html', $mail)) { + /* + * This just aggressively strips out all tags. For the examples at + * hand, this looked okay-ish. Better than nothing, at least, and + * should be totally safe because all of the text get re-encoded + * later. + */ + // This makes HTML from Apple's Mail app retain paragraph breaks + $text = preg_replace('#<div><br></div>#', "\n\n", $mail['html']); + // And this avoids extra linebreaks from another example (Android?) + $text = preg_replace("#\n<br>\n#", "\n", $mail['html']); + $mail['text'] = html_entity_decode(strip_tags($text), encoding: 'UTF-8'); + } else { + $mail['text'] = "> There was no text content in this message."; + } +} + $lines = preg_split("@(?<=\r\n|\n)@", $mail['text']); $insig = $is_commit = $is_diff = 0;