- 浏览: 2560005 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Mail Solution with Content.IO
1. Introduction
The develop console is here
https://console.context.io
The API key and secret are here
https://console.context.io/#settings/keys
Lite API will be more powerful for web hook. 2.0 API will be more powerful to filter lists of historical messages.
2. Start from 2.0 API
Here is the clients.
https://context.io/docs/2.0/libraries
I directly go to there console and try the “explore”. This should work for me.
subject = /sillycat post ([0-9]*): (.*)$/
email = gmail.com
filename = /(.*?)\.(pdf|doc|docx|DOC|DOCX|PDF)$/
I will go on trying the nodeJS client library.
https://github.com/contextio/ContextIO-node
Based on the nodeJS API, here are some codes
fetchAccountInfoByEmail : function(email, callback) {
var logger = services.get('logger');
var cxtioClient = this.cxtioClient;
logger.trace("EmailScan - fetchAccountInfoByEmail - email = " + email);
cxtioClient.accounts().get({ "email": email}, function(err, data){
if(err){
logger.error("EmailScan - fetchAccountInfoByEmail - fail to fetch the account info.");
callback(err, null);
return ;
}
if(data){
logger.trace("EmailScan - fetchAccountInfoByEmail - get the account info with key = " + email);
logger.trace("EmailScan - fetchAccountInfoByEmail - get response info = " + JSON.stringify(data));
var msgBody = data.body;
logger.trace("EmailScan - fetchAccountInfoByEmail - get message body = " + JSON.stringify(msgBody));
if(msgBody.length > 0){
var account = _.first(msgBody);
logger.trace("EmailScan - fetchAccountInfoByEmail - get account = " + JSON.stringify(account));
callback(null, { id: account.id } );
return ;
}else{
logger.trace("EmailScan - fetchAccountInfoByEmail - fail to fetch any account info with key = " + email);
callback(null,null);
return ;
}
}else{
logger.trace("EmailScan - fetchAccountInfoByEmail - fail to fetch any account info with key = " + email);
callback(null,null);
return ;
}
});
}
Scan the emails with some filters
fetchSillycatJobsByAccountId : function(accountId, pager, callback) {
var sillycatFilter = {
subject: ‘/sillycat post ([0-9]*): (.*)$/',
from: ‘robot@sillycat.ddns.org'
} ;
var filter = _.merge(sillycatFilter, pager);
this.fetchEmailsWithFilter(accountId, filter, callback);
}
Scan the emails with attachment
fetchSillycatResumesByAccountId : function(accountId, pager, callback) {
var sillycatFilter = {
file_name: '/(.*?)\.(pdf|doc|docx|DOC|DOCX|PDF)$/',
email: ’sillycat.org'
} ;
var filter = _.merge(sillycatFilter, pager);
this.fetchEmailsWithFilter(accountId, filter, callback);
},
Private Method provide here for previous methods.
fetchEmailsWithFilter : function(accountId, filter, callback){
var logger = services.get('logger');
var cxtioClient = this.cxtioClient;
logger.trace("EmailScan - fetchEmailsWithFilter - accountId = " + accountId);
logger.trace("EmailScan - fetchEmailsWithFilter - filter = " + JSON.stringify(filter));
cxtioClient.accounts(accountId).messages().get(filter, function(err, data){
if(err){
logger.error("EmailScan - fetchEmailsWithFilter - fail to fetch the messages.");
callback(err, null);
return ;
}
if(data){
logger.trace("EmailScan - fetchEmailsWithFilter - get the messages info with filter = " + JSON.stringify(filter));
logger.trace("EmailScan - fetchEmailsWithFilter - get response info = " + JSON.stringify(data));
var msgBody = data.body;
logger.trace("EmailScan - fetchEmailsWithFilter - get message body = " + JSON.stringify(msgBody));
if(msgBody.length > 0 ){
callback(null, msgBody);
return ;
}else{
logger.warn("EmailScan - fetchEmailsWithFilter - fail to fetch any messages with filter = " + JSON.stringify(filter));
return ;
}
}else{
logger.warn("EmailScan - fetchEmailsWithFilter - fail to fetch any messages with filter = " + JSON.stringify(filter));
return ;
}
});
}
Fetch the Email Content
fetchMailContent: function(accountId, messageId, callback) {
var logger = services.get('logger');
var cxtioClient = this.cxtioClient;
logger.trace("EmailScan - fetchMailContent - accountId = " + accountId);
logger.trace("EmailScan - fetchMailContent - messageId = " + messageId);
cxtioClient.accounts(accountId).messages(messageId).body().get(function(err, data){
if(err){
logger.error("EmailScan - fetchMailContent - fail to fetch the mail content.");
callback(err, null);
return ;
}
if(data){
logger.trace("EmailScan - fetchMailContent - get response info = " + JSON.stringify(data));
var msgBody = data.body;
logger.trace("EmailScan - fetchMailContent - get message body = " + JSON.stringify(msgBody));
if(msgBody.length > 0){
var contents = _.filter(msgBody, function(item){
return (item.type==='text/plain');
});
logger.trace("EmailScan - fetchMailContent - get any plain result = " + JSON.stringify(contents));
if(contents.length > 0){
logger.trace("EmailScan - fetchMailContent - return the text content.");
callback(null, _.first(contents));
return ;
}else{
logger.trace("EmailScan - fetchMailContent - return the html content or etc.");
callback(null,_.first(msgBody));
return ;
}
}
}else{
logger.warn("EmailScan - fetchMailContent - fail to fetch any email content.");
return ;
}
});
},
Fetch the Attachment Link
fetchAttachmentLink: function(accountId, fileId, callback){
var logger = services.get('logger');
var cxtioClient = this.cxtioClient;
logger.trace("EmailScan - fetchAttachmentLink - accountId = " + accountId);
logger.trace("EmailScan - fetchAttachmentLink - fileId = " + fileId);
cxtioClient.accounts(accountId).files(fileId).content().get({ as_link: 1 },function(err, data){
if(err){
logger.error("EmailScan - fetchAttachmentLink - fail to fetch the file link.");
callback(err, null);
return ;
}
if(data){
logger.trace("EmailScan - fetchAttachmentLink - get response info = " + JSON.stringify(data));
var link = data.body;
logger.trace("EmailScan - fetchAttachmentLink - get link = " + link);
callback(null, link);
return ;
}
});
},
References:
https://www.context.io/
https://context.io/docs/lite/quickstart
1. Introduction
The develop console is here
https://console.context.io
The API key and secret are here
https://console.context.io/#settings/keys
Lite API will be more powerful for web hook. 2.0 API will be more powerful to filter lists of historical messages.
2. Start from 2.0 API
Here is the clients.
https://context.io/docs/2.0/libraries
I directly go to there console and try the “explore”. This should work for me.
subject = /sillycat post ([0-9]*): (.*)$/
email = gmail.com
filename = /(.*?)\.(pdf|doc|docx|DOC|DOCX|PDF)$/
I will go on trying the nodeJS client library.
https://github.com/contextio/ContextIO-node
Based on the nodeJS API, here are some codes
fetchAccountInfoByEmail : function(email, callback) {
var logger = services.get('logger');
var cxtioClient = this.cxtioClient;
logger.trace("EmailScan - fetchAccountInfoByEmail - email = " + email);
cxtioClient.accounts().get({ "email": email}, function(err, data){
if(err){
logger.error("EmailScan - fetchAccountInfoByEmail - fail to fetch the account info.");
callback(err, null);
return ;
}
if(data){
logger.trace("EmailScan - fetchAccountInfoByEmail - get the account info with key = " + email);
logger.trace("EmailScan - fetchAccountInfoByEmail - get response info = " + JSON.stringify(data));
var msgBody = data.body;
logger.trace("EmailScan - fetchAccountInfoByEmail - get message body = " + JSON.stringify(msgBody));
if(msgBody.length > 0){
var account = _.first(msgBody);
logger.trace("EmailScan - fetchAccountInfoByEmail - get account = " + JSON.stringify(account));
callback(null, { id: account.id } );
return ;
}else{
logger.trace("EmailScan - fetchAccountInfoByEmail - fail to fetch any account info with key = " + email);
callback(null,null);
return ;
}
}else{
logger.trace("EmailScan - fetchAccountInfoByEmail - fail to fetch any account info with key = " + email);
callback(null,null);
return ;
}
});
}
Scan the emails with some filters
fetchSillycatJobsByAccountId : function(accountId, pager, callback) {
var sillycatFilter = {
subject: ‘/sillycat post ([0-9]*): (.*)$/',
from: ‘robot@sillycat.ddns.org'
} ;
var filter = _.merge(sillycatFilter, pager);
this.fetchEmailsWithFilter(accountId, filter, callback);
}
Scan the emails with attachment
fetchSillycatResumesByAccountId : function(accountId, pager, callback) {
var sillycatFilter = {
file_name: '/(.*?)\.(pdf|doc|docx|DOC|DOCX|PDF)$/',
email: ’sillycat.org'
} ;
var filter = _.merge(sillycatFilter, pager);
this.fetchEmailsWithFilter(accountId, filter, callback);
},
Private Method provide here for previous methods.
fetchEmailsWithFilter : function(accountId, filter, callback){
var logger = services.get('logger');
var cxtioClient = this.cxtioClient;
logger.trace("EmailScan - fetchEmailsWithFilter - accountId = " + accountId);
logger.trace("EmailScan - fetchEmailsWithFilter - filter = " + JSON.stringify(filter));
cxtioClient.accounts(accountId).messages().get(filter, function(err, data){
if(err){
logger.error("EmailScan - fetchEmailsWithFilter - fail to fetch the messages.");
callback(err, null);
return ;
}
if(data){
logger.trace("EmailScan - fetchEmailsWithFilter - get the messages info with filter = " + JSON.stringify(filter));
logger.trace("EmailScan - fetchEmailsWithFilter - get response info = " + JSON.stringify(data));
var msgBody = data.body;
logger.trace("EmailScan - fetchEmailsWithFilter - get message body = " + JSON.stringify(msgBody));
if(msgBody.length > 0 ){
callback(null, msgBody);
return ;
}else{
logger.warn("EmailScan - fetchEmailsWithFilter - fail to fetch any messages with filter = " + JSON.stringify(filter));
return ;
}
}else{
logger.warn("EmailScan - fetchEmailsWithFilter - fail to fetch any messages with filter = " + JSON.stringify(filter));
return ;
}
});
}
Fetch the Email Content
fetchMailContent: function(accountId, messageId, callback) {
var logger = services.get('logger');
var cxtioClient = this.cxtioClient;
logger.trace("EmailScan - fetchMailContent - accountId = " + accountId);
logger.trace("EmailScan - fetchMailContent - messageId = " + messageId);
cxtioClient.accounts(accountId).messages(messageId).body().get(function(err, data){
if(err){
logger.error("EmailScan - fetchMailContent - fail to fetch the mail content.");
callback(err, null);
return ;
}
if(data){
logger.trace("EmailScan - fetchMailContent - get response info = " + JSON.stringify(data));
var msgBody = data.body;
logger.trace("EmailScan - fetchMailContent - get message body = " + JSON.stringify(msgBody));
if(msgBody.length > 0){
var contents = _.filter(msgBody, function(item){
return (item.type==='text/plain');
});
logger.trace("EmailScan - fetchMailContent - get any plain result = " + JSON.stringify(contents));
if(contents.length > 0){
logger.trace("EmailScan - fetchMailContent - return the text content.");
callback(null, _.first(contents));
return ;
}else{
logger.trace("EmailScan - fetchMailContent - return the html content or etc.");
callback(null,_.first(msgBody));
return ;
}
}
}else{
logger.warn("EmailScan - fetchMailContent - fail to fetch any email content.");
return ;
}
});
},
Fetch the Attachment Link
fetchAttachmentLink: function(accountId, fileId, callback){
var logger = services.get('logger');
var cxtioClient = this.cxtioClient;
logger.trace("EmailScan - fetchAttachmentLink - accountId = " + accountId);
logger.trace("EmailScan - fetchAttachmentLink - fileId = " + fileId);
cxtioClient.accounts(accountId).files(fileId).content().get({ as_link: 1 },function(err, data){
if(err){
logger.error("EmailScan - fetchAttachmentLink - fail to fetch the file link.");
callback(err, null);
return ;
}
if(data){
logger.trace("EmailScan - fetchAttachmentLink - get response info = " + JSON.stringify(data));
var link = data.body;
logger.trace("EmailScan - fetchAttachmentLink - get link = " + link);
callback(null, link);
return ;
}
});
},
References:
https://www.context.io/
https://context.io/docs/lite/quickstart
发表评论
-
Stop Update Here
2020-04-28 09:00 322I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 484NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 374Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 375Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 345Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 436Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 444Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 381Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 463VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 394Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 487NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 432Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 342Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 254GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 455GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 332GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 318Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 324Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 302Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 315Serverless with NodeJS and Tenc ...
相关推荐
Macallan Mail Solution 是一款 POP3 、IMAP、SMTP、HTTP (webMail) 邮件服务器软件 ,它还包括了防垃圾邮件机制。 Macallan Mail Solution 免费邮件服务器 (SMTP/POP3/IMAP/HTTP/NEWS/SSL/Tunnel) 支持 ...
综上所述,"socket_io-express-solution-master"项目提供了一个使用Socket.IO和Express创建实时Web应用的模板。通过学习这个项目,你可以了解如何将这两个强大的工具结合,构建出具有实时通信功能的应用。这个解决...
Color_LJPro_MFP_M176_full-solution_15321.exe
### 标题解读:“Apress.Spring.Recipes.A.Problem.Solution.Approach.2nd.Edition” 这本书的标题表明了它的主要内容与Spring框架的应用实践密切相关。通过问题解决的方式介绍Spring框架的各种应用技巧(recipes)...
在本项目"module2-solution.github.io"中,主要涉及的是网页开发技术,特别是CSS(层叠样式表)的应用。CSS是网页设计的核心组成部分,它用于控制网页元素的布局、颜色、字体、大小等视觉效果,使网页更具美观性和易...
打印机驱动M1536,不错,很好用,32位版本,hp_M1530_MFP_Basic_Solution_15188.exe
【标题】"Module5-Solution.github.io" 指的可能是一个GitHub托管的项目,它通常代表一个在线课程或教程的第五个模块的解决方案。这个模块可能专注于通过GitHub Pages服务来展示项目成果,GitHub Pages允许用户免费...
HP_M125-126打印机驱动
【标题】"mysolution20.github.io" 是一个基于GitHub Pages建立的个人网站或博客,通常用于分享技术解决方案、编程知识或个人项目。这个压缩包文件 "mysolution20.github.io-master" 暗示了它是该网站的源代码仓库,...
"capture_solution.exe"是Capture Solution XE 10.43的可执行程序文件,用户可以通过双击安装。而"sshot-1.png"可能是软件的截图示例,展示了软件的界面或者功能特点,用户可以通过查看这张图片了解软件的基本操作和...
Cisco.Press.Cisco.CallManager.Fundamentals.A.Cisco.AVVID.Solution.2nd.Edition.Sep.2005.eBook-DDU
Footstepper Complete Footstep Solution 1.3.0a.unitypackage Footstepper Complete Footstep Solution 1.3.0a.unitypackage Footstepper Complete Footstep Solution 1.3.0a.unitypackage
在C#中,可以使用.NET框架的System.Net命名空间中的Socket类来实现网络通信,使用System.IO.Pipes或System.IO命名空间中的类进行数据读写。 2. **客户端**:客户端程序则用于连接到GB28181服务端,获取视频流,发送...
Apress.Linux.System.Administration.Recipes.A.Problem.Solution.Approach.Oct.2009.rar
标题中的"PyPI 官网下载 | Solution-2.3.11.tar.gz"表明这是一个在Python Package Index(PyPI)官方平台上发布的软件包,名为Solution,版本为2.3.11,其分发形式是经过tar.gz压缩的源代码文件。PyPI是Python开发者...
《Wise Solution V9.022汉化版:打造多平台程序安装的高效解决方案》 在IT行业中,软件的安装程序制作是一项至关重要的任务,它直接影响到用户的使用体验和软件的部署效率。Wise Solution V9.022汉化版就是这样一个...
Altiris Software Virtualization Solution CN 150905.pdf
Wrox.ASP.NET.2.0.Website.Programming.Problem.Design.Solution.May.2006