📄 mailutils.cpp
字号:
/*
* Copyright (C) 2003-2007 Funambol, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY, TITLE, NONINFRINGEMENT 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
#include "pim/mail/MailUtils.h"
#include "notify/checknet.h"
#include "Tlhelp32.h"
wchar_t* c2wc (wchar_t t) {
wchar_t* ret = new wchar_t[2];
wsprintf(ret, TEXT("%c"), t);
return ret;
}
wchar_t* convertBinaryToWChar(SBinary sbEntry, wchar_t folder) {
int len = sbEntry.cb;
char* b64 = new char[((len/3+1)<<2) + 1];
len = b64_encode(b64, sbEntry.lpb, len);
b64[len] = 0;
wchar_t* t = toWideChar(b64);
wchar_t* ret = new wchar_t[wcslen(t) + 1 + 2];
wsprintf(ret, TEXT("%c/%s"), folder, t);
// AAAAAG8TAAECAAAAAQAAA==
delete [] b64; b64 = NULL;
delete [] t; t = NULL;
return ret;
}
char* convertBinaryToChar(SBinary sbEntry, wchar_t folder) {
int len = sbEntry.cb;
char* b64 = new char[((len/3+1)<<2) + 1];
len = b64_encode(b64, sbEntry.lpb, len);
b64[len] = 0;
char* ret = new char[strlen(b64) + 1 + 2];
sprintf(ret, "%lc/%s", folder, b64);
// AAAAAG8TAAECAAAAAQAAA==
delete [] b64; b64 = NULL;
return ret;
}
/*
* Check if the t char starts with I/, O/, D/, T/, S/
*/
static inline bool startWithFolder(const char* t) {
bool ret = false;
if (strstr(t, "I/") != NULL ||
strstr(t, "O/") != NULL ||
strstr(t, "D/") != NULL ||
strstr(t, "S/") != NULL ||
strstr(t, "T/") != NULL )
ret = true;
return ret;
}
size_t decodeEntryId(const wchar_t *entryId, char **id) {
char* eid = toMultibyte(entryId);
if (!eid) {
LOG.error("decodeEntryId: error coverting entryId");
return NULL;
}
// Skip folder letter + /
char *p = (startWithFolder(eid)) ? eid+2 : eid ;
// Decode the id
*id = new char[strlen(p)];
size_t len = b64_decode(*id, p);
delete [] eid;
return len;
}
ULONG getFolderId(wchar_t t) {
ULONG ret = -1;
if (t == INBOX_FOLDER)
ret = PR_CE_IPM_INBOX_ENTRYID;
else if (t == OUTBOX_FOLDER)
ret = PR_IPM_OUTBOX_ENTRYID;
else if (t == TRASH_FOLDER)
ret = PR_IPM_WASTEBASKET_ENTRYID;
else if (t == DRAFT_FOLDER)
ret = PR_CE_IPM_DRAFTS_ENTRYID;
else if (t == SENT_FOLDER)
ret = PR_IPM_SENTMAIL_ENTRYID;
return ret;
}
void getFolderToSync(MailSyncSourceConfig &sc, OUT wchar_t* tt) {
int i = 0;
if (sc.getInbox()) {
tt[i] = INBOX_FOLDER;
i++;
}
if (sc.getOutbox()) {
tt[i] = OUTBOX_FOLDER;
i++;
}
if (sc.getDraft()) {
tt[i] = DRAFT_FOLDER;
i++;
}
if (sc.getSent()) {
tt[i] = SENT_FOLDER;
i++;
}
if (sc.getTrash()) {
tt[i] = TRASH_FOLDER;
i++;
}
tt[i] = 0;
}
char* createMessageID(const wchar_t* entryID) {
const char* address ;
if(checkNetwork())
address = getLocalAddress();
else
address = "127.0.0.1";
char* messageID = new char[wcslen(entryID)+strlen(address)+2];
sprintf(messageID, "%ls@%s", entryID, address);
return messageID;
}
int closeMailProcess() {
DWORD out = 0;
PROCESSENTRY32 lppe;
BOOL next = TRUE;
HANDLE hProcess = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // 0 is however ignored
if (hSnapshot == INVALID_HANDLE_VALUE)
return 0;
lppe.dwSize = sizeof( PROCESSENTRY32 );
if (!Process32First(hSnapshot, &lppe))
return 1;
if (wcsstr(lppe.szExeFile, TEXT("tmail.exe")) != NULL) {
hProcess = OpenProcess(0, FALSE, lppe.th32ProcessID);
TerminateProcess(hProcess, -1);
goto exit;
}
do {
next = Process32Next(hSnapshot, &lppe);
if (!next)
break;
if (wcsstr(lppe.szExeFile, TEXT("tmail.exe")) != NULL ) {
hProcess = OpenProcess(0, FALSE, lppe.th32ProcessID);
TerminateProcess(hProcess, -1);
goto exit;
}
} while(next);
exit:
if (hSnapshot)
CloseToolhelp32Snapshot(hSnapshot);
CloseHandle(hProcess);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -