在电子邮件会话正文中检测新消息的结尾 [英] Detect end of new message in email conversation body

查看:94
本文介绍了在电子邮件会话正文中检测新消息的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当邮件被回复或被转发时,通过在其前面放置---- Original Message ----,将先前的线程附加到新邮件上.

When a message gets replied or forwared the previous thread gets appended on your new mail by placing i.e. ----Original Message---- in front of it.

Outlook对tekst消息执行相同的操作,但是对于HTML邮件,它显示一行,其后跟发件人:..

Outlook does the same with tekst messages but with HTML mails it shows a line followed with From:..

由于Outlook在这些消息之间显示了一条界线,因此我相信可以使用VBA减去这些消息.但是如何?

Since outlook shows a line in between these messages i believe it's possible to subtract these messages using VBA. But How?

目标:当用户发送邮件(Application_ItemSend)时,我要扫描邮件中的某些单词.但是我不在乎它是否出现在上一条消息中,我只想扫描新键入的消息.

Goal: When the user sends a mail (Application_ItemSend) I want to scan the message for certain words. But I don't care if it occurs in a previous message, i only want to scan the newly typed message.

当在Outlook中以文本形式(而Outlook是英语!)答复电子邮件时,以下示例将起作用.但是在发送HTML电子邮件时将无法正常工作.

The example below will work when answering an email in outlook when it's in text (and outlook is in english!). But it will NOT work when sending a HTML email.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  Dim EndOfMsg As Integer
  Dim myMsg as String

  EndOfMsg = InStr(Item.Body, "-----Original Message-----")
  If EndOfMsg = 0 Then 
    myMsg = Item.Body
  Else 
    myMsg = Left(Item.Body, EndOfMsg)
  End If

  MsgBox myMsg
End Sub

因此,我需要一些令牌"来拆分,更正..但是,此令牌是什么? myMsg和较旧的味精之间只有一个双vbCrLf.就像我在消息中输入新行时一样..完全没有任何独特之处!

So i need some 'token' to split on, correct.. But what is this token? All there is between myMsg and the older msg's is a double vbCrLf. The same as when i enter a new line in my message.. no nothing at all unique!

推荐答案

答案取决于用户是发送HTML还是富文本电子邮件. (这通常取决于他们是否回复/转发HTML或RTF消息,除非他们手动更改格式.)

The answer depends on whether the user is sending HTML or rich text email. (This will usually depend on whether they are replying to/forwarding a message in HTML or RTF, unless they manually change the format.)

在任何一种情况下,您都需要查找一个模式,该模式指示您感兴趣的消息的结尾,然后在此处停止.使用Instr()标识您需要在哪里停下来.然后,在解析文本以查找某些单词"时,请跟踪已读的字符数,并在到达标记时停止.

In either case, you need to look for a pattern that indicates the end of the message you are interested in, and stop there. Use Instr() to identify where you need to stop. Then, as you are parsing the text looking for your "certain words", keep track of how many characters you have read and stop when you get to the marker.

富文本

Item.Body中查找"^ p ^ p_ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ ___ ^ p".

Look in Item.Body for "^p^p__________________________ ^p".

这是VbCrLf的2个实例,Chr(95)的46个实例,一个空格,然后是VbCrLf的另一个实例.

That's 2 instances of VbCrLf, 46 instances of Chr(95), a space, and then another instance of VbCrLf.

HTML

Item.Body中,令牌为"^ p _ ^ p".

In Item.Body, the token is "^p  _  ^p".

那是一个VbCrLf,2个空格,5个Chr(95)实例,另外2个空格和另一个VbCrLf.

That's one VbCrLf, 2 spaces, 5 instances of Chr(95), 2 more spaces, and another VbCrLf.

Item.HTMLBody中,令牌为

<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>

该令牌在其前面,两行之间以及最后都有一个VbCrLf.

That token has a VbCrLf before it, between the two lines, and at the end.

这篇关于在电子邮件会话正文中检测新消息的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