Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace the MS Outlook html source string using regex?

I have an application which reads the source html and downloads all the attachments of an email. This works fine except for the fact that Microsoft Outlook has some weird source value, for example...

<img width="163" height="39" id="Picture_x0020_1" src="cid:[email protected]" alt="Description: Description: Description: cid:[email protected]">

Firstly, I'd like to change it to just Attachments\image001.png as the source. Also, the alt should just be image001.png, not this long weird alt. Not really sure how to go about this.

like image 344
michael Avatar asked Aug 23 '12 17:08

michael


1 Answers

You should use Regex (I updated the tags in your question to reflect this):

Regex.Replace(text, @"src=""cid:(?<FileName>[^@]+)@[^""]*""", @"src=""Attachments\${FileName}""",
    RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
Regex.Replace(x, @"alt=""[^.]*cid:(?<FileName>[^@]+)@[^""]*""", @"alt=""${FileName}""",
    RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);

I'm sure there are more efficient ways of doing this, but that's what I could come up with.

like image 160
myermian Avatar answered Oct 31 '22 23:10

myermian