Last active
December 14, 2019 18:50
-
-
Save floscher/ae765e2f1733a4f41438bcb808540dfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/php | |
<?php | |
$SUBJECT_PREFIX = "Subject: "; | |
$allHeadersRead = FALSE; | |
$subject = NULL; | |
while($f = fgets(STDIN)){ | |
$allHeadersRead |= (trim($f) === ''); | |
if ($subject != NULL) { | |
if (preg_match("#^\\s#", $f)) { | |
$subject .= iconv_mime_decode(substr($f, 1), 2, "UTF-8"); | |
} else { | |
$prefix = '['.$argv[1].']'; | |
echo iconv_mime_encode( | |
'Subject', | |
(strpos($subject, $prefix) === FALSE ? "$prefix " : '').$subject, | |
array( | |
'scheme' => 'Q', | |
'input-charset' => 'UTF-8', | |
'output-charset' => 'UTF-8' | |
) | |
)."\r\n"; | |
$subject = NULL; | |
echo $f; | |
} | |
} else if ($argc > 1 && !$allHeadersRead && substr($f, 0, strlen($SUBJECT_PREFIX)) === $SUBJECT_PREFIX) { | |
$subject = iconv_mime_decode(substr($f, strlen($SUBJECT_PREFIX)), 2, "UTF-8"); | |
$allHeadersRead = TRUE; | |
} else { | |
echo $f; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment