Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to RE: RegExp to delete mail attachments by BlaisePascal
in thread RegExp to delete mail attachments by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found