401
402
} /* isoEncode */
404
/*********************************************************************
405
Return a string that defines the charset of the outgoing mail.
406
This just looks at your language setting - reaaly dumb.
407
It should interrogate each file/attachment.
408
Well, this will get us started.
409
*********************************************************************/
412
charsetString(const char *ct, const char *ce)
416
if(!stringEqual(ce, "7bit") &&
417
(stringEqual(ct, "text/plain") || stringEqual(ct, "text/html"))) {
419
strcpy(buf, "; charset=utf-8");
421
sprintf(buf, "; charset=iso-8859-%d", type8859);
424
} /* charsetString */
403
426
/* Read a file into memory, mime encode it,
404
427
* and return the type of encoding and the encoded data.
405
428
* Last three parameters are result parameters.
594
616
file, buflen, nacount, nullcount, longline);
595
617
nacount += nullcount;
619
/* Set the type of attachment */
620
if(buflen > 20 && nacount * 5 > buflen) {
622
ct = "application/octet-stream"; /* default type for binary */
597
627
/* Criteria for base64 encode.
598
* But, some web servers won't take qp encode, so if this is a web form,
599
* and we would normally qp encode, do base 64. */
628
* files uploaded from a web form need not be encoded, unless they contain
629
* nulls, which is a quirk of my slapped together software. */
601
if(buflen > 20 && nacount * 5 > buflen ||
602
webform && (nacount * 20 > buflen || nullcount || longline)) {
631
if(!webform && (buflen > 20 && nacount * 5 > buflen) ||
632
webform && nullcount) {
604
634
setError(MSG_MailBinary, file);
608
637
s = base64Encode(buf, buflen, true);
612
ct = "application/octet-stream"; /* default type */
620
645
/* Switch to unix newlines - we'll switch back to dos later. */
622
for(s = t = buf; s < v; ++s) {
624
if(c == '\r' && s < v - 1 && s[1] == '\n')
647
for(s = t = buf; s < v; ++s) {
649
if(c == '\r' && s < v - 1 && s[1] == '\n')
630
655
/* Do we need to use quoted-printable? */
631
656
/* Perhaps this hshould read (nacount > 0) */
632
if(nacount * 20 > buflen || nullcount || longline) {
634
int l, colno = 0, space = 0;
657
if(nacount * 20 > buflen || nullcount || longline) {
659
int l, colno = 0, space = 0;
636
newbuf = initString(&l);
638
for(s = buf; s < v; ++s) {
661
newbuf = initString(&l);
663
for(s = buf; s < v; ++s) {
640
665
/* do we have to =expand this character? */
641
if(c < '\n' && c != '\t' ||
644
(c == ' ' || c == '\t') && s < v - 1 && s[1] == '\n') {
646
sprintf(expand, "=%02X", (uchar) c);
647
stringAndString(&newbuf, &l, expand);
650
stringAndChar(&newbuf, &l, c);
657
if(c == ' ' || c == '\t')
666
if(c < '\n' && c != '\t' ||
669
(c == ' ' || c == '\t') && s < v - 1 && s[1] == '\n') {
671
sprintf(expand, "=%02X", (uchar) c);
672
stringAndString(&newbuf, &l, expand);
675
stringAndChar(&newbuf, &l, c);
682
if(c == ' ' || c == '\t')
663
688
/* If newline's coming up anyways, don't force another one. */
667
if(!space || space == i) {
668
stringAndString(&newbuf, &l, "=\n");
673
stringAndString(&newbuf, &l, "**"); /* make room */
675
newbuf[i + 1] = newbuf[i - 1];
679
newbuf[space + 1] = '\n';
681
} /* loop over characters */
692
if(!space || space == i) {
693
stringAndString(&newbuf, &l, "=\n");
698
stringAndString(&newbuf, &l, "**"); /* make room */
700
newbuf[i + 1] = newbuf[i - 1];
704
newbuf[space + 1] = '\n';
706
} /* loop over characters */
685
ce = "quoted-printable";
710
ce = "quoted-printable";
688
/* quoted printable */
690
716
ce = (nacount ? "8bit" : "7bit");
1036
1062
if(!mustmime) {
1037
1063
/* no mime components required, we can just send the mail. */
1038
1064
sprintf(serverLine,
1039
"Content-type: %s%sContent-Transfer-Encoding: %s%s%s", ct, eol, ce,
1065
"Content-Type: %s%s%sContent-Transfer-Encoding: %s%s%s", ct,
1066
charsetString(ct, ce), eol, ce, eol, eol);
1041
1067
stringAndString(&out, &j, serverLine);
1043
1069
sprintf(serverLine,
1049
1075
this format, some or all of this message may not be legible.\r\n\r\n--");
1050
1076
stringAndString(&out, &j, boundary);
1051
1077
sprintf(serverLine,
1052
"%sContent-type: %s%sContent-Transfer-Encoding: %s%s%s", eol, ct,
1078
"%sContent-Type: %s%s%sContent-Transfer-Encoding: %s%s%s", eol, ct,
1079
charsetString(ct, ce), eol, ce, eol, eol);
1054
1080
stringAndString(&out, &j, serverLine);
1063
1089
for(i = 0; s = attachments[i]; ++i) {
1064
1090
if(!encodeAttachment(s, 0, false, &ct, &ce, &encoded))
1066
sprintf(serverLine, "%s--%s%sContent-Type: %s", eol, boundary, eol,
1092
sprintf(serverLine, "%s--%s%sContent-Type: %s%s", eol, boundary,
1093
eol, ct, charsetString(ct, ce));
1068
1094
stringAndString(&out, &j, serverLine);
1069
1095
/* If the filename has a quote in it, forget it. */
1070
1096
/* Also, suppress filename if this is an alternate presentation. */