Skip to content

Instantly share code, notes, and snippets.

View boicualexandru's full-sized avatar

Alex Boicu boicualexandru

  • Cluj-Napoca, Romania
View GitHub Profile
@boicualexandru
boicualexandru / ConvertHtmlSrcToAttachmentCid.cs
Created July 23, 2020 07:49
Replace html image urls with the cid of the attachments
var templateDecoded = Encoding.UTF8.GetString(Convert.FromBase64String(campaign.Template));
templateDecoded = ReplaceHtmlImagesWithCIds(templateDecoded);
private string[] GetImageNamesFromHtml(string html)
{
string[] htmlImgSrcNames = Regex.Matches(html, @"<img.+?src=[\""'](.*?[\\/])?(.+?)[\""'].*?>", RegexOptions.IgnoreCase).Select(x => x.Groups[2].Value).ToArray();
string[] htmlImgUrlNames = Regex.Matches(html, @"url\([\""']?(.*?[\\/])(.+?)[\""']?\)", RegexOptions.IgnoreCase).Select(x => x.Groups[1].Value).ToArray();
string[] htmlImageNames = htmlImgSrcNames.Concat(htmlImgUrlNames).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToArray();