首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >邮件垃圾邮件分类从标头中提取特征

邮件垃圾邮件分类从标头中提取特征
EN

Stack Overflow用户
提问于 2014-07-06 06:24:13
回答 1查看 1.3K关注 0票数 0

我正在尝试构建一个垃圾邮件分类器。我一直在阅读一些研究论文,在添加基于内容的功能的同时,我也试图为BCC收件人、主题、发件人等的数量添加标题字段功能,但是我被困在了一个特定的地方:

  • 我需要检查发件人域名地址的合法性。我正在用R编写我所有的代码,我不太确定如何使用R来检查它。
  • 我还试图提取X字段,这并不是一项困难的任务.然而,X-mailer的问题是,如果它不存在,那么它很好地表明电子邮件是垃圾邮件,然而,当垃圾邮件发送者试图混淆X-mailer并将其填充到混淆的文本时,我如何区分这两种类型的数据-混淆的X邮件内容和合法的X-mailer。
  • 类似地,我试图创建这样的特性:发送方域的"domain_legality“合法性、消息创建和接收的日期和时间的合法性、接收方的"IP_legality”IP和"sender_legality",这些都是不言而喻的。

我感谢你的时间和考虑。

下面是我的代码示例,我要做的是:

代码语言:javascript
复制
extract_header <- function(email.data){
  header.features <- data.frame(matrix(ncol = 13))
  email.regex <- "[[:alnum:].-]+@[[:alnum:].-]+" #regular expression to extract from email address
  colnames(header.features) <- c("rec_field_num_of_hops", "span_time", "domain_legality", "date_time_legality", "IP_legality", "sender_legality", "num_of_To_receivers", "num_of_CC_receivers", "num_of_BCC_receivers", "mail_agent", "email_subject", "date_received")
  for(i in 1:length(email.data)){
    #extracting the email address of the sender
    header.features$sender_legality[i] = str_match(email.data[[i]]$meta$author, email.regex)

    #the subject of the email
    header.features$email_subject[i] = email.data$meta$heading

    #number of To receipients of the email
    posToField = which(!is.na(str_match(email.data[[i]]$meta$header, ignore.case("^To:"))))
    if(length(posToField) > 0)
      header.features$num_of_To_receivers[i]  = sum(str_count(email.data[[i]]$meta$header[posToField], email.regex))
    else
      header.features$num_of_To_receivers[i]  = 0

    #number of people CC in the email
    posCCField = which(!is.na(str_match(email_corpus[[i]]$meta$header, ignore.case("^Cc:"))))
    if(length(posCCField) > 0)
      header.features$num_of_CC_receivers[i] = sum(str_count(email.data[[i]]$meta$header[posCCField], email.regex))
    else
      header.features$num_of_CC_receivers[i] = 0

    #number of the Bcc people in the email
    posBccField = which(!is.na(str_match(email_corpus[[i]]$meta$header, ignore.case("^Bcc:"))))
    if(length(posBccField) > 0)
      header.features$num_of_BCC_receivers[i] = sum(str_count(email.data[[i]]$meta$header[posBccField], email.regex))
    else
      header.features$num_of_BCC_receivers[i] = 0

    #number of email servers hopped by
    header.features$rec_field_num_of_hops[i] <- sum(str_count(email_corpus[[i]]$meta$header, "^Received: from"))

  }
}

我现正按照研究报告所载的方法:

  • 一种可扩展的、基于非内容的垃圾邮件过滤框架
  • 识别用于电子邮件垃圾邮件过滤的可能有用的电子邮件头功能

我需要检查电子邮件的发件人是否是合法的发送者,这样做的理由是大多数情况下垃圾邮件发送者伪造他们的电子邮件地址,而这一特殊功能有助于识别电子邮件是否是垃圾邮件。

标题:

代码语言:javascript
复制
From rpm-list-admin@freshrpms.net  Tue Oct  8 10:56:20 2002
Return-Path: <rpm-zzzlist-admin@freshrpms.net>
Delivered-To: zzzz@localhost.example.com
Received: from localhost (jalapeno [127.0.0.1])
    by example.com (Postfix) with ESMTP id 79DB116F16
    for <zzzz@localhost>; Tue,  8 Oct 2002 10:56:20 +0100 (IST)
Received: from jalapeno [127.0.0.1]
    by localhost with IMAP (fetchmail-5.9.0)
    for zzzz@localhost (single-drop); Tue, 08 Oct 2002 10:56:20 +0100 (IST)
