pstsdk下载地址:https://archive.codeplex.com/?p=pstsdk

下载后,我们只需要取出pstsdk目录,并自己进行dll封装,实现提取邮件内容、主题、收件人信息,把附件保存在一个目录下。利用VS2015进行调用该dll。

下载后,把新建一个pst目录,把头文件剪贴到原本的pstsdk目录外边,新建pst目录结构如下:

要编译pstsdk库,需要boost库,并且是1.42以上的版本,在VS2010中新建一个工程(测试过在VS10更高的版本建立工程,但是都编译失败了),在工程添加boost的目录。

pstParser.h如下:

#ifndef PSTPARSER_H__
#define PSTPARSER_H__
#include<algorithm>
#include<functional>
#include<locale.h>
#include <string>
#include<iostream>
#include<Windows.h>//解析pst文件
//参数1为pst文件,
//参数2保存收件人、主题、内容的文件
//参数3为一个目录,附件如果为文件,则保存在该目录下
extern "C" _declspec(dllexport) void PstParser(const WCHAR* pstFile,const WCHAR *contentFile,const WCHAR *TempDir);
typedef void(_cdecl *PstParserDef)(const WCHAR* pstFile,const WCHAR *contentFile,const WCHAR *TempDir);#endif

pstParser.cpp如下:

