outlook电子邮件解析
This is an Add-On procedure to be used in conjunction with the code provided in Reducing EE Email Clutter using Outlook, because it uses the "tagging system" of that article.
这是一个附加过程,可与使用Outlook减少EE电子邮件混乱中提供的代码结合使用 ,因为它使用了该文章的“标记系统”。
Purpose
目的
Imagine the following situation: You have read the prior article, and implemented the code provided, and your EE Email is organized in a better way now. Maybe you even used conditional colouring to emphasize specific topics.
想象一下以下情况:您已阅读上一篇文章,并实现了所提供的代码,并且现在以更好的方式组织了EE电子邮件。 也许您甚至使用条件着色来强调特定主题。
But you have still 500 notification mails for the last 4 days in your inbox informing you about new questions you have set a filter for, or neglected questions of areas you are a Designated Expert in. You pick one or another of those questions, maybe posted the prior day already, to provide suggestions. You go into the questions, and find them answered and closed already.
但是收件箱中的最后4天仍然有500封通知邮件,通知您有关您设置了过滤器的新问题或您是指定专家所在领域的被忽略的问题。您可以选择其中一个或另一个,也许是已发布已在前一天提供建议。 您进入问题,
Well, that can't happen anymore, if you apply this code on all or some of your questions! It will go thru the (EE assigned) inbox completely (if nothing is selected), or only thru the selected posts, and look whether the question is already closed or deleted. If so, it is removed from the inbox, and you can be sure about each remaining question being worth to have a look into it.
好吧,如果您对所有或部分问题应用此代码,就不可能再发生了! 它会完全通过(分配给EE的)收件箱(如果未选择任何内容),或者仅通过选定的帖子,然后查看问题是否已关闭或删除。 如果是这样,则将其从收件箱中删除,并且您可以确定每个剩余的问题都值得一看。
For Page Editors: The code also checks for deleted articles, and removes the notif then. It is more difficult to extend to check for the other states, like Editor or Author Review, or (Re-)Published, since that is not reflected in the printer-friendly version.
对于页面编辑器 :该代码还将检查已删除的文章,然后删除该notif。 扩展检查其他状态(例如“编辑器”或“作者审阅”或“(重新)发布”)会更加困难,因为这不会反映在易于打印的版本中。
Inside the code
代码内
Since it isn't much of code, I'll provide it "inline" here. But before you can use it, you need to put
由于代码不是很多,因此我将在此处“内联”提供它。 但是在使用之前,您需要先放置
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliSeconds As Long)
In addition you need to add a reference to IE. While in the VBA Editor, choose Extras » References, search for "Microsoft Internet Controls" and tick it. That allows us to use Early Binding of Internet Explorer, that is we can directly access its properties. For a property description, see MSDN.
另外,您需要添加对IE的引用。 在VBA编辑器中,选择“其他»参考” ,搜索“ Microsoft Internet控件”并勾选它。 这使我们可以使用Internet Explorer的Early Binding,即我们可以直接访问其属性。 有关属性的描述,请参见MSDN 。
Sub CheckForClosed()
Static Web As InternetExplorer
Dim pos0, pos1 As Integer
Dim str, c As String
Dim Sel
Dim ml As MailItem
Dim q#, del#, sol#
Dim isArticle As Boolean
If Web Is Nothing Or TypeName(Web) <> "IWebBrowser2" Then Set Web = CreateObject("InternetExplorer.Application")
' Web.Visible = True
Set Sel = myOlEEItems
If Outlook.ActiveExplorer.Selection.Count > 0 Then
If TypeName(Outlook.ActiveExplorer.Selection.item(1)) = "MailItem" Then
Set Sel = Outlook.ActiveExplorer.Selection
End If
End If
For Each ml In Sel
str = ""
On Error Resume Next
str = ml.UserProperties("Reference")
q# = q# + 1
On Error GoTo 0
If str <> "" Then
isArticle = (Left(str, 1) = "A")
If isArticle Then
str = "http://e-e.com/viewArticlePrinterFriendly.jsp?articleID=" & Mid$(str, 3)
Else
str = "http://e-e.com/viewQuestionPrinterFriendly.jsp?qid=" & Mid$(str, 3)
End If
Web.Navigate (str)
While Web.ReadyState <> READYSTATE_COMPLETE: Sleep 10: Wend
str = LCase(Left$(Web.Document.Body.InnerHtml, 2000))
If isArticle Then
str = Mid$(str, InStr(str, "<div class=""postabletype"">") + Len("<div class=""postabletype"">"))
Else
str = Mid$(str, InStr(str, "<div class=""questiontype"">") + Len("<div class=""questiontype"">"))
End If
str = Left$(str, InStr(str, "</div>") - 1)
str = Trim(Replace(str, Chr(10), ""))
c = "."
If str = "solution" Then ml.Delete: sol# = sol# + 1: c = "+"
If str = "<span style=""color: #ff0000"">deleted</span> question" Then ml.Delete: del# = del# + 1: c = "-"
If str = "<span style=""color: #ff0000"">deleted</span> article" Then ml.Delete: del# = del# + 1: c = "-"
Debug.Print c;
End If
Next
Debug.Print Chr(13) & "Q: " & q# & " Solved: " & sol# & " Deleted: " & del#
Web.Quit
Set Web = Nothing
End Sub
Each page then is parsed for the question (or article) header, which tells us if it is closed or deleted.
然后解析每个页面的问题(或文章)标题,该标题告诉我们页面是关闭还是删除。
After all (selected) mails have been processed, the debugger output presents a summary of the amount of questions processed, and how many of them were solved or deleted. You will see that only in the Direct Window of the VBA Editor, which you can switch on by pressing Ctrl-G.
在处理完所有(选定的)邮件之后,调试器的输出将汇总显示已处理问题的数量以及已解决或删除了多少个问题。 您将仅在VBA编辑器的“直接窗口”中看到该内容,您可以通过按Ctrl-G来打开它。
"Obvious" Improvements
“明显”的改进
This macro uses an synchronous approach, processing only one question at any time. It could have been done asynchronous, by using more than one IE (or IE Tab), and corresponding Event handlers, processing a shared queue. The result could be a "multi-threaded" processing of more than one question in-parallel.
该宏使用一种同步方法,可以随时仅处理一个问题。 通过使用多个IE(或IE Tab)和相应的事件处理程序来处理共享队列,它可以异步完成。 结果可能是并行处理多个问题的“多线程”处理。
I have to admit I tried that, but it is too complex because of the limitations Outlook, VBA and the InternetExplorer Events impose. For example you can't get DocumentComplete Events for each tab if using a tabbed browser – only the first tab's events are catched. And changing that requires to use one browser per question, and one event handler per browser – which again requires you to have a static setup of those. Feasible, but cumbersome.
我必须承认我尝试过,但是由于Outlook,VBA和InternetExplorer Events施加的限制,它太复杂了。 例如,如果使用选项卡式浏览器,则无法获取每个选项卡的DocumentComplete事件-仅捕获第一个选项卡的事件。 更改要求每个问题使用一个浏览器,每个浏览器使用一个事件处理程序,这又需要您对这些问题进行静态设置。 可行,但麻烦。
It would be great if you could limit the amount of data retrieved for displaying a page. As-is, the code has to retrieve the full printer-friendly rendered thread, just to read the top let's say 500 bytes.
如果可以限制为显示页面而检索的数据量,那将是很好的。 照原样,该代码必须检索完整的打印机友好渲染线程,仅读取顶部(假设500字节)即可。
outlook电子邮件解析