的GoldMine 5.5(哇!) - 我的哀悼(BOT其實,你是幸運的,因爲在GoldMine的RFC822領域的未來版本進行加密以及)
我看到兩個選項來解決問題(所有需要SQL Server 2005或以上):
- 與SQLCLR集成,能夠使用正則表達式解析RFC822場
- ,或者如果你想使用SQL的GoldMine API)來獲取電子郵件中使用GoldMineAPI(並集成了SQLCLR通過業務邏輯功能
我有兩個選項的一些例子:使用SQLCLR來解析HTML
我寫這一次解析ContHist注意到了的一個例子
例如,
GoldMine 9。0
SQLCLR函數(C#)
[SqlFunction()]
public static SqlString RemoveHTML(SqlString html)
{
if (!html.IsNull)
{
string remove_style = @"\<STYLE((\S|\ |\s)+?)\<\/STYLE\>";
string remove_html = @"(?></?\w+)(?>(?:[^>'""]+|'[^']*'|""[^""]*"")*)>";
string result = Regex.Replace(html.Value, remove_style, string.Empty, RegexOptions.IgnoreCase);
result = Regex.Replace(result, remove_html, string.Empty, RegexOptions.IgnoreCase);
return result;
}
else return new SqlString();
}
安裝到DB
USE YourDB
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
ALTER DATABASE YourDB SET TRUSTWORTHY ON
----
CREATE ASSEMBLY GMSQLCLRAPI
FROM 'DRIVE:\Path\To\DLL\dll_name.dll'
with permission_set = UNSAFE;
--
CREATE FUNCTION RemoveHTML(@html NVARCHAR(MAX))
RETURNS NVARCHAR(MAX) WITH EXECUTE AS CALLER
AS EXTERNAL NAME GMSQLCLRAPI.[CLSQLCLR.GMSQLCLRAPI].RemoveHTML
用法
select dbo.RemoveHTML(rfc822) from Mailbox
使用這種方法,您可以將SQLCLR函數中的正則表達式替換爲您自己的,它將爲您解析收件人。
和示例使用的GoldMine API的
實際上有相當多的代碼,我將提供幾件
С#包裝函數來調用readmail將GoldMine的API函數
public Dictionary<string, string> ReadMail(Dictionary<string, string> NVDictionary)
{
const string failure = "Failure to read email\n";
Int32 res;
Dictionary<string, string> result = null;
IntPtr nvc = import.GMW_NV_Create();
if (nvc == null) throw (new CLGMAPIException(failure + "Unable to create name/value container"));
try
{
foreach (KeyValuePair<string, string> kvp in NVDictionary)
{
import.GMW_NV_SetValue(nvc, kvp.Key, kvp.Value);
}
res = import.GMW_Execute("ReadMail", nvc);
if (res > 0)
{
int count = import.GMW_NV_Count(nvc);
result = new Dictionary<string, string>(count);
IntPtr ptr;
string name;
for (int i = 0; i < count; i++)
{
ptr = import.GMW_NV_GetNameFromIndex(nvc, i);
name = Marshal.PtrToStringAnsi(ptr);
ptr = import.GMW_NV_GetValue(nvc, name, string.Empty);
result[name] = Marshal.PtrToStringAnsi(ptr);
}
}
}
finally
{
import.GMW_NV_Delete(nvc);
}
switch (res)
{
case 0: throw (new CLGMAPIException(failure));
case -1: throw (new CLGMAPIException(failure + "Message is private"));
case -2: throw (new CLGMAPIException(failure + "Message not found, or cannot be loaded"));
case -3: throw (new CLGMAPIException(failure + "Exception"));
default:
break;
}
return result;
}
包裝用法
public GoldMineEmails(GoldMineAPI api, DataTable mailbox)
{
foreach (DataRow emailRow in mailbox.Rows)
{
var dict = new Dictionary<string, string>(3);
dict["MboxRecID"] = emailRow["recid"].ToString();
dict["History"] = "1";
try
{
var res = api.ReadMail(dict);
var email = new GoldMineEmail(res["To"], res["Cc"], res["Bcc"], res["Outgoing"])
{
body = res["Body"],
From = res["From"],
subject = res["Subject"],
user = res["User"]
};
this.Add(email);
}
catch
{
throw;
// error logging
}
}
}
我希望這有助於。 不要猶豫與我聯繫 - 我可以給你發送源代碼的例子
沒人?只是鏈接到博客文章或讓我知道這是不可能的,複雜或我應該嘗試在VB或C#...基本答案將不勝感激,只有自己有一個點從哪裏開始。 .. 謝謝! – 2013-04-05 14:57:38