mirror of https://github.com/adamdruppe/arsd.git
handle super long recipient lists in email without breaking on servers with a line length limit
This commit is contained in:
parent
984964d2a9
commit
55a83dc929
43
email.d
43
email.d
|
|
@ -179,10 +179,23 @@ struct RecipientList {
|
|||
|
||||
string toProtocolString(string linesep = "\r\n") {
|
||||
string ret;
|
||||
int lineLengthCounter = 6; // first line probably includes "Bcc: " or similar and if not, we're allowed to be a wee bit conservative anyway
|
||||
foreach(idx, item; recipients) {
|
||||
if(idx)
|
||||
if(idx) {
|
||||
ret ~= ", ";
|
||||
ret ~= item.toProtocolString(linesep);
|
||||
lineLengthCounter += 2;
|
||||
}
|
||||
|
||||
auto itemString = item.toProtocolString(linesep);
|
||||
|
||||
if(lineLengthCounter > 0 && lineLengthCounter + itemString.length > 78) {
|
||||
ret ~= linesep;
|
||||
ret ~= " ";
|
||||
lineLengthCounter = 1;
|
||||
}
|
||||
|
||||
ret ~= itemString;
|
||||
lineLengthCounter += itemString.length;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -1734,6 +1747,32 @@ unittest {
|
|||
assert(test !is encodeEmailHeaderForTransmit(test, linesep)); // a newline forces encoding
|
||||
}
|
||||
|
||||
unittest {
|
||||
auto message = new EmailMessage();
|
||||
//message.to ~= "someusadssssssssssssssssssssssssssssssssssssssssssssssssssssssser@example.com";
|
||||
foreach(i; 0 .. 10)
|
||||
message.to ~= "someuser@example.com";
|
||||
//message.to ~= "someusadssssssssssssssssssssssssssssssssssssssssssssssssssssssser@example.com";
|
||||
//foreach(i; 0 .. 10)
|
||||
//message.to ~= "someuser@example.com";
|
||||
message.from = "youremail@example.com";
|
||||
message.subject = "My Subject";
|
||||
message.setTextBody("hi there");
|
||||
int lineLength;
|
||||
|
||||
//import arsd.core; writeln(message.toString());
|
||||
|
||||
foreach(char c; message.toString()) {
|
||||
if(c == 13) {
|
||||
assert(lineLength < 78);
|
||||
lineLength = 0;
|
||||
} else {
|
||||
lineLength++;
|
||||
}
|
||||
}
|
||||
assert(lineLength < 78);
|
||||
}
|
||||
|
||||
/+
|
||||
void main() {
|
||||
import std.file;
|
||||
|
|
|
|||
Loading…
Reference in New Issue