过滤邮箱
continuous-integration/drone/push Build is passing Details

于相涌/mail
YXY 1 year ago
parent 9c6507a7c9
commit e207b3cbda

@ -32,6 +32,11 @@ public class MailInfo extends BaseEntity {
/** 收件箱地址 */ /** 收件箱地址 */
private String mailReceiveFolder; private String mailReceiveFolder;
/** 邮件来源名称 */
private String sourceName;
/** /**
* @see com.ruoyi.common.enums.FlagStatus * @see com.ruoyi.common.enums.FlagStatus
*/ */

@ -6,6 +6,7 @@ import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper;
import com.ruoyi.flyingbook.domain.Event; import com.ruoyi.flyingbook.domain.Event;
import com.ruoyi.flyingbook.domain.EventLog; import com.ruoyi.flyingbook.domain.EventLog;
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest; import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
import com.ruoyi.flyingbook.mail.request.MailRequest;
import com.ruoyi.flyingbook.mapper.EventLogMapper; import com.ruoyi.flyingbook.mapper.EventLogMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
@ -34,7 +35,7 @@ public class MailHelper {
@Autowired @Autowired
private EventLogMapper eventLogMapper; private EventLogMapper eventLogMapper;
protected void parseMsg(Message[] messages,LarkTableRequest add) { protected void parseMsg(Message[] messages, LarkTableRequest add, MailRequest req) {
log.info("------------------------开始解析邮件----------------------------------"); log.info("------------------------开始解析邮件----------------------------------");
/** /**
@ -47,12 +48,16 @@ public class MailHelper {
log.info("----------------------------------------------------------"); log.info("----------------------------------------------------------");
String from = MimeUtility.decodeText(message.getFrom()[0].toString()); String from = MimeUtility.decodeText(message.getFrom()[0].toString());
InternetAddress internetAddress = new InternetAddress(from); InternetAddress internetAddress = new InternetAddress(from);
String receiveAddress = this.getReceiveAddress(message, null);
if (!from.contains(req.getSourceName())){
continue;
}
msgSubject = String.format("主题:%s,发件人:%s(%s),收件人:%s", msgSubject = String.format("主题:%s,发件人:%s(%s),收件人:%s",
message.getSubject(), message.getSubject(),
internetAddress.getPersonal(), internetAddress.getPersonal(),
internetAddress.getAddress(), internetAddress.getAddress(),
this.getReceiveAddress(message,null)); receiveAddress);
String recordId = syncLarkTable(message,add); String recordId = syncLarkTable(message,add,req.getSourceName());
this.buildLog(logs,msgSubject,recordId,null); this.buildLog(logs,msgSubject,recordId,null);
message.setFlag(Flags.Flag.SEEN, true); message.setFlag(Flags.Flag.SEEN, true);
} catch (Exception e) { } catch (Exception e) {
@ -73,8 +78,9 @@ public class MailHelper {
addresss = msg.getRecipients(type); addresss = msg.getRecipients(type);
} }
if (addresss == null || addresss.length < 1) if (addresss == null || addresss.length < 1) {
return null; return null;
}
for (Address address : addresss) { for (Address address : addresss) {
InternetAddress internetAddress = (InternetAddress) address; InternetAddress internetAddress = (InternetAddress) address;
receiveAddress.append(internetAddress.toUnicodeString()).append(","); receiveAddress.append(internetAddress.toUnicodeString()).append(",");
@ -110,10 +116,11 @@ public class MailHelper {
logs.add(log); logs.add(log);
} }
private String syncLarkTable(Message message,LarkTableRequest add) throws MessagingException, IOException { private String syncLarkTable(Message message,LarkTableRequest add,String sourceName) throws MessagingException, IOException {
StringBuffer content = new StringBuffer(30); StringBuffer content = new StringBuffer(30);
getMailTextContent(message,content); getMailTextContent(message,content);
Map<String, Object> body = this.buildBody(message,content.toString()); Map<String, Object> body = this.buildBody(message,content.toString());
body.put("邮箱来源",sourceName);
add.setBody(body); add.setBody(body);
CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(add); CreateAppTableRecordRespBody respBody = larkTableHelper.addTableRecord(add);
return respBody.getRecord().getRecordId(); return respBody.getRecord().getRecordId();

@ -67,7 +67,7 @@ public class MailHttpHelper extends MailHelper{
folder.getUnreadMessageCount(), folder.getUnreadMessageCount(),
folder.getNewMessageCount(), folder.getNewMessageCount(),
folder.getDeletedMessageCount()); folder.getDeletedMessageCount());
this.parseMsg(messages,add); this.parseMsg(messages,add,req);
} catch (Exception e) { } catch (Exception e) {
log.error("邮件解析失败",e); log.error("邮件解析失败",e);
} finally { } finally {
@ -90,7 +90,7 @@ public class MailHttpHelper extends MailHelper{
@Override @Override
protected Map<String, Object> buildBody(Message message,String content) { protected Map<String, Object> buildBody(Message message,String content) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
Integer index = 0; Integer index = 1;
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
for (String s : content.split("")) { for (String s : content.split("")) {
if (StringUtils.isNotBlank(str) && s.equals(" ")){ if (StringUtils.isNotBlank(str) && s.equals(" ")){
@ -112,34 +112,27 @@ public class MailHttpHelper extends MailHelper{
map.put("信息完成度",null); map.put("信息完成度",null);
map.put("数据来源",null); map.put("数据来源",null);
map.put("所属学校",null); map.put("所属学校",null);
map.put("邮箱来源",null);
// if (index > 6){
// map.clear();
// }
map.put("原始线索",content); map.put("原始线索",content);
return map; return map;
} }
private void fillMap(Map<String, Object> map,String msg,Integer index){ private void fillMap(Map<String, Object> map,String msg,Integer index){
switch (index){ switch (index){
case 0:
map.put("学生姓名",msg);
break;
case 1: case 1:
map.put("省市",msg); map.put("学生姓名",msg);
break; break;
case 2: case 2:
map.put("现有学历",msg); map.put("省市",msg);
break; break;
case 3: case 3:
map.put("手机号码",msg); map.put("现有学历",msg);
break; break;
case 4: case 4:
map.put("手机号码",msg);
break; break;
case 5: case 5:
map.put("目标国家",msg);
break; break;
case 6: case 6:
map.put("备注",msg); map.put("目标国家",msg);
break; break;
default: default:
break; break;

@ -26,7 +26,7 @@ public class MailTencentHelper {
public static void main(String[] args) { public static void main(String[] args) {
MailTencentHelper mailHelper = new MailTencentHelper(); MailTencentHelper mailHelper = new MailTencentHelper();
MailRequest req = new MailRequest("imap.qq.com",993,"932687738","ohziejkxqvsgbbag"); MailRequest req = new MailRequest("imap.qq.com",993,"932687738","ohziejkxqvsgbbag","新梦想");
mailHelper.receiveMail(req); mailHelper.receiveMail(req);
} }
@ -64,14 +64,12 @@ public class MailTencentHelper {
//获得收件箱的邮件列表 //获得收件箱的邮件列表
Message[] messages = folder.search(flagTerm); Message[] messages = folder.search(flagTerm);
// 打印不同状态的邮件数量 // 打印不同状态的邮件数量
log.info("收件箱中共{}封邮件!\n共{}封未读邮件!\n共{}封新邮件!\n共{}封已删除邮件!",
messages.length,
folder.getUnreadMessageCount(),
folder.getNewMessageCount(),
folder.getDeletedMessageCount());
log.info("------------------------开始解析邮件----------------------------------"); log.info("------------------------开始解析邮件----------------------------------");
for (int i = 0; i < messages.length; i++) { for (int i = 0; i < messages.length; i++) {
Message message = messages[i]; Message message = messages[i];
if (!message.getSubject().contains(req.getSourceName())){
continue;
}
parseMsg(message); parseMsg(message);
//设置已读 //设置已读
message.setFlag(Flags.Flag.SEEN,true); message.setFlag(Flags.Flag.SEEN,true);

@ -41,6 +41,10 @@ public class MailRequest {
* INBOX * INBOX
*/ */
private String receiveFolder; private String receiveFolder;
/** 邮件来源名称 */
private String sourceName;
/** /**
* *
*/ */
@ -54,11 +58,12 @@ public class MailRequest {
} }
} }
public MailRequest(String emailServer, Integer emailPort, String userName, String authorizationCode) { public MailRequest(String emailServer, Integer emailPort, String userName, String authorizationCode,String sourceName) {
this.emailServer = emailServer; this.emailServer = emailServer;
this.emailPort = emailPort; this.emailPort = emailPort;
this.userName = userName; this.userName = userName;
this.authorizationCode = authorizationCode; this.authorizationCode = authorizationCode;
this.sourceName = sourceName;
this.fillDefault(Boolean.TRUE); this.fillDefault(Boolean.TRUE);
} }
@ -70,5 +75,6 @@ public class MailRequest {
this.emailProtocol = info.getMailProtocol(); this.emailProtocol = info.getMailProtocol();
this.receiveFolder = info.getMailReceiveFolder(); this.receiveFolder = info.getMailReceiveFolder();
this.readFeedback = Boolean.TRUE.equals(readFeedback); this.readFeedback = Boolean.TRUE.equals(readFeedback);
this.sourceName = info.getSourceName();
} }
} }

@ -13,6 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="mailUserName" column="mail_user_name" /> <result property="mailUserName" column="mail_user_name" />
<result property="mailAuthorizationCode" column="mail_authorization_code" /> <result property="mailAuthorizationCode" column="mail_authorization_code" />
<result property="mailReceiveFolder" column="mail_receive_folder" /> <result property="mailReceiveFolder" column="mail_receive_folder" />
<result property="sourceName" column="source_name" />
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
@ -22,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectMailInfoVo"> <sql id="selectMailInfoVo">
select id,lark_table_id, mail_server, mail_port, mail_protocol, mail_user_name, mail_authorization_code, mail_receive_folder, create_by, create_time, update_by, update_time, flag, remark from mail_info select id,lark_table_id, mail_server, mail_port, mail_protocol, mail_user_name, mail_authorization_code, mail_receive_folder,source_name, create_by, create_time, update_by, update_time, flag, remark from mail_info
</sql> </sql>
<select id="selectMailInfoList" parameterType="com.ruoyi.flyingbook.domain.MailInfo" resultMap="MailInfoResult"> <select id="selectMailInfoList" parameterType="com.ruoyi.flyingbook.domain.MailInfo" resultMap="MailInfoResult">
@ -35,6 +36,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mailUserName != null and mailUserName != ''"> and mail_user_name like concat('%', #{mailUserName}, '%')</if> <if test="mailUserName != null and mailUserName != ''"> and mail_user_name like concat('%', #{mailUserName}, '%')</if>
<if test="mailAuthorizationCode != null and mailAuthorizationCode != ''"> and mail_authorization_code = #{mailAuthorizationCode}</if> <if test="mailAuthorizationCode != null and mailAuthorizationCode != ''"> and mail_authorization_code = #{mailAuthorizationCode}</if>
<if test="mailReceiveFolder != null and mailReceiveFolder != ''"> and mail_receive_folder = #{mailReceiveFolder}</if> <if test="mailReceiveFolder != null and mailReceiveFolder != ''"> and mail_receive_folder = #{mailReceiveFolder}</if>
<if test="sourceName != null and sourceName != ''"> and source_name = #{sourceName}</if>
<if test="flag != null "> and flag = #{flag}</if> <if test="flag != null "> and flag = #{flag}</if>
</where> </where>
</select> </select>
@ -54,6 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mailUserName != null and mailUserName != ''">mail_user_name,</if> <if test="mailUserName != null and mailUserName != ''">mail_user_name,</if>
<if test="mailAuthorizationCode != null and mailAuthorizationCode != ''">mail_authorization_code,</if> <if test="mailAuthorizationCode != null and mailAuthorizationCode != ''">mail_authorization_code,</if>
<if test="mailReceiveFolder != null">mail_receive_folder,</if> <if test="mailReceiveFolder != null">mail_receive_folder,</if>
<if test="sourceName != null">source_name,</if>
<if test="createBy != null and createBy != ''">create_by,</if> <if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if> <if test="updateBy != null">update_by,</if>
@ -69,6 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mailUserName != null and mailUserName != ''">#{mailUserName},</if> <if test="mailUserName != null and mailUserName != ''">#{mailUserName},</if>
<if test="mailAuthorizationCode != null and mailAuthorizationCode != ''">#{mailAuthorizationCode},</if> <if test="mailAuthorizationCode != null and mailAuthorizationCode != ''">#{mailAuthorizationCode},</if>
<if test="mailReceiveFolder != null">#{mailReceiveFolder},</if> <if test="mailReceiveFolder != null">#{mailReceiveFolder},</if>
<if test="sourceName != null">#{sourceName},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if> <if test="updateBy != null">#{updateBy},</if>
@ -88,6 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mailUserName != null and mailUserName != ''">mail_user_name = #{mailUserName},</if> <if test="mailUserName != null and mailUserName != ''">mail_user_name = #{mailUserName},</if>
<if test="mailAuthorizationCode != null and mailAuthorizationCode != ''">mail_authorization_code = #{mailAuthorizationCode},</if> <if test="mailAuthorizationCode != null and mailAuthorizationCode != ''">mail_authorization_code = #{mailAuthorizationCode},</if>
<if test="mailReceiveFolder != null">mail_receive_folder = #{mailReceiveFolder},</if> <if test="mailReceiveFolder != null">mail_receive_folder = #{mailReceiveFolder},</if>
<if test="sourceName != null">source_name = #{sourceName},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if> <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if> <if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if> <if test="updateBy != null">update_by = #{updateBy},</if>

Loading…
Cancel
Save