cruxports/mblaze/mblaze-fofl.patch
2022-05-12 11:16:20 -04:00

106 lines
4.0 KiB
Diff

--- mblaze-1.2/mmime.c 2021-12-12 11:39:30.000000000 -0500
+++ mblaze-1.2f/mmime.c 2022-05-12 09:13:44.371637134 -0400
@@ -143,6 +143,70 @@ gen_qp(uint8_t *s, off_t size, size_t ma
return linelen;
}
+
+size_t
+gen_flowd(uint8_t *s, off_t size, size_t maxlinelen, size_t linelen)
+{
+ off_t i;
+ int header = linelen > 0;
+
+ for (i = 0; i < size; i++) {
+ // inspect utf8 sequence to not wrap in between multibyte
+ int mb;
+ if ((s[i] & 0x80) == 0) mb = 3;
+ else if ((s[i] & 0xc0) == 0x80) mb = 3;
+ else if ((s[i] & 0xe0) == 0xc0) mb = 6;
+ else if ((s[i] & 0xf0) == 0xe0) mb = 9;
+ else if ((s[i] & 0xf8) == 0xf0) mb = 12;
+ else mb = 3;
+
+ if (linelen >= maxlinelen-mb-!!header) {
+ linelen = 0;
+ if (header) {
+ printf("\n");
+ } else {
+ puts(" ");
+ }
+ }
+
+
+ if ((s[i] > 126) ||
+ (linelen == 0 &&
+ (strncmp((char *)s, "From ", 5) == 0 ||
+ (s[i] == '.' && i+1 < size &&
+ (s[i+1] == '\n' || s[i+1] == '\r'))))) {
+ putc_unlocked(s[i], stdout);
+ linelen ++;
+ } else if (header &&
+ (s[i] == '\n' || s[i] == '\t' || s[i] == '_')) {
+ putc_unlocked(s[i], stdout);
+ linelen ++;
+ } else if (header && s[i] == ' ') {
+ putc_unlocked('_', stdout);
+ linelen++;
+ } else if (s[i] < 33 && s[i] != '\n') {
+ if ((s[i] == ' ' || s[i] == '\t') &&
+ i+1 < size &&
+ (s[i+1] != '\n' && s[i+1] != '\r')) {
+ putc_unlocked(s[i], stdout);
+ linelen++;
+ } else {
+ putc_unlocked(s[i], stdout);
+ linelen++;
+ }
+ } else if (s[i] == '\n') {
+ putc_unlocked('\n', stdout);
+ linelen = 0;
+ } else {
+ putc_unlocked(s[i], stdout);
+ linelen++;
+ }
+ }
+ if (linelen > 0 && !header)
+ puts("\n");
+ return linelen;
+}
+
static const char *
basenam(const char *s)
{
@@ -444,8 +508,8 @@ gen_build()
inheader = 0;
printf("MIME-Version: 1.0\n");
if (rflag) {
- printf("Content-Type:%s", contenttype ? contenttype : " text/plain; charset=UTF-8\n");
- printf("Content-Transfer-Encoding:%s", contenttransferenc ? contenttransferenc : " quoted-printable\n");
+ printf("Content-Type:%s", contenttype ? contenttype : " text/plain; charset=US-ASCII; format=flowed\n");
+ printf("Content-Transfer-Encoding:%s", contenttransferenc ? contenttransferenc : " 7bit\n");
printf("\n");
} else {
printf("Content-Type: %s; boundary=\"%s\"\n", tflag, sep);
@@ -487,9 +551,9 @@ gen_build()
if (!rflag && !intext) {
printf("\n--%s\n", sep);
- printf("Content-Type:%s", contenttype ? contenttype : " text/plain; charset=UTF-8\n");
+ printf("Content-Type:%s", contenttype ? contenttype : " text/plain; charset=US-ASCII; format=flowed\n");
printf("Content-Disposition: inline\n");
- printf("Content-Transfer-Encoding:%s", contenttransferenc ? contenttransferenc : " quoted-printable\n");
+ printf("Content-Transfer-Encoding:%s", contenttransferenc ? contenttransferenc : " 7bit\n");
printf("\n");
intext = 1;
@@ -498,7 +562,7 @@ gen_build()
if (contenttransferenc)
printf("%s", line);
else
- gen_qp((uint8_t *)line, strlen(line), 78, 0);
+ gen_flowd((uint8_t *)line, strlen(line), 78, 0);
emptybody = 0;
}