1

On Apple Mail when I send an email with Base64 encoding (from a Perl script) the Apple Mail client is not decoding it's subject line i.e. it is showing raw base64 encoded text.

So when I am sending below from my Perl script:

Subject: =?UTF-8?B?IPCfjLkgVGhlIGVuY2hhbnRpbmcgc291bmR0cmFjayB0byAnQmVhdXR5IEFuZCBUaGUgQ mVhc3Qn
IGlzIG91dCB0b2RheSEg8J+MuQ==
?=

Instead of showing this: The enchanting soundtrack to 'Beauty And The Beast' is out today!

It is showing below in subject line:

=?UTF-8?B?IPCfjLkgVGhlIGVuY2hhbnRpbmcgc291bmR0cmFjayB0byAnQmVhdXR5IEFuZCBUaGUgQm Vhc3Qn
IGlzIG91dCB0b2RheSEg8J+MuQ==
?=

Please can you advise why this is happening.

It appears to be issue with Apple Mail client, as the same subject line is working fine on all other mail clients.

Let me know if I missed to explain anything.

Best regards, Amar

Manish Kumar Sharma
  • 12,982
  • 9
  • 58
  • 105
Amar N
  • 11
  • 2

1 Answers1

0

If you are using MIME::Base64 to encode the string, it adds a trailing whitespace (for some reason!). From your example it looks like your converter function is adding a newline character:

Subject: =?UTF-8?B?IPCfjLkgVGhlIGVuY2hhbnRpbmcgc291bmR0cmFjayB0byAnQmVhdXR5IEFuZCBUaGUgQ mVhc3QnIGlzIG91dCB0b2RheSEg8J+MuQ==
?=

...should be all on one line:

Subject: =?UTF-8?B?IPCfjLkgVGhlIGVuY2hhbnRpbmcgc291bmR0cmFjayB0byAnQmVhdXR5IEFuZCBUaGUgQ mVhc3QnIGlzIG91dCB0b2RheSEg8J+MuQ==?=

Breaking the line with a newline or whitespace breaks the encoding and causes some clients to panic. This is what I use:

## ENCODE SUBJECT
use MIME::Base64;
my $subject_enc = encode_base64($subject);
$subject_enc =~ s/^\s+|\s+$//g; #TRIMS ANY SURROUNDING WHITESPACE
$subject_enc =~ s/^\n+|\n+$//g; #TRIMS ANY NEWLINE CHARACTERS
my $subject_enc = '=?UTF-8?B?' . $subject_enc . '?=';
Colin R. Turner
  • 1,323
  • 15
  • 24