summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp7
-rw-r--r--messages.cpp75
2 files changed, 65 insertions, 17 deletions
diff --git a/main.cpp b/main.cpp
index 7d8ef1f..702a9b2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -90,7 +90,8 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM
TCHAR cmd[512];
_tcscpy(cmd, _T("--list-secret-keys"));
pxExecute(cmd, "", &out, &code);
- }
+ }
+ cp866_to_cp1251(&out);
while(p != string::npos)
{
if((p = out.find("sec ", p)) == string::npos)
@@ -112,11 +113,11 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM
mir_free(tmp);
p = out.find("uid ", p);
p2 = out.find_first_not_of(" ", p+5);
- p = out.find(" ", p2);
+ p = out.find("<", p2);
tmp = mir_a2t(out.substr(p2,p-p2).c_str());
ListView_SetItemText(hwndList, iRow, 2, tmp);
mir_free(tmp);
- p = out.find("<", p) + 1;
+ p++;
p2 = out.find(">", p);
tmp = mir_a2t(out.substr(p,p2-p).c_str());
ListView_SetItemText(hwndList, iRow, 1, tmp);
diff --git a/messages.cpp b/messages.cpp
index 2b81167..f6cff09 100644
--- a/messages.cpp
+++ b/messages.cpp
@@ -40,13 +40,59 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
if(!DBGetContactSettingByte(ccs->hContact, szModuleName, "GPGEncryption", 0))
;//
}
- else if(((s2 = str.find(_T("-/ENCRYPTED-"))) != wstring::npos) && ((s1 = str.find(_T("-ENCRYPTED-"))) != wstring::npos))
+ else if((str.find(_T("-----END PGP MESSAGE-----")) != wstring::npos) && (str.find(_T("-----BEGIN PGP MESSAGE-----")) != wstring::npos))
{ //this is generic encrypted data block
if(!DBGetContactSettingByte(ccs->hContact, szModuleName, "GPGEncryption", 0))
;//
+ {
+ wstring::size_type p = 0;
+ while((p = str.find(_T("\r"), p)) != wstring::npos)
+ str.erase(p, 1);
+ }
+ char *tmp = mir_t2a(str.c_str());
+ TCHAR *tmp2 = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
+ wstring path = tmp2;
+ path.append(_T("\\encrypted_data.asc"));
+ wfstream f(path.c_str(), std::ios::out);
+ f<<tmp;
+ mir_free(tmp);
+ f.close();
+ {
+ string out;
+ DWORD code;
+ TCHAR cmd[512] = {0};
+ _tcscpy(cmd, _T(" -d \""));
+ _tcscat(cmd, path.c_str());
+ _tcscat(cmd, _T("\" > "));
+ wstring path2 = tmp2;
+ mir_free(tmp2);
+ path2.append(_T("\\decrypted_data"));
+ _tcscat(cmd, _T("\""));
+ _tcscat(cmd, path2.c_str());
+ _tcscat(cmd, _T("\""));
+ pxExecute(cmd, "", &out, &code);
+ wfstream f(path2.c_str(), std::ios::in);
+ str.clear();
+ while(!f.eof() && f.is_open())
+ {
+ TCHAR tmp[128];
+ f.getline(tmp, 128);
+ str.append(tmp);
+ str.append(_T("\n"));
+ }
+ f.close();
+ DeleteFile(path.c_str());
+ DeleteFile(path2.c_str());
+ if(str.length() > 0)
+ {
+ mir_free((void**)ccs->lParam);
+ char *utf = mir_utf8encodeW(str.c_str());
+ ccs->lParam = (LPARAM)utf;
+ }
+ }
}
else if(((s1 = str.find(_T("<body>This message is encrypted.</body>"))) != wstring::npos))
- { //this is jabber encrypted data
+ { //this is xmpp encrypted data
if(!DBGetContactSettingByte(ccs->hContact, szModuleName, "GPGEncryption", 0))
;//
}
@@ -75,10 +121,9 @@ int SendMsgSvc(WPARAM w, LPARAM l)
{ //encrypt data here
wchar_t *tmp = mir_utf8decodeW(msg);
wstring str = tmp;
- MessageBox(0, str.c_str(), _T(""), MB_OK);
mir_free(tmp);
wstring::size_type s1, s2;
- { //not xmpp
+ { //not xmpp, just replace whole message
string out;
DWORD code;
TCHAR cmd[128];
@@ -94,7 +139,7 @@ int SendMsgSvc(WPARAM w, LPARAM l)
mir_free(tmp);
_tcscat(cmd, tmp2);
mir_free(tmp2);
- _tcscat(cmd, _T("\""));
+ _tcscat(cmd, _T(" \""));
tmp2 = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T(""));
path.append(tmp2);
_tcscat(cmd, tmp2);
@@ -103,28 +148,30 @@ int SendMsgSvc(WPARAM w, LPARAM l)
path.append(_T("\\exported_data"));
_tcscat(cmd, _T("\""));
{
- wfstream f(path.c_str(), std::ios_base::in);
- f<<str;
+ char *tmp = mir_t2a(str.c_str());
+ wfstream f(path.c_str(), std::ios::out);
+ f<<tmp;
+ mir_free(tmp);
f.close();
}
pxExecute(cmd, "", &out, &code);
DeleteFile(path.c_str());
path.append(_T(".asc"));
- wfstream f(path.c_str(), std::ios_base::out);
+ wfstream f(path.c_str(), std::ios::in);
str.clear();
while(!f.eof())
{
TCHAR tmp[128];
f.getline(tmp, 128);
str.append(tmp);
+ str.append(_T("\n"));
}
+ f.close();
+ DeleteFile(path.c_str());
mir_free((void**)ccs->lParam);
- char *utf = mir_utf8encodeW(str.c_str()); //for later usage
- ccs->hContact = utf;
- }
-
-
+ char *utf = mir_utf8encodeW(str.c_str());
+ ccs->lParam = (LPARAM)utf;
+ }
}
-
return CallService(MS_PROTO_CHAINSEND, w, l);
} \ No newline at end of file