The MailEntityProcessor
邮件处理程序使用Java邮件API使用IMAP协议对电子邮件消息进行索引。
MailEntityProcessor的工作原理是:使用用户名和密码连接到指定的邮箱,为每封邮件提取电子邮件头,然后提取完整的电子邮件内容以构建一个文档(每封邮件一个文档)。
MailEntityProcessor特有的实体属性如下所示。除了上述所有实体处理器所共有的属性之外,这些属性也是相同的。
processor
必需的。必须设置为MailEntityProcessor。
user
必需的。验证到IMAP服务器的用户名;IMAP服务器通常是邮箱所有者的电子邮件地址。
password
必需的。验证到IMAP服务器的密码。
host
必需的。要连接的IMAP服务器。
protocol
必需的。要使用的IMAP协议,有效值为:IMAP、IMAP、GIMAP和GIMAPS。
fetchMailsSince
可选的。用于设置筛选器以导入在指定日期之后发生的邮件的日期/时间;预期格式为:yyyy-mm-dd hh:mm:ss。
folders
必需的。要从中提取邮件的文件夹名称列表(以逗号分隔),如“(inbox)收件箱”。
recurse
可选的。默认值为true。标识是否递归子目录。
include
可选的。处理文件夹时要包含的文件夹模式的逗号分隔列表(可以是文字值或正则表达式)。
exclude
可选。处理文件夹时要排除的文件夹模式的逗号分隔列表(可以是文字值或正则表达式)。排除的文件夹模式优先于包含文件夹模式。
processAttachement or processAttachments
可选的。默认值为true。使用tika处理邮件附件。
includeContent
可选的。默认值为true。在构建用于索引的solr文档时包含消息体。 Include the message body when constructing Solr documents for indexing。
Here is an example from the mail collection of the dih example (data-config file found at example/example-DIH/mail/conf/mail-data-config.xml):
<?xml version="1.0" encoding="utf-8"?>
<dataConfig>
<document>
<entity processor="MailEntityProcessor" user="email@gmail.com" password="password" host="imap.gmail.com" protocol="imaps" fetchMailsSince="2014-06-30 00:00:00" batchSize="20" folders="inbox" processAttachement="false" name="mail_entity"/>
</document>
</dataConfig>
验证备注:
<dataConfig>
<document>
<!--
Note - In order to index attachments, set processAttachement="true" and drop
Tika and its dependencies to example-DIH/solr/mail/lib directory
-->
<!--<entity processor="MailEntityProcessor" user="email@gmail.com"
password="password" host="imap.gmail.com" protocol="gimaps"
fetchMailsSince="2014-06-30 00:00:00" batchSize="20" folders="inbox" processAttachement="false"
name="mail_entity"/>
-->
<entity processor="MailEntityProcessor" user="329656576@qq.com" password="替换正确" host="imap.qq.com" protocol="imaps" fetchMailsSince="2014-06-30 00:00:00" batchSize="20" folders="inbox" processAttachement="false" name="mail_entity">
</entity>
</document>
</dataConfig>
测试中使用qq,需要设置imaps协议。password中得到。
managed-schema注意设置
<field name="content" type="text_general" indexed="true" stored="true" multiValued="true"/>
<!-- catchall field, containing all other searchable text fields (implemented
via copyField further on in this schema -->
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
<field name="messageId" type="string" indexed="true" stored="true" required="true" multiValued="false"/>
<field name="subject" type="text_general" indexed="true" stored="true"/>
<field name="from" type="string" indexed="true" stored="true" omitNorms="true"/>
<field name="sentDate" type="pdate" indexed="true" stored="true"/>
<field name="xMailer" type="string" indexed="true" stored="true" omitNorms="true"/>
<field name="allTo" type="string" indexed="true" stored="true" omitNorms="true" multiValued="true"/>
<field name="flags" type="string" indexed="true" stored="true" omitNorms="true" multiValued="true"/>
<field name="attachment" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="attachmentNames" type="string" indexed="true" stored="true" omitNorms="true" multiValued="true"/>
参考
https://wiki.apache.org/solr/MailEntityProcessor