#include "pstParser.h"#include <pst.h>
#include<ltp.h>
#include<util.h>
using namespace std;
using namespace std::placeholders;void process_message(const pstsdk::message& m,wstring &content,wstring &TempDir);void Wstring2String(wstring inStr,string &outStr)
{int size = WideCharToMultiByte(CP_ACP , NULL, inStr.c_str(), inStr.length(), NULL, 0, NULL, false);char *buff=(char*)malloc(sizeof(char)*(size+1));if (!buff){return;}memset(buff,0,sizeof(char)*(size+1));WideCharToMultiByte(CP_ACP , NULL, inStr.c_str(), -1,buff , size, NULL, false);buff[size]=0;outStr=buff;free(buff);
}
void String2Wstring(string inStr,wstring &outStr)
{int size=MultiByteToWideChar(CP_ACP ,NULL,inStr.c_str(),inStr.length(),NULL,0);wchar_t *buff=(wchar_t*)malloc(sizeof(wchar_t)*(size+1));if (!buff){return;}memset(buff,0,sizeof(wchar_t)*(size+1));MultiByteToWideChar(CP_ACP ,NULL,inStr.c_str(),inStr.length(),buff,size);buff[size]=0;outStr=buff;free(buff);
}
//提取附件
void process_attachment(const pstsdk::attachment& a,wstring &content,wstring &TempDir)
{if(a.is_message()){process_message(a.open_as_message(),content,TempDir);}else{std::wstring wfilename = a.get_filename();  wstring dir=TempDir;dir.append(L"\\");dir.append(wfilename);ofstream newfile(dir.c_str(), ios::out | ios::binary);newfile << a;newfile.close();}
}//收件人信息
void process_recipient(const pstsdk::recipient& r,wstring &content)
{std::wstring recName=r.get_name();if (recName.size()){content.append(recName);}
}//提取邮件
void process_message(const pstsdk::message& m,wstring &content,wstring &TempDir)
{try {wstring body=m.get_body();  //获得邮件内容if (body.size()){content.append(body);}wstring subject=m.get_subject(); //邮件主题if (subject.size()){content.append(subject);}if (m.get_attachment_count()>0){for_each(m.attachment_begin(),m.attachment_end(),bind(process_attachment,_1,ref(content),ref(TempDir)));}if (m.get_recipient_count()>0){for_each(m.recipient_begin(),m.recipient_end(),bind(process_recipient,_1,ref(content)));}}catch(pstsdk::key_not_found<pstsdk::prop_id>&){}
}//遍历邮件目录
void process_folder(const pstsdk::folder& f,wstring &content,wstring &TempDir)
{for_each(f.message_begin(), f.message_end(), bind(process_message, _1,ref(content),ref(TempDir)));for_each(f.sub_folder_begin(), f.sub_folder_end(), bind(process_folder, _1,ref(content),ref(TempDir)));
}extern "C" _declspec(dllexport) void PstParser(const WCHAR* pstFile,const WCHAR *contentFile,const WCHAR *TempDir)
{wstring wTempDir;wstring wdat;   try{pstsdk::pst f(pstFile);process_folder(f.open_root_folder(),wdat,wTempDir);string dat;Wstring2String(wdat,dat);wstring filePath=TempDir;filePath.append(L"\\");filePath.append(contentFile);ofstream cFile(filePath.c_str());if (!cFile.is_open()){return;}cFile<<dat;cFile.close();}catch(...){return;}
}

利用pstsdk进行解析pst文件相关推荐

  1. 【python脚本系列】利用mido库解析midi文件

    [python脚本系列]利用mido库解析midi文件       Hallo大家好~~我是Lampard猿奋       昨天写了关于Midi数字化乐器接口的文章,介绍了midi是一组代表音乐参数( ...

  2. python中利用lxml模块解析xml文件报错XMLSyntaxError: Opening and ending tag mismatch

    今天在代码中第一次使用lxml解析xml文件时出错了, XMLSyntaxError: Opening and ending tag mismatch: keyEffectiveDate line 2 ...

  3. 微信小程序——利用java后台解析Excel文件的数据

    后台为java,ssm框架 1.在SpringMvc.xml文件中增加Spring文件上传的解析器 <bean id="multipartResolver"class=&qu ...

  4. java利用io流读取文件发生了乱码以及java解析vcf文件

    如果文件中含有中文字符,那么这时候直接进行读取,即new FileInputStream(要读取的文件),就会出现了乱码,所以这时候,我们需要设置对应的格式进行读取,所以还需要传递对应的编码,所以将代 ...

  5. World Wind Java开发之六——解析shape文件(转)

    http://blog.csdn.net/giser_whu/article/details/41647117 最近一直忙于导师项目的事情了,几天没更新了,昨天和今天研究了下WWJ解析shp文件的源代 ...

  6. java解析Excel文件

    下文介绍java解析Excel文件的方案 前置准备 1.第三方jar包或者Maven配置 org.apache.poi的jar包 Maven配置如下 <groupId>org.apache ...

  7. java的getshape()_World Wind Java开发之六——解析shape文件(转)

    http://blog.csdn.net/giser_whu/article/details/41647117 最近一直忙于导师项目的事情了,几天没更新了,昨天和今天研究了下WWJ解析shp文件的源代 ...

  8. World Wind Java开发之六——解析shape文件

    最近一直忙于导师项目的事情了,几天没更新了,昨天和今天研究了下WWJ解析shp文件的源代码,现在记录下,希望可以帮到更多的人! 上一篇博客:World Wind Java开发之五--读取本地shp文件 ...

  9. [Linux C]利用libxml2解析xml文件

    为了解析xml,可以使用Linux下默认安装的libxml2. /*a.c功能:利用libxml2解析xml文件 */#include <stdio.h> #include <std ...

最新文章

  1. CBAC ftp测试
  2. 2020 蚂蚁面试指南!
  3. 算法 【第九章】动态规划问题
  4. Java黑皮书课后题第11章:11.3(Account类的子类)在编程练习题9.7中定义了一个Account类来对一个银行账户建模。一个账户有账号、余额、年利率、开户日期等属性,以及存款和取款等方法
  5. Cocos2d-x 手游开发群:296733909
  6. Ubuntu 14.04中修复默认启用HDMI后没有声音的问题
  7. stat函数_使用Python的stat函数有效地获得所有者,组和其他权限
  8. The Robustness of Deep Networks A geometrical perspective论文解读
  9. IDEA去掉Performing Code Analysis,Check TODO
  10. 用Python批量缩放图片
  11. 攻防世界 —— Crypto新手练习区7题(不仅仅是Morse)题解
  12. 人物志 | 美团技术委员会前端通道主席洪磊:爱折腾的斜杠青年
  13. java开发平台有哪些_java都有哪些开发平台
  14. CSharp 基本知识-数组
  15. tomcatServlet
  16. NB-IoT的应用领域
  17. Jquery的parent和closet方法
  18. Docker容器之Docker Toolbox下配置国内镜像源-阿里云加速器(Windows)
  19. ClearType检索方法
  20. MMC、CE-ATA、SD、TF、SDIO的异同

热门文章

  1. Windows Server 系统怎么显示桌面图标“这台电脑”。
  2. 仪表盘(用ECharts绘制)
  3. galgame 游戏动画汉化(动画外挂字幕)和字幕合成方法
  4. java应用环境_搭建java应用环境.doc
  5. Dreamweaver cc 2018精简版
  6. 吴恩达机器学习(二十六) 数据压缩与可视化、PCA
  7. 注册表编辑器导入、导出注意事项
  8. 思考致富-55个著名的借口
  9. SpaceSniffer直观分析并清理硬盘垃圾文件(查看文件夹大小)
  10. spring源码编译导入eclipse