MIME::Lite -- Add attribute to part's Content-Type

J

Jerry Krinock

When Apple's Mail.app composes a message with a .zip attachment, it
adds an "x-mac-auto-archive" attribute to Content-Type, which I
believe tells the receiving Mail.app to automatically unzip the
attachment upon receipt. I would like to be able to send messages
behaving like that when I use MIME::Lite. Taking a wild guess, I
wrote this code:

$msg->attach(
Type => 'application/zip',
Path => $myPath,
'x-mac-auto-archive' => 'yes',
Filename => "MyScript.app.zip"
) ;

What I get from that (which fails to make Mail.app automatically
unzip) is:

Content-Type: application/zip; name="MyScript.app.zip"
X-Mac-Auto-Archive: yes

A similar message sent by the real Mail.app gives me a Content-Type
like this:

Content-Type: application/zip;
x-mac-auto-archive=yes;
name="MyScript.app.zip"

Apparently, the problem is that instead of becoming an attribute of
Content-Type, my x-mac-auto-archive becomes a Header field. (I hope
my terminology is correct.)

I poked around in the MIME::Lite source code for a while but didn't
get anywhere. Does anyone know how to set an custom attribute ^of^ a
header field using Perl?

Sincerely,

Jerry Krinock
 
T

Todd Wade

When Apple's Mail.app composes a message with a .zip attachment, it
adds an "x-mac-auto-archive" attribute to Content-Type, which I
believe tells the receiving Mail.app to automatically unzip the
attachment upon receipt. I would like to be able to send messages
behaving like that when I use MIME::Lite. Taking a wild guess, I
wrote this code:

$msg->attach(
Type => 'application/zip',
Path => $myPath,
'x-mac-auto-archive' => 'yes',
Filename => "MyScript.app.zip"
) ;

What I get from that (which fails to make Mail.app automatically
unzip) is:

Content-Type: application/zip; name="MyScript.app.zip"
X-Mac-Auto-Archive: yes

A similar message sent by the real Mail.app gives me a Content-Type
like this:

Content-Type: application/zip;
x-mac-auto-archive=yes;
name="MyScript.app.zip"

Apparently, the problem is that instead of becoming an attribute of
Content-Type, my x-mac-auto-archive becomes a Header field. (I hope
my terminology is correct.)

Just looking at what you've got here, I'd try:

Type => 'application/zip; x-mac-auto-archive=yes'

Todd W.
 
J

Jerry Krinock

Just looking at what you've got here, I'd try:
Type => 'application/zip; x-mac-auto-archive=yes'

Thanks for the great guess, Todd. It WORKS.

Can anyone interpret that documentation [1] to say that Todd's trick
is supported, or suggest a supported method? Otherwise, I'll submit a
bug on the documentation, asking to please officially support Todd's
trick.

Jerry Krinock

Looking at the documentation further, it appears that the 'attr'
method [2] is provided to set attributes in header fields, but I can't
get it to work.

First Attempt: I invoked attr on the whole message, as in the example
given in the documentation. This doesn't make sense, because I want
this attribute applied only to one part. But I tried it anyhow:

$msg->attach(
Type => 'application/zip',
Path => $myPath,
Filename => "MyScript.app.zip"
) ;
$msg->attr("x-mac-auto-archive" => "yes") ;

Result: Failed. x-mac-auto-archive does not appear anywhere in the
message.

Second Attempt: Assuming that attach() would return the part (which is
undocumented), I tried to invoke 'attr' on the part. At least this
makes sense:

my $fileAttachmentPart = $msg->attach(
Type => 'application/zip',
Path => $myScriptPath,
Filename => "MyScript.app.zip"
) ;
$fileAttachmentPart->attr("x-mac-auto-archive" => "yes");

Result: Failed. I get the attribute as a header field,
X-Mac-Auto-Archive: yes
which does not have the desired effect on Apple's Mail.app.


REFERENCES

[1] http://search.cpan.org/~rjbs/MIME-Lite-3.023/lib/MIME/Lite.pm#Content_types

[2] attr ATTR,[VALUE]
Instance method. Set MIME attribute ATTR to the string VALUE. ATTR is
converted to all-lowercase. This method is normally used to set/get
MIME attributes:

$msg->attr("content-type" => "text/html");
$msg->attr("content-type.charset" => "US-ASCII");
$msg->attr("content-type.name" => "homepage.html");

This would cause the final output to look something like this:
Content-type: text/html; charset=US-ASCII; name="homepage.html"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top