mxrecord.h
/*
** This class is used to parse domain name via email address
** It can get all MX records according to domain name
** It uses dns protocol to handle domain name parsing
** It will be used by us in sending email function
** Note that: this class uses STL
**
** Document:RFC 1034 and RFC 1035
** 0 = 初始化
** 1 = 处理成功
** -1 = 邮件地址没有'@'或者'.'
** -2 = 初始化winsock或者socket失败
** -3 = 发送DNS数据报失败
** -4 = 没有收到DNS数据报
** -5 = 收到DNS数据报不是本机发送的
** -6 = DNS服务器处理该数据报有错误
** -7 = 没有对应的 RR
** -8 = 关闭socket失败
*/
#ifndef DNS_MX
#define DNS_MX
#include<vector>
#include<string>
using namespace std;
struct TaskInformation
{
char *title; //邮件的标题
char *userName; //任务的用户名
char *taskName; //任务名
char *usedPlace; //本次使用的空间
char *leftPlace; //剩余的空间
char *startedTime; //开始的时间
char *endedTime; //结束的时间
int errorCode; //本次任务的错误码
};
/* 1 = 发送邮件成功
** 2 = 初始化winsock或者socket失败
** 3 = 表示没有mail exchanger
** 4 = 连接mail exchanger 失败
** 5= 接受数据失败
** 6 = 处理ehlo命令失败
** 7 = 处理mail from命令失败
** 8 = 处理rctp to命令失败
** 9 = 处理data命令失败
** 10 = 处理'.'命令失败
** 9 = 处理quit命令失败
** 20 = 初始化
**/
class MXRecord
{
public:
MXRecord( char * );
~MXRecord();
int getErrorCode() const;
void getResourceRecord();
void divideEmail( char* ); // divide email address into servral section including integer and string section
void display(); // only to test class
vector<string>mailExchanger;
vector<int>preference;
private:
int errorCode;
char *pemailAddress;
vector<unsigned int>sectionLength;
vector<string>sectionString;
char buff[512]; // store information sending
char receiver[ 512 ];
};
[ 本帖最后由 paulmeng 于 2007-1-4 16:01 编辑 ]作者: paulmeng 时间: 2007-1-4 16:03
mxrecord.cpp
/*
** All functions are displayed to implemented belonging to MXRecord class
*/
#include<iostream>
#include<winsock2.h>
#include"mxrecord.h"
using namespace std;
// MXRecord structor function
MXRecord::MXRecord( char * emailaddress )
{
// allocate buff space
memset( this->buff,'\0',512 );
memset( this->receiver,'\0',512 );
this->errorCode =0; // initialize errorCode
this->pemailAddress = emailaddress;
} //End MXRecord();
//MXRecord destructor function
MXRecord::~MXRecord()
{
} //~MXRecord()
//return errorCode value
//errorCode can describle error information when using class
// sending email class will be used the errorCode
int MXRecord::getErrorCode() const
{
return this->errorCode;
} //End getErrorCode()
//handle sending and receiving dns package
// handle parse response package at the same time
//all the result will be stored in mailExchanger and preference vector
//Warning: pay attention to bit pointer
void MXRecord::getResourceRecord()
{
// get resource record according to this->emailAddress