[Thamesvalley-pm] MIME:Parser

Andrew thamesvalley-pm at unitedgames.co.uk
Mon Jul 18 19:12:12 PDT 2016


At tonight's social, I did venture a tech question, about how to get a name
attribute given after a content-type, in a multipart email.

Roger mentioned there was a recommended_filename I could try.
I mentioned I'd tried it just before coming, and got the error message that
it wasn't a method for the object I was using.
I mentioned it was a method of head, and not of the parser bit of Mime Tools
I was using (use Mime::Parser;). Now back home, I figured I'd just write
"head->" before "recommended_filename", .....and I'm guessing that would
work.
I say I'm guessing, as I didn't actually use recommended_filename upon my
return - I had a nosy online, and saw someone else had used mime_attr to get
attributes given after the main field. So I still tried adding in "head->",
and instead of recommended_filename, followed it up with mime_attr, and
ended up with:
$part->head->mime_attr('content-type.name')
....where $part was the current multipart in a for loop:
 for my $part ($entity->parts()) { #stuff };
....and $entity was defined earlier as:
my $entity = $parser->parse_data($emailtoparse);

Matthew (one t? Two ts?) suggested looking at the file attachment itself -
reading the first few bytes to detect the file type, rather than trusting
mime_types and filenames in email headers, to determine if the attachment
was a PDF file or not.
A quick google, and I learnt PDFs typically start with the characters %PDF
before any binary or ascii kicks in.
That said, in multipart email context, the attachment is base64 encoded,
and since we're talking two emails a week,
from a trusted source,
from an automated source [ so the message source is always structured the
same ]....I think I'm safe just grabbing the name attribute, using
mime_attr.

At least for now, ;-).

We'll see how we get on, =).

Many thanks everyone!

I'll still try and clue myself up on File, and also hope to look into
Imager, the latter of which is what Roger mentioned after I mentioned Image
Magick.

I'm just keeping things simple for now, as it's 3am in the morning, ;-).

All the best everyone! ^_^


Yours,
Andrew.

----- Original Message -----
From: "Oliver Gorwits" <oliver at cpan.org>
To: <thamesvalley-pm at pm.org>
Sent: Monday, July 18, 2016 2:11 PM
Subject: Re: [Thamesvalley-pm] Oxford meetup today: The Jam Factory, 8pm



On 2016-07-18 13:31, Oliver Gorwits wrote:
> To whet your appetites before this evening, check out a new interview
> with Larry Wall, on Slashdot:
>
>
https://developers.slashdot.org/story/16/07/14/1349207/the-slashdot-intervie
w-with-larry-wall

And I love that a Perl 6 version of a+b is "get.words.sum.say" :-D

via this very interesting site:

https://www.rosettacode.org/wiki/A%2BB#Perl_6

>
> On 2016-07-18 09:42, Neil Bowers wrote:
>> A reminder that we’re meeting in Oxford this evening:
>>
>>> The July meetup for TVPM will be:
>>>
>>> Monday 18th July at 8pm
>>> at The Jam Factory, in Oxford
>>> http://www.thejamfactoryoxford.com [1]
>>
>> Neil
>>
>>
>>
>> Links:
>> ------
>> [1] http://www.thejamfactoryoxford.com
>>
>> _______________________________________________
>> Thamesvalley-pm mailing list
>> Thamesvalley-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/thamesvalley-pm
> _______________________________________________
> Thamesvalley-pm mailing list
> Thamesvalley-pm at pm.org
> http://mail.pm.org/mailman/listinfo/thamesvalley-pm
_______________________________________________
Thamesvalley-pm mailing list
Thamesvalley-pm at pm.org
http://mail.pm.org/mailman/listinfo/thamesvalley-pm




More information about the Thamesvalley-pm mailing list