diff --git a/lib/src/smtp/internal_representation/ir_header.dart b/lib/src/smtp/internal_representation/ir_header.dart index 86709e8..ddbe48d 100644 --- a/lib/src/smtp/internal_representation/ir_header.dart +++ b/lib/src/smtp/internal_representation/ir_header.dart @@ -37,16 +37,24 @@ 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); @@ -54,6 +62,7 @@ abstract class _IRHeader extends _IROutput { yield convert.utf8.encode(maddr); yield _$gt; } + len += maddr.length; } yield _$eol;