Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

RE: RegExp to delete mail attachments

by BlaisePascal (Monk)
on Sep 12, 2000 at 01:08 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2023-05-30 18:22 GMT
Find Nodes?
    Voting Booth?

    No recent polls found