1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
#include "stdafx.h"
int OpenBrowser(WPARAM hContact, LPARAM)
{
char *proto = GetContactProto(hContact);
if (proto && !mir_strcmp(proto, MODULE_NAME)) {
Account *curAcc = GetAccountByContact(hContact);
PUDeletePopup(curAcc->popUpHwnd);
pcli->pfnRemoveEvent(curAcc->hContact, 1);
if (GetKeyState(VK_SHIFT) >> 8 || optionWindowIsOpen)
return FALSE;
if (curAcc->oldResults_num != 0) {
db_set_w(curAcc->hContact, MODULE_NAME, "Status", ID_STATUS_NONEW);
curAcc->oldResults_num = 0;
DeleteResults(curAcc->results.next);
curAcc->results.next = NULL;
}
mir_forkthread(Login_ThreadFunc, curAcc);
}
return FALSE;
}
INT_PTR Notifying(WPARAM, LPARAM lParam)
{
OpenBrowser(((CLISTEVENT*)lParam)->hContact, 0);
return 0;
}
static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
MCONTACT hContact = PUGetContact(hWnd);
Account *curAcc = GetAccountByContact(hContact);
switch (message) {
case UM_INITPOPUP:
curAcc->popUpHwnd = hWnd;
break;
case WM_COMMAND:
if (HIWORD(wParam) == STN_CLICKED)
OpenBrowser((WPARAM)hContact, 0);
break;
case WM_CONTEXTMENU:
PUDeletePopup(hWnd);
curAcc->popUpHwnd = NULL;
pcli->pfnRemoveEvent(hContact, 1);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
void NotifyUser(Account *curAcc)
{
if (optionWindowIsOpen)
return;
db_set_s(curAcc->hContact, "CList", "MyHandle", curAcc->results.content);
switch (curAcc->results_num) {
case 0:
PUDeletePopup(curAcc->popUpHwnd);
pcli->pfnRemoveEvent(curAcc->hContact, 1);
if (curAcc->oldResults_num != 0)
db_set_w(curAcc->hContact, MODULE_NAME, "Status", ID_STATUS_NONEW);
break;
case -1:
db_set_w(curAcc->hContact, MODULE_NAME, "Status", ID_STATUS_AWAY);
break;
default:
db_set_w(curAcc->hContact, MODULE_NAME, "Status", ID_STATUS_OCCUPIED);
int newMails = (curAcc->oldResults_num == -1) ? (curAcc->results_num) : (curAcc->results_num - curAcc->oldResults_num);
if (opt.LogThreads&&newMails > 0) {
DBEVENTINFO dbei = { sizeof(dbei) };
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.flags = DBEF_READ;
dbei.szModule = MODULE_NAME;
dbei.timestamp = time(NULL);
resultLink *prst = curAcc->results.next;
for (int i = 0; i < newMails; i++) {
dbei.cbBlob = (DWORD)mir_strlen(prst->content) + 1;
dbei.pBlob = (PBYTE)prst->content;
db_event_add(curAcc->hContact, &dbei);
prst = prst->next;
}
}
if (opt.notifierOnTray&&newMails > 0) {
pcli->pfnRemoveEvent(curAcc->hContact, 1);
CLISTEVENT cle = {};
cle.hContact = curAcc->hContact;
cle.hDbEvent = 1;
cle.flags = CLEF_URGENT;
cle.hIcon = Skin_LoadProtoIcon(MODULE_NAME, ID_STATUS_OCCUPIED);
cle.pszService = "GmailMNotifier/Notifying";
cle.pszTooltip = curAcc->results.next->content;
pcli->pfnAddEvent(&cle);
}
if (opt.notifierOnPop&&newMails > 0) {
POPUPDATA ppd = { 0 };
ppd.lchContact = curAcc->hContact;
ppd.lchIcon = Skin_LoadProtoIcon(MODULE_NAME, ID_STATUS_OCCUPIED);
mir_strcpy(ppd.lpzContactName, curAcc->results.content);
resultLink *prst = curAcc->results.next;
for (int i = 0; i < 5 && i < newMails; i++) {
mir_strcat(ppd.lpzText, prst->content);
mir_strcat(ppd.lpzText, "\n");
prst = prst->next;
}
ppd.colorBack = opt.popupBgColor;
ppd.colorText = opt.popupTxtColor;
ppd.PluginWindowProc = PopupDlgProc;
ppd.PluginData = NULL;
ppd.iSeconds = opt.popupDuration;
PUDeletePopup(curAcc->popUpHwnd);
PUAddPopup(&ppd);
}
if (newMails > 0)
SkinPlaySound("Gmail");
}
curAcc->oldResults_num = curAcc->results_num;
DeleteResults(curAcc->results.next);
curAcc->results.next = NULL;
}
void DeleteResults(resultLink *prst)
{
if (prst != NULL) {
if (prst->next != NULL)
DeleteResults(prst->next);
free(prst);
}
}
void __cdecl Login_ThreadFunc(void *lpParam)
{
if (lpParam == NULL)
return;
HANDLE hTempFile;
DWORD dwBytesWritten, dwBufSize = 1024;
char szTempName[MAX_PATH];
char buffer[1024];
char *str_temp;
char lpPathBuffer[1024];
Account *curAcc = (Account *)lpParam;
if (GetBrowser(lpPathBuffer)) {
if (opt.AutoLogin == 0) {
if (curAcc->hosted[0]) {
mir_strcat(lpPathBuffer, "https://mail.google.com/a/");
mir_strcat(lpPathBuffer, curAcc->hosted);
mir_strcat(lpPathBuffer, "/?logout");
}
else {
mir_strcat(lpPathBuffer, "https://mail.google.com/mail/?logout");
}
}
else {
if (curAcc->hosted[0]) {
GetTempPathA(dwBufSize, buffer);
GetTempFileNameA(buffer, "gmail", 0, szTempName);
hTempFile = CreateFileA(szTempName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
mir_strcpy(buffer, FORMDATA1);
mir_strcat(buffer, curAcc->hosted);
mir_strcat(buffer, FORMDATA2);
mir_strcat(buffer, curAcc->hosted);
mir_strcat(buffer, FORMDATA3);
mir_strcat(buffer, "<input type=hidden name=userName value=");
mir_strcat(buffer, curAcc->name);
if ((str_temp = strstr(buffer, "@")) != NULL)
*str_temp = '\0';
mir_strcat(buffer, "><input type=hidden name=password value=");
mir_strcat(buffer, curAcc->pass);
mir_strcat(buffer, "></form></body>");
WriteFile(hTempFile, buffer, (DWORD)mir_strlen(buffer), &dwBytesWritten, NULL);
CloseHandle(hTempFile);
mir_strcat(lpPathBuffer, szTempName);
}
else {
char *szEncodedURL = mir_urlEncode(curAcc->name);
mir_strcat(lpPathBuffer, LINK);
mir_strcat(lpPathBuffer, szEncodedURL);
//mir_strcat(lpPathBuffer, "&Passwd=");
//mir_strcat(lpPathBuffer, mir_urlEncode(curAcc->pass));
if (opt.AutoLogin == 1)
mir_strcat(lpPathBuffer, "&PersistentCookie=yes");
mir_free(szEncodedURL);
}
}
}
STARTUPINFOA suInfo = { 0 };
PROCESS_INFORMATION procInfo;
suInfo.cb = sizeof(suInfo);
suInfo.wShowWindow = SW_MAXIMIZE;
if (CreateProcessA(NULL, lpPathBuffer, NULL, NULL, FALSE, 0, NULL, NULL, &suInfo, &procInfo))
CloseHandle(procInfo.hProcess);
if (curAcc->hosted[0]) {
Sleep(30000);
DeleteFileA(szTempName);
}
}
|