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 cb132d3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/src/smtp/internal_representation/ir_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,32 @@ 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;
if (second) {
yield _$commaSpace;

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

final name = address.sanitizedName,
maddr = address.sanitizedAddress;
if (name == null) {
yield convert.utf8.encode(maddr);
} else {
len += name.length + 3; //not accurate but good enough
if (_shallB64(name, irMetaInformation)) yield* _outB64(name);
else yield convert.utf8.encode(name);

yield _$spaceLt;
yield convert.utf8.encode(maddr);
yield _$gt;
}
len += maddr.length;
}

yield _$eol;
Expand Down

0 comments on commit cb132d3

Please sign in to comment.