mailserver2client.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,844 行 · 第 1/5 页
CPP
1,844 行
messId = toWideChar(msg.getMessageId());
if (messId) {
rgprops[cProps].Value.lpszW = messId;
++cProps;
}
rgprops[cProps].ulPropTag = PR_CUSTOM_MESSAGE_HEADER;
headers = toWideChar(msg.getHeaders());
if (headers) {
rgprops[cProps].Value.lpszW = headers;
++cProps;
}
// Body
bp = msg.getBody();
// add to the body the name of the attachments and their sizes
if (m->getEmailData()->getIsMailPartial()) {
int attachNum = 0, attachSize = 0;
unsigned long maxMsg = 0, bodySize = 0, totalBodySize = 0, filter;
string appendToBody;
string maxMsgString;
string filterString;
string totalBodySizeString;
char tmp[64];
// are in bytes
bodySize = m->getEmailData()->getRemainingBodySize() > 0 ?
m->getEmailData()->getRemainingBodySize() : 0;
filter = m->getCurrentMessageSizeFilter();
totalBodySize = bodySize + filter;
attachNum = m->getEmailData()->getRemainingAttachNumber() > 0 ?
m->getEmailData()->getRemainingAttachNumber() : 0;
maxMsg = m->getMaxMailMessageSize();
//
// round to the nearest ten value. This because
// the 500 kb supported are not really 500 but a multiple 1024
// so a round is needed to not write 496 kb
//
unsigned long toShow = (maxMsg/1024 % 5);
toShow = (5 - toShow) + maxMsg/1024;
sprintf(tmp, "%luKb", toShow);
maxMsgString += tmp;
if ((toShow = filter/1024) > 450) {
toShow = (filter/1024 % 5);
toShow = (5 - toShow) + filter/1024;
}
sprintf(tmp, "%luKb", toShow);
filterString += tmp;
sprintf(tmp, "%luKb", totalBodySize/1024);
totalBodySizeString += tmp;
// inside here filter < maxMsg
if (isInclusive == false) {
if (bodySize > 0) {
if (totalBodySize > maxMsg) {
if (attachNum > 0) {
//case Pre-action 10
appendToBody += "Click here to download the rest of the message";
appendToBody += " up to the maximum allowed size of ";
appendToBody += maxMsgString;
} else {
// case Pre-action 3
appendToBody += "Only first ";
appendToBody += filterString;
appendToBody += " (of " + totalBodySizeString + ").";
appendToBody += " Click below to get the rest";
appendToBody += " up to the maximum allowed size of ";
appendToBody += maxMsgString;
}
} else {
if (attachNum > 0) {
bool existsMinorOfMaxMsg = false;
bool existsMajorOfMaxMsg = false;
for (int i = 0; i < attachNum; i++) {
if (m->getEmailData()->getAttachmentSize(i) > 0 &&
(m->getEmailData()->getAttachmentSize(i) < maxMsg)) {
existsMinorOfMaxMsg = true;
} else {
existsMajorOfMaxMsg = true;
}
}
// all attachments are under max message
if (!existsMajorOfMaxMsg && existsMinorOfMaxMsg) {
// case Pre-action 7
appendToBody += "Only first ";
appendToBody += filterString;
appendToBody += " downloaded. Click below to get the rest";
appendToBody += " up to the maximum allowed size of ";
appendToBody += maxMsgString;
}
// at least an attachments is under max message
else if (existsMinorOfMaxMsg) {
// case Pre-action 9
appendToBody += "Only first ";
appendToBody += filterString;
appendToBody += " downloaded. Click below to get the rest";
appendToBody += " up to the maximum allowed size of ";
appendToBody += maxMsgString;
}
// no attachment under max message
// all attachments are above max message
// only the remaining part of the body to be downloaded
//if (existsMajorOfMaxMsg && !existsMinorOfMaxMsg) {
// case Pre-action 8
//}
else {
// case Pre-action 8
appendToBody += "Click below to get the rest";
appendToBody += " of the message up to the maximum allowed size of ";
appendToBody += maxMsgString;
}
} else {
// case Pre-action 2
appendToBody += "Only first ";
appendToBody += filterString;
appendToBody += " downloaded. Click below to get the rest.";
}
}
}
else {
if (attachNum > 0) {
bool existsMinorOfMaxMsg = false;
bool existsMajorOfMaxMsg = false;
for (int i = 0; i < attachNum; i++) {
if (m->getEmailData()->getAttachmentSize(i) > 0 &&
(m->getEmailData()->getAttachmentSize(i) < maxMsg)) {
existsMinorOfMaxMsg = true;
} else {
existsMajorOfMaxMsg = true;
}
}
// all attachments are under max message
if (!existsMajorOfMaxMsg && existsMinorOfMaxMsg) {
// case Pre-action 4
char toappend[256];
appendToBody += "Click below to download the following attachment(s):\r\n";
for (int i = 0; i < attachNum; i++) {
long fileSizeKB = m->getEmailData()->getAttachmentSize(i)/1024;
sprintf(toappend, "%s (%i Kb)\r\n",
m->getEmailData()->getAttachmentName(i),
fileSizeKB == 0 ? 1 : fileSizeKB);
appendToBody += toappend;
}
}
// at least an attachments is under max message
else if (existsMinorOfMaxMsg) {
// case Pre-action 6
char toappend[256];
appendToBody += "Click below to download the attachment(s) listed below";
appendToBody += " up to the maximum allowed size of ";
appendToBody += maxMsgString + ":\r\n";
for (int i = 0; i < attachNum; i++) {
long fileSizeKB = m->getEmailData()->getAttachmentSize(i)/1024;
sprintf(toappend, "%s (%i Kb)\r\n",
m->getEmailData()->getAttachmentName(i),
fileSizeKB == 0 ? 1 : fileSizeKB);
appendToBody += toappend;
}
}
// no attachment under max message
// all attachments are above max message
//if (existsMajorOfMaxMsg && !existsMinorOfMaxMsg) {
// case Pre-action 5
// }
else {
// case Pre-action 5
char toappend[256];
appendToBody += "None of the attachment(s) listed below";
appendToBody += " can be downloaded because they exceed";
appendToBody += " the maximum allowed size of ";
appendToBody += maxMsgString + ":\r\n";
for (int i = 0; i < attachNum; i++) {
long fileSizeKB = m->getEmailData()->getAttachmentSize(i)/1024;
sprintf(toappend, "%s (%i Kb)\r\n",
m->getEmailData()->getAttachmentName(i),
fileSizeKB == 0 ? 1 : fileSizeKB);
appendToBody += toappend;
}
}
} else {
// case Pre-action 1
// no action to perform: all body and attachment are downloaded
}
}
} else { // is inclusive == true
if (bodySize > 0) {
if (attachNum > 0 ) {
// case Post-action 10
appendToBody += "Only first ";
appendToBody += filterString;
appendToBody += " of the message downloaded. The following attachment(s)";
appendToBody += " could not be downloaded because the maximum allowed size of ";
appendToBody += maxMsgString;
appendToBody += " was exceeded by the message:\r\n";
char toappend[256];
for (int i = 0; i < attachNum; i++) {
long fileSizeKB = m->getEmailData()->getAttachmentSize(i)/1024;
sprintf(toappend, "%s (%i Kb)\r\n",
m->getEmailData()->getAttachmentName(i),
fileSizeKB == 0 ? 1 : fileSizeKB);
appendToBody += toappend;
}
} else {
// case Post-action 3
appendToBody += "Only first ";
appendToBody += filterString;
appendToBody += " downloaded";
appendToBody += " (of " + totalBodySizeString + ")";
appendToBody += " because the the maximum allowed size of ";
appendToBody += maxMsgString;
appendToBody += " was exceeded by the message.\r\n";
}
} else {
if (attachNum > 0 ) {
// case Post-action 6, 8, 9
appendToBody += "The following attachment(s) could not be downloaded ";
appendToBody += " because the maximum allowed size of ";
appendToBody += maxMsgString;
appendToBody += " was exceeded by the message:\r\n";
char toappend[256];
for (int i = 0; i < attachNum; i++) {
long fileSizeKB = m->getEmailData()->getAttachmentSize(i)/1024;
sprintf(toappend, "%s (%i Kb)\r\n",
m->getEmailData()->getAttachmentName(i),
fileSizeKB == 0 ? 1 : fileSizeKB);
appendToBody += toappend;
}
} else {
// case Post-action 1, 2
// nothing to do
}
}
}
/********************************************************/
if (appendToBody.length() > 0) {
appendToBody.insert(0, "\r\n=====\r\n");
bp.appendContent(appendToBody.c_str());
}
} else {
bp.appendContent(" ");
}
if (bp.getContent()) {
// Stream the body in...
hr = pmsg->OpenProperty(PR_BODY, NULL, 0, MAPI_MODIFY | MAPI_CREATE,
(LPUNKNOWN*)&pstm);
EXIT_ON_FAILED(hr);
wchar_t *content = toWideChar(bp.getContent(), bp.getCharset());
pstm->Write(content, (wcslen(content)+1)*sizeof(wchar_t), NULL);
pstm->Release();
delete [] content;
}
if (m->getEmailData()->getIsMailPartial() && foundToBeDownloaded) {
rgprops[cProps].ulPropTag = PR_MESSAGE_SIZE;
rgprops[cProps].Value.ul = strlen(bp.getContent());
++cProps;
rgprops[cProps].ulPropTag = PR_MESSAGE_SIZE_EX;
rgprops[cProps].Value.ul = m->getEmailData()->getTotalEmailSize();
//
// To store the real mail to be downloaded
//
//rgprops[cProps].Value.ul = emailSizeToDownload;
++cProps;
}
//
// Add attachments only if the attachnumber is == 0. If
//
AddAttachment(pmsg, m);
}
hr = pmsg->SetProps(cProps, rgprops, NULL);
EXIT_ON_FAILED(hr);
FuncExit:
if(subj)
delete [] subj;
if(from)
delete [] from;
if (messId) {
delete [] messId; messId = NULL;
}
if (headers) {
delete [] headers; headers = NULL;
}
LOG.debug("Exiting from SetMessageProps function");
return hr;
}
void MailServer2Client::setFolderToSync(const wchar_t* t){
if (server_folderToSync) {
delete [] server_folderToSync; server_folderToSync = NULL;
}
server_folderToSync = wstrdup(t);
}
const wchar_t* MailServer2Client::getFolderToSync() {
return server_folderToSync;
}
/**
* It deletes a just created email that cannot be completed
* due to low memory on the device or
*/
HRESULT deleteGhostEmail(LPMAPIFOLDER pfldrInbox, SPropValue* rgprops2) {
HRESULT hr = S_OK;
if (pfldrInbox == NULL || rgprops2 == NULL) {
return S_FALSE;
}
int len = rgprops2[eePR_ENTRYID].Value.bin.cb;
ENTRYLIST entryList;
entryList.cValues = 0;
MAPIAllocateBuffer(sizeof(SBinary), (LPVOID*)&(entryList.lpbin));
entryList.lpbin[0].cb = len;
MAPIAllocateBuffer(len, (LPVOID*)&(entryList.lpbin[0].lpb) );
memcpy(entryList.lpbin[0].lpb, rgprops2[eePR_ENTRYID].Value.bin.lpb, len);
entryList.cValues++;
hr = pfldrInbox->DeleteMessages (&entryList, 0, NULL, 0);
return hr;
}
/*
* Return the ID of the inserted message
*/
wchar_t* MailServer2Client::addMessage(MailClientData* m) {
LOG.debug("Enter into addMessage function");
HRESULT hr;
IMAPISession * pSession = NULL;
IMAPITable* pTable = NULL;
SRowSet* psrs = NULL;
IMsgStore* pStore = NULL;
int i = 0;
LPADRBOOK lpAddrBook = NULL;
ULONG* rgTags;
folderNumber = 0;
BOOL accountFound = FALSE;
if (server_folderToSync == NULL) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?