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
|
#include "stdafx.h"
static INT_PTR Service_GetCaps(WPARAM wParam, LPARAM)
{
switch (wParam) {
case PFLAGNUM_4:
return PF4_NOCUSTOMAUTH;
case PFLAG_UNIQUEIDTEXT:
return (INT_PTR)TranslateT("Nick");
case PFLAG_MAXLENOFMESSAGE:
return 400;
case PFLAGNUM_2:
case PFLAGNUM_5:
return PF2_ONLINE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND;
}
return 0;
}
static INT_PTR Service_GetName(WPARAM wParam, LPARAM lParam)
{
mir_strncpy((char *)lParam, YAMN_DBMODULE, wParam);
return 0;
}
static INT_PTR Service_LoadIcon(WPARAM wParam, LPARAM)
{
if (LOWORD(wParam) == PLI_PROTOCOL)
return (INT_PTR)CopyIcon(g_plugin.getIcon(IDI_CHECKMAIL)); // noone cares about other than PLI_PROTOCOL
return (INT_PTR)(HICON)NULL;
}
static INT_PTR ContactApplication(WPARAM hContact, LPARAM)
{
char *szProto = Proto_GetBaseAccountName(hContact);
if (mir_strcmp(szProto, YAMN_DBMODULE))
return 0;
if (CAccount *ActualAccount = FindAccountByContact(POP3Plugin, hContact)) {
SReadGuard sra(ActualAccount->AccountAccessSO);
if (sra.Succeeded()) {
if (ActualAccount->NewMailN.App != nullptr) {
CMStringW wszCommand(L"\"");
wszCommand.Append(ActualAccount->NewMailN.App);
wszCommand.Append(L"\" ");
if (ActualAccount->NewMailN.AppParam != nullptr)
wszCommand.Append(ActualAccount->NewMailN.AppParam);
PROCESS_INFORMATION pi;
STARTUPINFOW si = {};
si.cb = sizeof(si);
CreateProcessW(nullptr, wszCommand.GetBuffer(), nullptr, nullptr, FALSE, NORMAL_PRIORITY_CLASS, nullptr, nullptr, &si, &pi);
}
}
}
return 0;
}
// This service will check/synchronize the account
static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM)
{
char *szProto = Proto_GetBaseAccountName(hContact);
if (mir_strcmp(szProto, YAMN_DBMODULE))
return 0;
if (CAccount *ActualAccount = FindAccountByContact(POP3Plugin, hContact)) {
// if we want to close miranda, we get event and do not run pop3 checking anymore
if (WAIT_OBJECT_0 == WaitForSingleObject(ExitEV, 0))
return 0;
mir_cslock lck(PluginRegCS);
SReadGuard sra(ActualAccount->AccountAccessSO);
if (sra.Succeeded()) {
// account cannot be forced to check
if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE))
mir_forkThread<CheckParam>(ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, new CheckParam(ActualAccount, g_plugin.CheckFlags()));
}
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
static void ContactDoubleclicked(WPARAM hContact, LPARAM)
{
char *szProto = Proto_GetBaseAccountName(hContact);
if (mir_strcmp(szProto, YAMN_DBMODULE))
return;
if (CAccount *ActualAccount = FindAccountByContact(POP3Plugin, hContact)) {
SReadGuard sra(ActualAccount->AccountAccessSO);
if (sra.Succeeded()) {
YAMN_MAILBROWSERPARAM Param = { ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, nullptr };
Param.nnflags = Param.nnflags | YAMN_ACC_MSG; // show mails in account even no new mail in account
Param.nnflags = Param.nnflags & ~YAMN_ACC_POP;
Param.nflags = Param.nflags | YAMN_ACC_MSG; // show mails in account even no new mail in account
Param.nflags = Param.nflags & ~YAMN_ACC_POP;
RunMailBrowser(&Param);
}
}
}
INT_PTR ClistContactDoubleclicked(WPARAM, LPARAM lParam)
{
ContactDoubleclicked(((CLISTEVENT *)lParam)->lParam, lParam);
return 0;
}
static int Service_ContactDoubleclicked(WPARAM wParam, LPARAM lParam)
{
ContactDoubleclicked(wParam, lParam);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
HBITMAP LoadBmpFromIcon(HICON hIcon)
{
int IconSizeX = 16;
int IconSizeY = 16;
HBRUSH hBkgBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
BITMAPINFOHEADER bih = {};
bih.biSize = sizeof(bih);
bih.biBitCount = 24;
bih.biPlanes = 1;
bih.biCompression = BI_RGB;
bih.biHeight = IconSizeY;
bih.biWidth = IconSizeX;
RECT rc;
rc.top = rc.left = 0;
rc.right = bih.biWidth;
rc.bottom = bih.biHeight;
HDC hdc = GetDC(nullptr);
HBITMAP hBmp = CreateCompatibleBitmap(hdc, bih.biWidth, bih.biHeight);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hoBmp = (HBITMAP)SelectObject(hdcMem, hBmp);
FillRect(hdcMem, &rc, hBkgBrush);
DrawIconEx(hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, nullptr, DI_NORMAL);
SelectObject(hdcMem, hoBmp);
return hBmp;
}
static int AddTopToolbarIcon(WPARAM, LPARAM)
{
TTBButton btn = {};
btn.pszService = MS_YAMN_FORCECHECK;
btn.dwFlags = TTBBF_VISIBLE | TTBBF_SHOWTOOLTIP;
btn.hIconHandleUp = btn.hIconHandleDn = g_plugin.getIconHandle(IDI_CHECKMAIL);
btn.name = btn.pszTooltipUp = LPGEN("Check mail");
g_plugin.addTTB(&btn);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
int Shutdown(WPARAM, LPARAM)
{
g_plugin.setDword(YAMN_DBMSGPOSX, HeadPosX);
g_plugin.setDword(YAMN_DBMSGPOSY, HeadPosY);
g_plugin.setDword(YAMN_DBMSGSIZEX, HeadSizeX);
g_plugin.setDword(YAMN_DBMSGSIZEY, HeadSizeY);
g_plugin.setWord(YAMN_DBMSGPOSSPLIT, HeadSplitPos);
g_bShutdown = true;
KillTimer(nullptr, SecTimer);
UnregisterProtoPlugins();
return 0;
}
int SystemModulesLoaded(WPARAM, LPARAM); // in main.cpp
void HookEvents(void)
{
HookEvent(ME_SYSTEM_MODULESLOADED, SystemModulesLoaded);
HookEvent(ME_TTB_MODULELOADED, AddTopToolbarIcon);
HookEvent(ME_OPT_INITIALISE, YAMNOptInitSvc);
HookEvent(ME_SYSTEM_PRESHUTDOWN, Shutdown);
HookEvent(ME_CLIST_DOUBLECLICKED, Service_ContactDoubleclicked);
}
void CreateServiceFunctions(void)
{
// Standard 'protocol' services
CreateServiceFunction(YAMN_DBMODULE PS_GETCAPS, Service_GetCaps);
CreateServiceFunction(YAMN_DBMODULE PS_GETNAME, Service_GetName);
CreateServiceFunction(YAMN_DBMODULE PS_LOADICON, Service_LoadIcon);
// Checks mail
CreateServiceFunction(MS_YAMN_FORCECHECK, ForceCheckSvc);
// Function contact list double click
CreateServiceFunction(MS_YAMN_CLISTDBLCLICK, ClistContactDoubleclicked);
// Function contact list context menu click
CreateServiceFunction(MS_YAMN_CLISTCONTEXT, ContactMailCheck);
// Function contact list context menu click
CreateServiceFunction(MS_YAMN_CLISTCONTEXTAPP, ContactApplication);
}
|