今天早上去瘋狂嘗試做這個工作。正則表達式模式解析Mime節在C#/ winrt
我正在使用電子郵件的邊界字符串嘗試將其分爲文本/純文本和文本/ html部分。我知道有些圖書館可以做到這一點,但是他們都沒有在WinRT中工作。
這是我的。我吸的正則表達式,所以它可能是各種錯誤的:
樣本數據
From: Rory <[email protected]>
Date: Mon, 8 Oct 2012 17:05:48 +0100
Message-ID: <[email protected]>
Subject: Subject of my email
To: [email protected]
Content-Type: multipart/alternative; boundary=bcaec54fbd3a824f3504cb8e677d
--bcaec54fbd3a824f3504cb8e677d
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
text part of email
--bcaec54fbd3a824f3504cb8e677d
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<html>
<strong>HTML part of email</strong>
</html>
--bcaec54fbd3a824f3504cb8e677d--
我想給--bcaec54fbd3a824f3504cb8e677d界碑之間抽取
- 兩部分
- 內容類型,字符集和Content-Transfer-Encoding這些部分中的每一個部分
- 內容本身(在Content-Transfer-Encoding下面,直到n分機邊界
正則表達式代碼
string b = "bcaec54fbd3a824f3504cb8e677d";
Regex r = new Regex(
"(--" + b + "\r?\nContent-Type: (text/plain|text/html); charset=(.+?)\r?\nContent-Transfer-Encoding: (.+?)\r?\n(.*?--" + b + "))",
RegexOptions.Singleline);
這兩個部分只匹配,如果我離開了在最後的邊界線。如果我包含它,它只匹配第一部分。有人可以幫我開始之前,我砸的東西
UPDATE: 加樣品數據,降低
樣本數據更新,試圖使它更清晰一點 – roryok