// Note that the only valid version of the GPL as far as jwSMTP
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
// unless explicitly otherwise stated.
//
// This file is part of the jwSMTP library.
//
// jwSMTP library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// jwSMTP library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with jwSMTP library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// jwSMTP library
// http://johnwiggins.net
// smtplib@johnwiggins.net
//
#include "stdafx.h"
#ifdef WIN32
// std::vector<std::string> This gives this warning in VC..
// bloody annoying, there is a way round it according to MS.
// The debugger basically cannot browse anything with a name
// longer than 256 characters, "get with the template program MS".
#pragma warning( disable : 4786 )
#endif
#include <fstream>
#include <sstream> // ostrstream
#include <ctime> // for localtime
#include <cassert>
#include "mailer.h"
#include "base64.h"
namespace jwsmtp {
mailer::mailer(const char* TOaddress, const char* FROMaddress,
const char* Subject, const std::vector<char>& Message,
const char* Nameserver, unsigned short Port,
bool MXLookup): type(LOGIN),
subject(Subject),
server(getserveraddress(TOaddress)),
nameserver(Nameserver),
port(htons(Port)), // make the 'port' network byte order.
lookupMXRecord(MXLookup),
auth(false) {
// Parse the email addresses into an Address structure.
setsender(FROMaddress);
addrecipient(TOaddress);
setmessage(Message);
initNetworking(); // in win32 init networking, else just does nothin'
}
mailer::mailer(const char* TOaddress, const char* FROMaddress,
const char* Subject, const char* Message,
const char* Nameserver, unsigned short Port,
bool MXLookup): type(LOGIN),
subject(Subject),
server(getserveraddress(TOaddress)),
nameserver(Nameserver),
port(htons(Port)), // make the 'port' network byte order.
lookupMXRecord(MXLookup),
auth(false) {
// Parse the email addresses into an Address structure.
setsender(FROMaddress);
addrecipient(TOaddress);
setmessage(Message);
initNetworking(); // in win32 init networking, else just does nothin'
}
mailer::mailer(bool MXLookup, unsigned short Port):
type(LOGIN),
port(htons(Port)),
lookupMXRecord(MXLookup),
auth(false) {
initNetworking(); // in win32 init networking, else just does nothin'
}
mailer::~mailer() { }
bool mailer::setmessage(const std::string& newmessage) {
if(!newmessage.length())
return false;
message.clear(); // erase the old message
for (std::string::size_type i = 0; i < newmessage.length(); ++i)
message.push_back(newmessage[i]);
checkRFCcompat();
return true;
}
bool mailer::setmessage(const std::vector<char>& newmessage) {
if(!newmessage.size())
return false;
message = newmessage;
checkRFCcompat();
return true;
}
bool mailer::setmessageHTML(const std::string& newmessage) {
if(!newmessage.length())
return false;
messageHTML.clear(); // erase the old message
for (std::string::size_type i = 0; i < newmessage.length(); ++i)
messageHTML.push_back(newmessage[i]);
messageHTML = base64encode(messageHTML);
return true;
}
bool mailer::setmessageHTML(const std::vector<char>& newmessage) {
if(!newmessage.size())
return false;
messageHTML = base64encode(newmessage);
return true;
}
bool mailer::setmessageHTMLfile(const std::string& filename) {
if(!filename.length())
return false;
std::ifstream file(filename.c_str(), std::ios::binary | std::ios::in);
if(!file)
return false;
std::vector<char> filedata;
char c = file.get();
for(; file.good(); c = file.get()) {
if(file.bad())
break;
filedata.push_back(c);
}
messageHTML = base64encode(filedata);
return true;
}
// this breaks a message line up to be less than 1000 chars per line.
// keeps words intact also.
// Check line returns are in the form "\r\n"
// (qmail balks otherwise, i.e. LAME server)
void mailer::checkRFCcompat() {
// Check the line breaks.
std::vector<char>::iterator it;
for(it = message.begin(); it != message.end(); ++it) {
// look for \n add \r before if not there. Pretty lame but still.
// haven't thought of a better way yet.
if(*it == '\n') {
if(it == message.begin()) {
it = message.insert(it, '\r');
++it; // step past newline
continue;
}
if((*(it -1) != '\r') ) {
// add a return before '\n'
it = message.insert(it, '\r');
++it; // step past newline
}
}
}
// if we get a period on a line by itself
// add another period to stop the server ending the mail prematurely.
// ( suggested by david Irwin )
if(message.size() == 1) {
if(*(message.begin()) == '.')
message.push_back('.');
}
else if(message.size() == 2) {
if(*(message.begin()) == '.') {
it = message.begin();
it = message.insert(it, '.');
}
}
else {
if(*(message.begin()) == '.') {
it = message.begin();
it = message.insert(it, '.');
}
for(it = message.begin()+2; it != message.end(); ++it) {
// follow the rfc. Add '.' if the first character on a line is '.'
if(*it == '\n') {
if( ((it + 1) != message.end()) && (*(it +1) == '.') ) {
it = message.insert(it + 1, '.');
++it; // step past
}
}
}
}
// don't do anything if we are not longer than a 1000 characters
if(message.size() < 1000)
return;
// now we have checked line breaks
// check line lengths.
int count(1);
for(it = message.begin(); it < message.end(); ++it, ++count) {
if(*it == '\r') {
count = 0; // reset for a new line.
++it; // get past newline
continue;
}
else if(count >= 998) {
++it;
if(*it != ' ') { // we are not in a word!!
// it should never get to message.begin() because we
// start at least 998 chars into the message!
// Also, assume a word isn't bigger than 997 chars! (seems reasonable)
std::vector<char>::iterator pos = it;
for(int j = 0; j < 997; ++j, --pos) {
if(*pos == ' ') {
it = ++pos; // get past the space.
break;
}
}
}
if(it < message.end())
it = message.insert(it, '\r');
++it;
if(it < message.end())
it = message.insert(it, '\n');
count = 0; // reset for a new line.
}
}
count=1; // reset the count
if(messageHTML.size()) {
for(it = messageHTML.begin(); it < messageHTML.end(); ++it, ++count) {
if(*it == '\r') {
count = 0; // reset for a new line.
++it; // get past newline
continue;
}
else if(count >= 998) {
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Dump.rar (25个子文件)
Dump
Dump.suo 23KB
Dump
Dump.vcxproj.filters 3KB
Dump.cpp 984B
res
Dump.ico 1KB
Dump.h 10B
Dump.rc 8KB
Dump.aps 17KB
MainDlg.h 1KB
stdafx.h 1KB
Dump.vcxproj.user 143B
MainDlg.cpp 1KB
stdafx.cpp 272B
DumpDialog.h 3KB
resource.h 720B
Dump.vcxproj 7KB
CommonFunctions.h 741B
DumpMail
jwsmtp.h 1KB
mailer.cpp 48KB
DumpMail.h 3KB
compat.h 4KB
base64.h 2KB
mailer.h 10KB
base64.cpp 5KB
compat.cpp 3KB
Dump.sln 879B
共 25 条
- 1
资源评论
风尘无名
- 粉丝: 1
- 资源: 24
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功