File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,10 +18,7 @@ class ImageTransformer implements DomTransformer {
1818 if (src != null ) {
1919 if (src.startsWith ('cid:' )) {
2020 var cid = src.substring ('cid:' .length);
21- if ((cid.startsWith ('%3C' ) && cid.endsWith ('%3E' )) ||
22- (cid.startsWith ('%3c' ) && cid.endsWith ('%3e' ))) {
23- cid = '<${cid .substring ('%3C' .length , cid .length - '%3E' .length )}>' ;
24- } else if (! cid.startsWith ('<' )) {
21+ if (! cid.startsWith ('<' )) {
2522 cid = '<$cid >' ;
2623 }
2724 final part = message.getPartWithContentId (cid);
@@ -32,7 +29,9 @@ class ImageTransformer implements DomTransformer {
3229 toImageData (part, contentType.mediaType, configuration);
3330 imageElement.attributes['src' ] = data;
3431 if (imageElement.parent? .localName != 'a' ) {
35- var anchor = Element .html ('<a href="cid://$cid "></a>' );
32+ final linkCid =
33+ Uri .encodeComponent (cid.substring (1 , cid.length - 1 ));
34+ var anchor = Element .html ('<a href="cid://$linkCid "></a>' );
3635 anchor.append (Element .html (imageElement.outerHtml));
3736 imageElement.replaceWith (anchor);
3837 }
Original file line number Diff line number Diff line change @@ -13,17 +13,20 @@ class MergeAttachedImageTextTransformer extends TextTransformer {
1313 final search = TextSearchIterator ('[cid:' , text, endSearchPattern: ']' );
1414 String ? nextImageDefinition;
1515 while ((nextImageDefinition = search.next ()) != null ) {
16- final cid = nextImageDefinition! .substring (
17- '[cid:' .length, nextImageDefinition.length - 2 );
16+ var cid = nextImageDefinition!
17+ .substring ('[cid:' .length, nextImageDefinition.length - 2 );
18+ if (! cid.startsWith ('<' )) {
19+ cid = '<$cid >' ;
20+ }
1821 final part = message.getPartWithContentId (cid);
1922 if (part != null ) {
2023 final contentType = part.getHeaderContentType ();
2124 final mediaType = contentType? .mediaType;
2225 final data =
2326 ImageTransformer .toImageData (part, mediaType, configuration);
24-
27+ final linkCid = Uri . encodeComponent (cid. substring ( 1 , cid.length - 1 ));
2528 text = text.replaceFirst (nextImageDefinition,
26- '<img src="$data " alt="${part .getHeaderContentDisposition ()?.filename }"/>' );
29+ '<a href="cid://$ linkCid ">< img src="$data " alt="${part .getHeaderContentDisposition ()?.filename }"/></a >' );
2730 }
2831 }
2932 return text;
You can’t perform that action at this time.
0 commit comments