Skip to content

Commit

Permalink
Split address header's value into multiple lines if too long
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyeh committed Mar 6, 2021
1 parent 77ee450 commit bc42f9c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/src/smtp/internal_representation/ir_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,23 @@ abstract class _IRHeader extends _IROutput {
yield convert.utf8.encode(_name);
yield _$colonSpace;

bool second = false;
var len = 2, //2 = _$commaSpace
second = false;
for (final address in addresses) {
if (second) yield _$commaSpace;
else second = true;

final name = address.sanitizedName,
maddr = address.sanitizedAddress;
var adrlen = maddr.length;
if (name != null) adrlen += name.length + 3; //not accurate but good enough

if (second) {
yield _$commaSpace;

if (len + adrlen > maxEncodedLength) {
len = 2;
yield _$eolSpace;
}
} else second = true;

if (name == null) {
yield convert.utf8.encode(maddr);
} else {
Expand All @@ -54,6 +64,8 @@ abstract class _IRHeader extends _IROutput {
yield convert.utf8.encode(maddr);
yield _$gt;
}

len += adrlen;
}

yield _$eol;
Expand Down

0 comments on commit bc42f9c

Please sign in to comment.