Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

RE: RegExp to delete mail attachments

by BlaisePascal (Monk)
on Sep 12, 2000 at 01:08 UTC ( [id://31987]=note: print w/replies, xml ) Need Help??


in reply to RegExp to delete mail attachments

Looking on CPAN is your best bet. If you wanted to do it yourself, I'd suggest really reading the MIME RFCs, because I can see some problems with what you have there immediately.

I'm gonna assume that the .* issues others have mentioned have been resolved, and you are using .*? for a non-greedy look-ahead. That'll help immediately.

But the end-terminator for an attachment isn't "From", it's a second line matching the first "--.*" line. Worse, the proper value of the ".*" is specified on a different line, which you don't wan't to chop out.

Ignoring that last problem, you could probably use something like:

s{ (\n--).*?\s*\n # Match boundary line Content-Type:\ image # Find image part .*? # Match part non-greedily (\1) # Match next boundary line }{\1}gs # Replace with boundary line
This should match the proper beginnings and endings better. I'd love to get rid of the .*? parts, but I'm not sure if it can be done. I though of using \S* for the first, but the boundary line can contain spaces, so that won't work.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://31987]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found