Received: from egwn.net (ns2.egwn.net [193.172.5.4]) by
    dogma.slashnull.org (8.11.6/8.11.6) with ESMTP id g988mPK07565 for
    <zzzz-rpm@example.com>; Tue, 8 Oct 2002 09:48:25 +0100
Received: from auth02.nl.egwn.net (localhost [127.0.0.1]) by egwn.net
    (8.11.6/8.11.6/EGWN) with ESMTP id g988i1f16827; Tue, 8 Oct 2002 10:44:02
    +0200
Received: from chip.ath.cx (cs146114.pp.htv.fi [213.243.146.114]) by
    egwn.net (8.11.6/8.11.6/EGWN) with ESMTP id g988hGf13093 for
    <rpm-list@freshrpms.net>; Tue, 8 Oct 2002 10:43:16 +0200
Received: from chip.ath.cx (localhost [127.0.0.1]) by chip.ath.cx
    (8.12.5/8.12.2) with ESMTP id g988hASA018848 for <rpm-list@freshrpms.net>;
    Tue, 8 Oct 2002 11:43:10 +0300
Received: from localhost (pmatilai@localhost) by chip.ath.cx
    (8.12.5/8.12.5/Submit) with ESMTP id g988h9j2018844 for
    <rpm-list@freshrpms.net>; Tue, 8 Oct 2002 11:43:10 +0300
X-Authentication-Warning: chip.ath.cx: pmatilai owned process doing -bs
From: Panu Matilainen <pmatilai@welho.com>
X-X-Sender: pmatilai@chip.ath.cx
To: rpm-zzzlist@freshrpms.net
Subject: Re: a problem with apt-get
In-Reply-To: <Pine.LNX.4.44.0210071231560.4199-100000@urgent.rug.ac.be>
Message-Id: <Pine.LNX.4.44.0210081140130.18762-100000@chip.ath.cx>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Mailscanner: Found to be clean, Found to be clean
Sender: rpm-zzzlist-admin@freshrpms.net
Errors-To: rpm-zzzlist-admin@freshrpms.net
X-Beenthere: rpm-zzzlist@freshrpms.net
X-Mailman-Version: 2.0.11
Precedence: bulk
Reply-To: rpm-zzzlist@freshrpms.net
List-Help: <mailto:rpm-zzzlist-request@freshrpms.net?subject=help>
List-Post: <mailto:rpm-zzzlist@freshrpms.net>
List-Subscribe: <http://lists.freshrpms.net/mailman/listinfo/rpm-zzzlist>,
    <mailto:rpm-list-request@freshrpms.net?subject=subscribe>
List-Id: Freshrpms RPM discussion list <rpm-zzzlist.freshrpms.net>
List-Unsubscribe: <http://lists.freshrpms.net/mailman/listinfo/rpm-zzzlist>,
    <mailto:rpm-list-request@freshrpms.net?subject=unsubscribe>
List-Archive: <http://lists.freshrpms.net/pipermail/rpm-zzzlist/>
X-Original-Date: Tue, 8 Oct 2002 11:43:09 +0300 (EEST)
Date: Tue, 8 Oct 2002 11:43:09 +0300 (EEST)

我希望这些额外的细节能有所帮助。谢谢你的帮助:)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-06 10:15:40

这个问题很笼统,但我会尝试给出一些建议。

首先,您应该考虑分层地构造分类器。也就是说:建立独立的分类器来处理特定的问题,例如日期、x邮件等各种参数的合法性。

在每个子分类器的上下文中,您将能够更容易地使用域知识和调试代码,而不是一起解决所有这些问题。

例如,让我们将重点放在将混淆的文本从合法的x-mailer中分离出来。

看看一堆例子,您可能会得到一些关于寻找什么来识别垃圾的洞察力。例如:字段长度、字符分布(对于乱码文本可能更好)、已知的有效x邮件列表等。

基于这些洞察力,你可以建立一个分类器:提取相关的特征,训练,测试等。

一旦您满意地解决了这个问题,您就可以使用这个分类器的输出作为对更一般的垃圾邮件过滤器的输入。如果这样做,最好让这个子分类器提取一个数字的可信度度量,而不仅仅是一个布尔值,这样一般的分类器就会有更多的信息。

此时的另一个选择是将您发现正在工作的特性添加到更通用的分类器的一组特性中,并让它与其他特性一起用于分类。

这种方法可以更好地解释您的特性之间更复杂的交互。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24593265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档