diff options
Diffstat (limited to 'options.cpp')
-rw-r--r-- | options.cpp | 715 |
1 files changed, 500 insertions, 215 deletions
diff --git a/options.cpp b/options.cpp index 9d9b952..c8e7777 100644 --- a/options.cpp +++ b/options.cpp @@ -192,7 +192,17 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA TCHAR *ptmp; char *tmp; bool keep = false; - tmp = UniGetContactSettingUtf(user_data[item_num+1], szGPGModuleName, "KeyID", ""); + bool ismetacontact = false; + HANDLE meta = NULL, hContact = user_data[item_num+1]; + if(isProtoMetaContacts(hContact)) + { + meta = hContact; + hContact = metaGetMostOnline(hContact); + ismetacontact = true; + } + else if((meta = metaGetContact(hContact)) != NULL) + ismetacontact = true; + tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact != NULL; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) { if(hContact != user_data[item_num+1]) @@ -208,46 +218,80 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA } } if(!keep) - { - wstring cmd; - string output; - DWORD exitcode; - cmd += _T(" --batch --yes --delete-key "); - ptmp = mir_a2t(tmp); - cmd += ptmp; - mir_free(ptmp);
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &output;
- params.code = &exitcode;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
- mir_free(tmp); - break; - }
- if(output.find("--delete-secret-keys") != string::npos) - MessageBoxA(0, "we have secret key for this public key, do not removing from GPG keyring", "info", MB_OK); + if(MessageBox(0, _T("This key not used by any contact, do you want to remove it from publick keyring ?"), _T("Key info"), MB_YESNO) == IDYES) + { + wstring cmd; + string output; + DWORD exitcode; + cmd += _T(" --batch --yes --delete-key "); + ptmp = mir_a2t(tmp); + cmd += ptmp;
+ mir_free(ptmp);
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &output;
+ params.code = &exitcode;
+ params.result = &result;
+ HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
+ {
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
+ {
+ MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); + mir_free(tmp); + break;
+ } + if(output.find("--delete-secret-keys") != string::npos) + MessageBoxA(0, "we have secret key for this public key, do not removing from GPG keyring", "info", MB_OK); + else + MessageBoxA(0, "Key removed from GPG keyring", "info", MB_OK); + } + mir_free(tmp); + if(ismetacontact) + { + if(MessageBox(0, _T("Do you want to remove key from entire metacontact (all subcontacts) ?"), _T("Metacontact detected"), MB_YESNO) == IDYES) + { + HANDLE hcnt = NULL; + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + { + DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyID"); + DBDeleteContactSetting(hcnt, szGPGModuleName, "GPGPubKey"); + DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyMainName"); + DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyType"); + DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyMainEmail"); + DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyComment"); + } + } + } + else + { + DBDeleteContactSetting(hContact, szGPGModuleName, "KeyID"); + DBDeleteContactSetting(hContact, szGPGModuleName, "GPGPubKey"); + DBDeleteContactSetting(hContact, szGPGModuleName, "KeyMainName"); + DBDeleteContactSetting(hContact, szGPGModuleName, "KeyType"); + DBDeleteContactSetting(hContact, szGPGModuleName, "KeyMainEmail"); + DBDeleteContactSetting(hContact, szGPGModuleName, "KeyComment"); + } + } else - MessageBoxA(0, "Key removed from GPG keyring", "info", MB_OK); - } - mir_free(tmp); + { + DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyID"); + DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "GPGPubKey"); + DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyMainName"); + DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyType"); + DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyMainEmail"); + DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyComment"); + } } - DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyID"); - DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "GPGPubKey"); - DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyMainName"); - DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyType"); - DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyMainEmail"); - DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyComment"); ListView_SetItemText(hwndList, item_num, 3, _T("not set")); ListView_SetItemText(hwndList, item_num, 2, _T("not set")); ListView_SetItemText(hwndList, item_num, 1, _T("not set")); @@ -485,10 +529,12 @@ static BOOL CALLBACK DlgProcGpgMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP HWND hPubKeyEdit = NULL; + static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) { HANDLE hContact = user_data[item_num+1]; + TCHAR *tmp = NULL; wstring key_buf; @@ -497,38 +543,44 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP { case WM_INITDIALOG: { + HANDLE hcnt = hContact; + if(isProtoMetaContacts(hcnt)) + hcnt = metaGetMostOnline(hcnt); TranslateDialogDefault(hwndDlg); bool isContactSecured(HANDLE); - tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); - if(!hContact) + if(!hcnt) { EnableWindow(GetDlgItem(hwndDlg, IDC_SELECT_EXISTING), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLE_ENCRYPTION), 0); } - if(isContactSecured(hContact)) + if(isContactSecured(hcnt)) SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, _T("Turn off encryption")); else SetDlgItemText(hwndDlg, IDC_ENABLE_ENCRYPTION, _T("Turn on encryption")); - wstring str = tmp; - mir_free(tmp); - wstring::size_type p = 0, stop = 0; - if(!str.empty()) + if(hcnt) { - for(;;) + tmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); + wstring str = tmp; + mir_free(tmp); + wstring::size_type p = 0, stop = 0; + if(!str.empty()) { - if((p = str.find(_T("\n"), p+2)) != wstring::npos) + for(;;) { - if(p > stop) + if((p = str.find(_T("\n"), p+2)) != wstring::npos) { - stop = p; - str.insert(p, _T("\r")); - } - else - break; + if(p > stop) + { + stop = p; + str.insert(p, _T("\r")); + } + else + break; + } } } + SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, !str.empty()?str.c_str():_T("")); } - SetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, !str.empty()?str.c_str():_T("")); hPubKeyEdit = GetDlgItem(hwndDlg, IDC_PUBLIC_KEY_EDIT); return TRUE; } @@ -539,187 +591,420 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP switch (LOWORD(wParam)) { case ID_OK: - tmp = new TCHAR [40960]; - TCHAR *begin, *end; - GetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, tmp, 40960); - key_buf.append(tmp); - key_buf.append(_T("\n")); //no new line at end of file ) - delete [] tmp; - while((ws1 = key_buf.find(_T("\r"), ws1)) != wstring::npos) - { - key_buf.erase(ws1, 1); //remove windows specific trash - } - ws1 = 0; - if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) != wstring::npos)) { - begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + 1]; - _tcscpy(begin, _T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); - end = new TCHAR [_tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")) + 1]; - _tcscpy(end, _T("-----END PGP PUBLIC KEY BLOCK-----")); - } - else if(((ws2 = key_buf.find(_T("-----END PGP PRIVATE KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----"))) != wstring::npos)) - { - begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) + 1]; - _tcscpy(begin, _T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); - end = new TCHAR [_tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")) + 1]; - _tcscpy(end, _T("-----END PGP PRIVATE KEY BLOCK-----")); - } - else - { - MessageBox(0, _T("This is not public or private key"), _T("INFO"), MB_OK); - break; - } - ws2 += _tcslen(end); - DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); - tmp = new TCHAR [key_buf.length()+1]; - _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str()); - { //gpg execute block - wstring cmd; - TCHAR tmp2[MAX_PATH] = {0}; - TCHAR *ptmp; - string output; - DWORD exitcode; - + tmp = new TCHAR [40960]; + TCHAR *begin, *end; + GetDlgItemText(hwndDlg, IDC_PUBLIC_KEY_EDIT, tmp, 40960); + key_buf.append(tmp); + key_buf.append(_T("\n")); //no new line at end of file ) + delete [] tmp; + while((ws1 = key_buf.find(_T("\r"), ws1)) != wstring::npos) { - ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - _tcscpy(tmp2, ptmp); - mir_free(ptmp); - _tcscat(tmp2, _T("\\")); - _tcscat(tmp2, _T("temporary_exported.asc")); - wfstream f(tmp2, std::ios::out); - ptmp = UniGetContactSettingUtf(user_data[item_num+1], szGPGModuleName, "GPGPubKey", _T("")); - wstring str = ptmp; - mir_free(ptmp); - wstring::size_type s = 0; - while((s = str.find(_T("\r"), s)) != wstring::npos) + key_buf.erase(ws1, 1); //remove windows specific trash + } + ws1 = 0; + if(((ws2 = key_buf.find(_T("-----END PGP PUBLIC KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----"))) != wstring::npos)) + { + begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PUBLIC KEY BLOCK-----")) + 1]; + _tcscpy(begin, _T("-----BEGIN PGP PUBLIC KEY BLOCK-----")); + end = new TCHAR [_tcslen(_T("-----END PGP PUBLIC KEY BLOCK-----")) + 1]; + _tcscpy(end, _T("-----END PGP PUBLIC KEY BLOCK-----")); + } + else if(((ws2 = key_buf.find(_T("-----END PGP PRIVATE KEY BLOCK-----"))) != wstring::npos) && ((ws1 = key_buf.find(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----"))) != wstring::npos)) + { + begin = new TCHAR [_tcslen(_T("-----BEGIN PGP PRIVATE KEY BLOCK-----")) + 1]; + _tcscpy(begin, _T("-----BEGIN PGP PRIVATE KEY BLOCK-----")); + end = new TCHAR [_tcslen(_T("-----END PGP PRIVATE KEY BLOCK-----")) + 1]; + _tcscpy(end, _T("-----END PGP PRIVATE KEY BLOCK-----")); + } + else + { + MessageBox(0, _T("This is not public or private key"), _T("INFO"), MB_OK); + break; + } + ws2 += _tcslen(end); + bool allsubcontacts = false; + { + if(isProtoMetaContacts(hContact)) { - str.erase(s, 1); + HANDLE hcnt = NULL; + if(MessageBox(0, _T("Do you want load key for all subcontacts ?"), _T("Metacontact detected"), MB_YESNO) == IDYES) + { + allsubcontacts = true; + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingTString(hcnt, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); + } + } + else + DBWriteContactSettingTString(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); } - f<<str.c_str(); - f.close(); - cmd += _T(" --batch "); - cmd += _T(" --import \""); - cmd += tmp2; - cmd += _T("\""); - }
- gpg_execution_params params;
- pxResult result;
- params.cmd = &cmd;
- params.useless = "";
- params.out = &output;
- params.code = &exitcode;
- params.result = &result;
- HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
- if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
- {
- TerminateThread(gpg_thread, 0);
- MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
- }
- if(result == pxNotFound)
- {
- MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); - break;
+ else + DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", key_buf.substr(ws1,ws2-ws1).c_str()); } - mir_free(begin); - mir_free(end); - DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "bAlwatsTrust"); - { - TCHAR *tmp; - - if(output.find("already in secret keyring") != string::npos) + tmp = new TCHAR [key_buf.length()+1]; + _tcscpy(tmp, key_buf.substr(ws1,ws2-ws1).c_str()); + { //gpg execute block + wstring cmd; + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + string output; + DWORD exitcode; { - MessageBox(0, _T("Key already in scret key ring."), _T("Info"), MB_OK); - DeleteFile(tmp2); + HANDLE hcnt = hContact; + if(isProtoMetaContacts(hcnt)) + hcnt = metaGetMostOnline(hcnt); + ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + _tcscpy(tmp2, ptmp); + mir_free(ptmp); + _tcscat(tmp2, _T("\\")); + _tcscat(tmp2, _T("temporary_exported.asc")); + wfstream f(tmp2, std::ios::out); + ptmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); + wstring str = ptmp; + mir_free(ptmp); + wstring::size_type s = 0; + while((s = str.find(_T("\r"), s)) != wstring::npos) + { + str.erase(s, 1); + } + f<<str.c_str(); + f.close(); + cmd += _T(" --batch "); + cmd += _T(" --import \""); + cmd += tmp2; + cmd += _T("\"");
+ }
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &output;
+ params.code = &exitcode;
+ params.result = &result;
+ HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
+ {
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
+ { + MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
break; } - char *tmp2; - string::size_type s = output.find("gpg: key ") + strlen("gpg: key "); - string::size_type s2 = output.find(":", s);
- tmp2 = new char [output.substr(s,s2-s).length()+1];
- strcpy(tmp2, output.substr(s,s2-s).c_str());
- mir_utf8decode(tmp2, 0); - DBWriteContactSettingString(user_data[item_num+1], szGPGModuleName, "KeyID", tmp2); - mir_free(tmp2); - tmp = mir_utf8decodeW(output.substr(s,s2-s).c_str()); - ListView_SetItemText(hwndList_p, item_num, 1, tmp); - mir_free(tmp); - s2+=2; - s = output.find("\"", s2)-1; - if(s != s2-1) - {
- tmp2 = new char [output.substr(s2,s-s2).length()+1];
- strcpy(tmp2, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp2, 0); - DBWriteContactSettingString(user_data[item_num+1], szGPGModuleName, "KeyType", output.substr(s2,s-s2).c_str()); - mir_free(tmp2); + mir_free(begin); + mir_free(end); + if(hContact) + { + if(isProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBDeleteContactSetting(hcnt, szGPGModuleName, "bAlwatsTrust"); + } + } + else + DBDeleteContactSetting(metaGetMostOnline(hContact), szGPGModuleName, "bAlwatsTrust"); + } + else + DBDeleteContactSetting(hContact, szGPGModuleName, "bAlwatsTrust"); } - s+=2; - if((s2 = output.find("(", s)) == string::npos) - s2 = output.find("<", s); - tmp2 = new char [output.substr(s,s2-s-1).length()+1];
- strcpy(tmp2, output.substr(s,s2-s-1).c_str());
- mir_utf8decode(tmp2, 0); - DBWriteContactSettingString(user_data[item_num+1], szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); - mir_free(tmp2); - tmp = mir_utf8decodeW(output.substr(s,s2-s-1).c_str()); - ListView_SetItemText(hwndList_p, item_num, 2, tmp); - mir_free(tmp); - if((s = output.find(")", s2)) == string::npos) - s = output.find(">", s2); - s2++; - if(output[s] == ')') { - tmp2 = new char [output.substr(s2,s-s2).length()+1];
- strcpy(tmp2, output.substr(s2,s-s2).c_str()); - mir_utf8decode(tmp2, 0); - DBWriteContactSettingString(user_data[item_num+1], szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); - mir_free(tmp2); - s+=3; - s2 = output.find(">", s); + TCHAR *tmp; + if(output.find("already in secret keyring") != string::npos) + { + MessageBox(0, _T("Key already in scret key ring."), _T("Info"), MB_OK); + DeleteFile(tmp2); + break; + } + char *tmp2; + string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
+ string::size_type s2 = output.find(":", s);
tmp2 = new char [output.substr(s,s2-s).length()+1];
strcpy(tmp2, output.substr(s,s2-s).c_str()); mir_utf8decode(tmp2, 0); - DBWriteContactSettingString(user_data[item_num+1], szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + { + if(isProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyID", tmp2); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyID", tmp2); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", tmp2); + } mir_free(tmp2); tmp = mir_utf8decodeW(output.substr(s,s2-s).c_str()); - ListView_SetItemText(hwndList_p, item_num, 3, tmp); + if(hContact) + ListView_SetItemText(hwndList_p, item_num, 1, tmp); mir_free(tmp); - } - else - { - tmp2 = new char [output.substr(s2,s-s2).length()+1];
- strcpy(tmp2, output.substr(s2,s-s2).c_str()); + s2+=2; + s = output.find("\"", s2)-1; + if(s != s2-1)
+ {
+ tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + if(isProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyType", output.substr(s2,s-s2).c_str()); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyType", output.substr(s2,s-s2).c_str()); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyType", output.substr(s2,s-s2).c_str()); + } + mir_free(tmp2); + } + s+=2; + if((s2 = output.find("(", s)) == string::npos) + s2 = output.find("<", s);
+ tmp2 = new char [output.substr(s,s2-s-1).length()+1];
+ strcpy(tmp2, output.substr(s,s2-s-1).c_str()); mir_utf8decode(tmp2, 0); - DBWriteContactSettingString(user_data[item_num+1], szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + if(hContact) + { + if(isProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainName", output.substr(s,s2-s-1).c_str()); + } mir_free(tmp2); - tmp = mir_utf8decodeW(output.substr(s2,s-s2).c_str()); - ListView_SetItemText(hwndList_p, item_num, 3, tmp); + tmp = mir_utf8decodeW(output.substr(s,s2-s-1).c_str()); + if(hContact) + ListView_SetItemText(hwndList_p, item_num, 2, tmp); mir_free(tmp); + if((s = output.find(")", s2)) == string::npos) + s = output.find(">", s2); + s2++; + if(output[s] == ')') + {
+ tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + if(isProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + } + mir_free(tmp2); + s+=3; + s2 = output.find(">", s);
+ tmp2 = new char [output.substr(s,s2-s).length()+1]; + strcpy(tmp2, output.substr(s,s2-s).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + if(isProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + } + mir_free(tmp2); + tmp = mir_utf8decodeW(output.substr(s,s2-s).c_str()); + if(hContact) + ListView_SetItemText(hwndList_p, item_num, 3, tmp); + mir_free(tmp); + } + else + {
+ tmp2 = new char [output.substr(s2,s-s2).length()+1]; + strcpy(tmp2, output.substr(s2,s-s2).c_str()); + mir_utf8decode(tmp2, 0); + if(hContact) + { + if(isProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + DBWriteContactSettingString(hcnt, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + } + } + else + DBWriteContactSettingString(metaGetMostOnline(hContact), szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + } + else + DBWriteContactSettingString(hContact, szGPGModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + } + mir_free(tmp2); + tmp = mir_utf8decodeW(output.substr(s2,s-s2).c_str()); + if(hContact) + ListView_SetItemText(hwndList_p, item_num, 3, tmp); + mir_free(tmp); + } + if(hContact) + { + ListView_SetColumnWidth(hwndList_p, 0, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_p, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_p, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList_p, 3, LVSCW_AUTOSIZE); + } + } + if(!hContact)
+ {
+ char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", "");
+ TCHAR *fp = mir_a2t(tmp);
+ mir_free(tmp);
+ {
+ string out;
+ DWORD code;
+ wstring cmd = _T("--batch -a --export ");
+ cmd += fp;
+ mir_free(fp);
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
+ {
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
+ {
+ MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
+ break;
+ }
+ string::size_type s = 0;
+ while((s = out.find("\r", s)) != string::npos)
+ {
+ out.erase(s, 1);
+ } + DBWriteContactSettingString(hContact, szGPGModuleName, "GPGPubKey", out.c_str()); + } + } + tmp = mir_utf8decodeW(output.c_str()); + MessageBox(0, tmp, _T(""), MB_OK); + mir_free(tmp); + DeleteFile(tmp2); + }
+ key_buf.clear();
+ if(IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ENCRYPTION))
+ {
+ void setSrmmIcon(HANDLE); + void setClistIcon(HANDLE); + if(hContact) + { + if(isProtoMetaContacts(hContact)) + { + HANDLE hcnt = NULL; + if(allsubcontacts) + { + int count = metaGetContactsNum(hContact); + for(int i = 0; i < count; i++) + { + hcnt = metaGetSubcontact(hContact, i); + if(hcnt) + { + if(!isContactSecured(hcnt)) + DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", 1); + else + DBWriteContactSettingByte(hcnt, szGPGModuleName, "GPGEncryption", 0); + setSrmmIcon(hContact); + setClistIcon(hContact); + } + } + } + else if(!isContactSecured(hContact)) + DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 1); + else + DBWriteContactSettingByte(metaGetMostOnline(hContact), szGPGModuleName, "GPGEncryption", 0); + } + else if(!isContactSecured(hContact)) + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); + else + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); } - ListView_SetColumnWidth(hwndList_p, 0, LVSCW_AUTOSIZE);// not sure about this - ListView_SetColumnWidth(hwndList_p, 1, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList_p, 2, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList_p, 3, LVSCW_AUTOSIZE); } - tmp = mir_utf8decodeW(output.c_str()); - MessageBox(0, tmp, _T(""), MB_OK); - mir_free(tmp); - DeleteFile(tmp2); - } - key_buf.clear(); - if(IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ENCRYPTION)) - {
- void setSrmmIcon(HANDLE);
- void setClistIcon(HANDLE); - if(!isContactSecured(hContact)) - DBWriteContactSettingByte(user_data[item_num+1], szGPGModuleName, "GPGEncryption", 1); - else - DBWriteContactSettingByte(user_data[item_num+1], szGPGModuleName, "GPGEncryption", 0); - setSrmmIcon(hContact); - setClistIcon(hContact); - } - DestroyWindow(hwndDlg); - break; + DestroyWindow(hwndDlg); + } + break; case ID_LOAD_FROM_FILE: { tmp = GetFilePath(_T("Set file containing GPG public key"), _T("*"), _T("GPG public key file")); |