ckemail.h

来自「DES加密解密算法,西望大家共享.参考学习」· C头文件 代码 · 共 710 行 · 第 1/3 页

H
710
字号
// CkEmail.h: interface for the CkEmail class.
//
//////////////////////////////////////////////////////////////////////

#ifndef _CKEMAIL_H
#define _CKEMAIL_H


#pragma once

#include "CkString.h"
class CkCSP;
class CkCert;
class CkByteData;
class CkMime;
class CkStringArray;
class CkSpamDefs;
class CkPrivateKey;

#include "CkObject.h"

/*
    IMPORTANT: Objects returned by methods as non-const pointers must be deleted
    by the calling application. 

    IMPORTANT: A return value of True indicates success, and False indicates failure.

  */


// CLASS: CkEmail
class CkEmail : public CkObject
{
    public:

	CkEmail();
	virtual ~CkEmail();

	void AddRelatedData2(const char *data, unsigned long dataLen, const char *fileNameInHtml);
	bool AddRelatedData(const char *nameInHtml, const char *data, unsigned long dataLen, CkString *strContentId);
	bool AddDataAttachment(const char *fileName, const char *data, unsigned long dataLen);
    	bool SetMbPlainTextBody(const char *charset, const char *data, unsigned long dataLen);
    	bool SetMbHtmlBody(const char *charset, const char *data, unsigned long dataLen);
	bool QEncodeBytes(const char *data, unsigned long dataLen, const char *charset, CkString &encodedStr);
	bool BEncodeBytes(const char *data, unsigned long dataLen, const char *charset, CkString &encodedStr);
	const char *qEncodeBytes(const char *data, unsigned long dataLen, const char *charset);
	const char *bEncodeBytes(const char *data, unsigned long dataLen, const char *charset);


	// BEGIN PUBLIC INTERFACE

	// Discards the current contents of the email and replaces it with the email passed in as MIME text.
	bool SetFromMimeText(const char *mimeText);
	bool SetFromMimeText2(const char *mimeText, int numBytes);
	bool LoadEml(const char *mimeFilename);
	bool LoadXml(const char *xmlFilename);
	bool SetFromXmlText(const char *xmlStr);

	// Replaces all the attachments of an email with a single Zip file attachment having the filename specified. 
	bool ZipAttachments(const char *zipFilename);

	// Unzips and replaces any Zip file attachments with the expanded contents. As an example, if 
	// an email contained a single Zip file containing 3 GIF image files as an attachment, then after 
	// calling this method the email would contain 3 GIF file attachments, and the Zip attachment 
	// would be gone.
	// If an email contains multiple Zip file attachments, each Zip is expanded and replaced 
	// with the contents. 
	bool UnzipAttachments();

	// Encrypts the email body, all alternative bodies, all message sub-parts and attachments using 
	// 128-bit AES (Rijndael, CBC mode) encryption. To decrypt, you must use the AesDecrypt 
	// method with the same password. 
	// The AesEncrypt/Decrypt methods use symmetric password-based greatly simplify sending and 
	// receiving encrypted emails because certificates and public/private key issues do not have to 
	// be dealt with. However, the sending and receiving applications must both be using Chilkat Mail.
	bool AesEncrypt(const char *password);

	// Decrypts and restores an email message that was previously encrypted using AesEncrypt. 
	// The password must match the password used for encryption.
	bool AesDecrypt(const char *password);

	// Creates a copy of the email object.
	CkEmail *Clone(void);

	// Returns a copy of the CkEmail object with the body and header fields changed so that the 
	// newly created email can be forwarded. After calling CreateForward, simply add new recipients 
	// to the created email, and call CkMailMan.SendEmail. 
	CkEmail *CreateForward(void);

	// Returns a copy of the CkEmail object with the body and header fields changed so that the newly 
	// created email can be sent as a reply. After calling CreateReply, simply prepend additional 
	// information to the body, and call CkMailMan.SendEmail. 
	CkEmail *CreateReply(void);

	// Sets the encryption and digital signature preferences for this email. 
	// The SendSigned and SendEncrypted properties still need to be set to cause an email to be 
	// sent encrypted or signed, but the CkCSP object will control the Cryptographic Service Provider used, 
	// the key container within the CSP to be used, and the encryption/hash algorithms. 
	bool SetCSP(const CkCSP *csp);
	bool SetCSP(const CkCSP &csp) { return SetCSP(&csp); }

	// Returns the certificate associated with a received signed email.
    	CkCert *GetSignedByCert(void); 
	// Returns the certificate associated with a received encrypted email.
	CkCert *GetEncryptedByCert(void); 

	// Gets the cert previously set by SetEncryptCert
	CkCert *GetEncryptCert(void);//

	// Gets the cert previously set by SetSigningCert
	CkCert *GetSigningCert(void);

	// Explicitly sets the certificate to be used for encryption when sending encrypted (S/MIME) emails.
	bool SetEncryptCert(const CkCert *cert);
	bool SetEncryptCert(const CkCert &cert) { return SetEncryptCert(&cert); }
	// Explicitly sets the certificate to be used for signing when sending digitally signed (S/MIME) emails.
	bool SetSigningCert(const CkCert *cert);
	bool SetSigningCert(const CkCert &cert) { return SetSigningCert(&cert); }
	bool SetSigningCert2(const CkCert &cert, CkPrivateKey &key);

	// Convenience method to load the complete contents of a text file into a CkByteData.
	bool GetFileContent(const char *filename, CkByteData &bData);

	CkMime **Decompose(int &numParts);

	// 
	// NOTE: Related items are images, style sheets, or other external resources
	// that are included within a multipart/related HTML email and are referenced
	// from the HTML via CID URLs.
	// 

	// Retrieves a related item's data as a String. All end-of-lines will be translated to CRLF sequences. 
	// Indexing begins at 0.
	bool GetRelatedStringCrLf(long index, const char *charset, CkString &str);

	// Retrieves the contentID of a related item. Indexing begins at 0.
	bool GetRelatedContentID(long index, CkString &strContentID);

	bool GetRelatedContentType(long index, CkString &strContentType);

	// Retrieves a related item's filename. Indexing begins at 0. 
	bool GetRelatedFilename(long index, CkString &strFilename);

	// Retrieves a related item's data as a String. All CRLF sequences will be translated 
	// to single newline characters. Indexing begins at 0.
	bool GetRelatedString(long index, const char *charset, CkString &strData);

	// Retrieves a related item's binary data. Indexing begins at 0.
	bool GetRelatedData(long index, CkByteData &buffer);

	// Any standard or non-standard (custom) header field can be added to the email with this method. 
	// One interesting feature is that all header fields whose name begins with "CKX-" will not be 
	// included in the header when an email is sent. These fields will be included when saved to 
	// or loaded from XML. This makes it easy to include persistent meta-data with an email which 
	// your programs can use in any way it chooses.
	void AddHeaderField(const char *fieldName, const char *fieldValue);

	// Removes a field from the email header. If duplicates of the field exist, all occurances are 
	// removed. Calling AddHeaderField(fieldname,0) also removes the header field.
	void RemoveHeaderField(const char *fieldName);

	// Sets the Body property, and sets the email's content type to "text/html". 
	// Use this method if the body is HTML, and if there are no other alternative bodies.
	void SetHtmlBody(const char *html);

	// Saves a related item to a file in a directory. The NumRelatedItems property contains the 
	// number of related items contained in the email. The function returns True if successful. 
	// Indexing begins at 0.
	bool SaveRelatedItem(long index, const char *directory);

	void DropRelatedItem(long index);
	void DropRelatedItems(void);

	// Adds the contents of a file to the email and returns the Content-ID. 
	// Emails formatted in HTML can include images with this call and internally reference the 
	// image through a "cid" hyperlink.
    	bool AddRelatedFile(const char *fileName, CkString *strContentID);
	bool AddRelatedFile(const char *fileName, CkString &strContentID) { return AddRelatedFile(fileName,&strContentID); }


    	bool AddRelatedFile2(const char *fileNameOnDisk, const char *filenameInHtml);
	void AddRelatedData2(const unsigned char *data, unsigned long dataLen, const char *fileNameInHtml);
	void AddRelatedString2(const char *str, const char *charset, const char *filenameInHtml);

	// Adds the contents of a memory data buffer to the email and returns the Content-ID. 
	// This data buffer would typically contain image data in GIF or JPG format. Although the data 
	// comes from an in-memory data buffer, a fictional filename must be provided to (1) determine the 
	// format of the data, and (2) determine the filename if the related data item was to be saved 
	// to disk (by the email recipient) and HTML reconstructed. 
	bool AddRelatedData(const char *nameInHtml, const unsigned char *data, unsigned long dataLen, CkString *strContentId);
	bool AddRelatedData(const char *nameInHtml, const unsigned char *data, unsigned long dataLen, CkString &strContentId)
	    {
	    return AddRelatedData(nameInHtml,data,dataLen,&strContentId);
	    }

	// Sets the HTML body of the email. Use this method if there will be multiple versions of the 
	// body, but in different formats, such as HTML and plain text. Otherwise, set the body by calling 
	// the SetHtmlBody method.  (For non-English emails, the input string should be in the utf-8 character
	// encoding.)
	bool AddHtmlAlternativeBody(const char *body);

	// Sets the plain-text body of the email. Use this method if there will be multiple versions of 
	// the body, but in different formats, such as HTML and plain text. Otherwise, simply set the 
	// Body property (i.e. put_Body method)
	bool AddPlainTextAlternativeBody(const char *body);

	// Returns the Nth alternative body. The NumAlternatives property tells the number of 
	// alternative bodies present. Use the GetHtmlBody and GetPlainTextBody methods to easily get 
	// the HTML or plain text alternative bodies. Indexing begins at 0. The text is returned as
	// a utf-8 string.
	bool GetAlternativeBody(long index, CkString &strBody);

	// Returns the content type of the Nth alternative body. The NumAlternatives property tells 
	// the number of alternative bodies present. Indexing begins at 0.
	bool GetAlternativeContentType( long index,  CkString &strContentType);

	// Returns the body that has the "text/html" content type. The HTML is returned as a utf-8 string
	bool GetHtmlBody(CkString &strBody);

	// Returns the body that has the "text/plain" content type. The text is returned as a utf-8 string.
	bool GetPlainTextBody(CkString &strBody);

	void SetTextBody(const char *bodyText, const char *contentType);

	// Return the name of the Nth header field. The NumHeaderFields() method can be used to get the 
	// number of header fields. The GetHeaderField() method can be used to get the value of the 
	// field given the field name. Indexing begins at 0.
	long get_NumHeaderFields(void);
	bool GetHeaderFieldName(long index, CkString &strFieldName);
	bool GetHeaderFieldValue(long index, CkString &strFieldValue);

	// Returns the number of header fields in this email.
	long NumHeaderFields(void);

	// Retrieves an attachment's data as a string. 
	// All end-of-lines will be translated to CRLF sequences. Indexing begins at 0. 
	bool GetAttachmentStringCrLf(long index, const char *charset, CkString &strData);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?