diff options
-rw-r--r-- | protocols/YAMN/YAMN.vcxproj | 3 | ||||
-rw-r--r-- | protocols/YAMN/YAMN.vcxproj.filters | 9 | ||||
-rw-r--r-- | protocols/YAMN/res/YAMN.rc | 17 | ||||
-rw-r--r-- | protocols/YAMN/src/account.cpp | 15 | ||||
-rw-r--r-- | protocols/YAMN/src/account.h (renamed from plugins/ExternalAPI/m_account.h) | 670 | ||||
-rw-r--r-- | protocols/YAMN/src/browser/mailbrowser.cpp | 8 | ||||
-rw-r--r-- | protocols/YAMN/src/mails/mails.h (renamed from plugins/ExternalAPI/m_mails.h) | 446 | ||||
-rw-r--r-- | protocols/YAMN/src/main.cpp | 3 | ||||
-rw-r--r-- | protocols/YAMN/src/proto/pop3/pop3comm.cpp | 78 | ||||
-rw-r--r-- | protocols/YAMN/src/proto/pop3/pop3opt.cpp | 5 | ||||
-rw-r--r-- | protocols/YAMN/src/protoplugin.h (renamed from plugins/ExternalAPI/m_protoplugin.h) | 410 | ||||
-rw-r--r-- | protocols/YAMN/src/resource.h | 5 | ||||
-rw-r--r-- | protocols/YAMN/src/services.cpp | 14 | ||||
-rw-r--r-- | protocols/YAMN/src/stdafx.h | 22 | ||||
-rw-r--r-- | protocols/YAMN/src/yamn.cpp | 58 |
15 files changed, 855 insertions, 908 deletions
diff --git a/protocols/YAMN/YAMN.vcxproj b/protocols/YAMN/YAMN.vcxproj index 889075d551..58ad133ee9 100644 --- a/protocols/YAMN/YAMN.vcxproj +++ b/protocols/YAMN/YAMN.vcxproj @@ -63,8 +63,11 @@ </ClCompile>
<ClCompile Include="src\synchro.cpp" />
<ClCompile Include="src\yamn.cpp" />
+ <ClInclude Include="src\account.h" />
<ClInclude Include="src\browser\browser.h" />
<ClInclude Include="src\mails\decode.h" />
+ <ClInclude Include="src\mails\mails.h" />
+ <ClInclude Include="src\protoplugin.h" />
<ClInclude Include="src\proto\netlib.h" />
<ClInclude Include="src\proto\pop3\pop3.h" />
<ClInclude Include="src\proto\pop3\pop3comm.h" />
diff --git a/protocols/YAMN/YAMN.vcxproj.filters b/protocols/YAMN/YAMN.vcxproj.filters index 522437edf9..5b637396bf 100644 --- a/protocols/YAMN/YAMN.vcxproj.filters +++ b/protocols/YAMN/YAMN.vcxproj.filters @@ -88,6 +88,15 @@ <ClInclude Include="src\main.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="src\account.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\protoplugin.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\mails\mails.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\Version.rc">
diff --git a/protocols/YAMN/res/YAMN.rc b/protocols/YAMN/res/YAMN.rc index 4e8460b858..20338bf727 100644 --- a/protocols/YAMN/res/YAMN.rc +++ b/protocols/YAMN/res/YAMN.rc @@ -91,8 +91,6 @@ BEGIN IDD_POP3ACCOUNTPOPUP, DIALOG
BEGIN
- VERTGUIDE, 155
- VERTGUIDE, 236
END
END
#endif // APSTUDIO_INVOKED
@@ -224,8 +222,8 @@ STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_VISIBLE EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
- COMBOBOX IDC_COMBOACCOUNT,4,4,140,65,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
- GROUPBOX "Mail Notifications",IDC_GBNEWMAIL,5,23,300,76
+ COMBOBOX IDC_COMBOACCOUNT,2,4,140,65,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+ GROUPBOX "Mail Notifications",IDC_GBNEWMAIL,0,23,300,76
CONTROL "Popup",IDC_CHECKPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,32,108,10
CONTROL "Single popup",IDC_RADIOPOP1,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,23,43,95,10
CONTROL "Multi popup",IDC_RADIOPOPN,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,23,55,95,10
@@ -233,14 +231,14 @@ BEGIN CONTROL "",IDC_CPB,"ColourPicker",WS_TABSTOP,145,66,29,12
CONTROL "",IDC_CPT,"ColourPicker",WS_TABSTOP,145,83,29,12
EDITTEXT IDC_EDITPOPS,23,65,20,12,ES_AUTOHSCROLL
- GROUPBOX "No new mail notifications",IDC_GBNONEWMAIL,5,152,300,62
+ GROUPBOX "No new mail notifications",IDC_GBNONEWMAIL,0,152,300,62
CONTROL "Popup if no mail",IDC_CHECKNPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,161,94,10
CONTROL "Persistent message",IDC_CHECKNMSGP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,188,110,10
CONTROL "Use custom color",IDC_CHECKNCOL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,201,107,10
CONTROL "",IDC_CPNB,"ColourPicker",WS_TABSTOP,145,181,29,12
CONTROL "",IDC_CPNT,"ColourPicker",WS_TABSTOP,145,198,29,12
EDITTEXT IDC_EDITNPOPS,23,173,20,12,ES_AUTOHSCROLL
- GROUPBOX "Connection failure notifications",IDC_GBBADCONNECT,5,101,300,49
+ GROUPBOX "Connection failure notifications",IDC_GBBADCONNECT,0,101,300,49
CONTROL "Popup notification if failed",IDC_CHECKFPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,110,118,10
CONTROL "Use custom color",IDC_CHECKFCOL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,136,95,10
CONTROL "",IDC_CPFB,"ColourPicker",WS_TABSTOP,145,118,29,12
@@ -256,6 +254,8 @@ BEGIN LTEXT "Text color",IDC_STATIC,177,136,107,10
LTEXT "Background color",IDC_STATIC,177,69,108,10
LTEXT "Text color",IDC_STATIC,177,85,107,10
+ CONTROL "Force popups for manual operations",IDC_FORCECHECK,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,218,231,10
END
@@ -290,6 +290,11 @@ BEGIN 0
END
+IDD_POP3ACCOUNTPOPUP AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
#endif // Neutral resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/YAMN/src/account.cpp b/protocols/YAMN/src/account.cpp index 7609a23e18..3c834b28cc 100644 --- a/protocols/YAMN/src/account.cpp +++ b/protocols/YAMN/src/account.cpp @@ -22,11 +22,6 @@ static mir_cs csFileWritingCS; void CAccount::CheckMail()
{
- // we use event to signal, that running thread has all needed stack parameters copied
- HANDLE ThreadRunningEV = CreateEvent(nullptr, FALSE, FALSE, nullptr);
- if (ThreadRunningEV == nullptr)
- return;
-
// if we want to close miranda, we get event and do not run pop3 checking anymore
if (WAIT_OBJECT_0 == WaitForSingleObject(ExitEV, 0))
return;
@@ -35,18 +30,10 @@ void CAccount::CheckMail() SReadGuard sra(AccountAccessSO, 0);
if (sra.Succeeded()) {
if ((Flags & YAMN_ACC_ENA) && Plugin->Fcn->SynchroFcnPtr) {
- CheckParam ParamToPlugin = { YAMN_CHECKVERSION, ThreadRunningEV, this };
-
TimeLeft = Interval;
- DWORD tid;
- HANDLE NewThread = CreateThread(nullptr, 0, (YAMN_STANDARDFCN)Plugin->Fcn->SynchroFcnPtr, &ParamToPlugin, 0, &tid);
- if (NewThread) {
- WaitForSingleObject(ThreadRunningEV, INFINITE);
- CloseHandle(NewThread);
- }
+ mir_forkThread<CheckParam>(Plugin->Fcn->SynchroFcnPtr, new CheckParam(this, g_plugin.CheckFlags()));
}
}
- CloseHandle(ThreadRunningEV);
}
void CAccount::RefreshContact()
diff --git a/plugins/ExternalAPI/m_account.h b/protocols/YAMN/src/account.h index 11458828ce..cadd83a1ec 100644 --- a/plugins/ExternalAPI/m_account.h +++ b/protocols/YAMN/src/account.h @@ -1,335 +1,335 @@ -/*
- * This file defines all needed parameters for one account.
- * Other plugin can use this (so YAMN does not check it and another plugin can inform YAMN about new mail e.g.),
- * this can be usefull for plugins like MSN (Hotmail notify)
- *
- * (c) majvan 2002-2004
- */
-
-#ifndef __ACCOUNT_H
-#define __ACCOUNT_H
-
-#include <windows.h>
-#include <tchar.h>
-
- //
- //================================== OTHER DEFINITIONS ========================================
- //
-
-enum
-{
- // Error codes returned from functions (services) working with account book files
- EACC_SYSTEM = 1, //use GetLastError() to retrieve detailed information about error
- EACC_ALLOC, //problem with memory allocation
- EACC_FILECOMPATIBILITY, //file is corrupted
- EACC_ENDOFFILE, //unexpected end of file occured
- EACC_FILEVERSION, //file should be YAMN book format, but newer version that expected
- EACC_FILESIZE, //file has wrong size
-};
-
-enum
-{
- // Status of account
- // used in messages WM_YAMN_CHANGESTATUS
- // used also in function GetStatus and SetStatus
- ACC_IDLE = 0, //account is IDLE (no work is performed with account)
- ACC_FINDING, //DNS lookup for account
- ACC_CONNECTING, //connecting in progress
- ACC_LOGGING, //logging in progress
- ACC_WORKING, //working
- ACC_DISCONNECTING, //disconnecting from server
-};
-
-#define YAMN_ACC_MSG 0x00000002 // Shows dialog
-#define YAMN_ACC_ICO 0x00000004 // Shows system tray icon (1)
-#define YAMN_ACC_ICOB 0x00000008 // not used now, enables tray icon flashing (1)
-#define YAMN_ACC_APP 0x00000010 // Runs application (1)
-#define YAMN_ACC_POP 0x00000020 // Shows popup
-#define YAMN_ACC_POPC 0x00000040 // Use custom colors in popup
-#define YAMN_ACC_MSGP 0x00000080 // Persistant messgage. This means, when an situation occurs (e.g. new mail) and message is displayed, it is not destroyed when YAMN_ACC_MSG is not set
-#define YAMN_ACC_KBN 0x00000100 // Use Keyboard notify
-#define YAMN_ACC_CONT 0x00000200 // Use Contact notify
-#define YAMN_ACC_CONTNICK 0x00000400 // Use Contact Nick replacement
-#define YAMN_ACC_CONTNOEVENT 0x00000800 // Suppress event for this contact
-
-struct YAMN_NOTIFICATION
-{
- //(1) - usable only in newmail notification
- DWORD Flags = 0;
-
- COLORREF PopupB = 0;
- COLORREF PopupT = 0;
- DWORD PopupTime = 0;
- WCHAR *App = nullptr;
- WCHAR *AppParam = nullptr;
-
- // These parameters are not stored in standard YAMN book file and therefore must be set by plugin
- char *Sound = nullptr;
- HICON TrayIcon1 = nullptr;
- HICON TrayIcon2 = nullptr;
-};
-
-struct CServer
-{
- char *Name = nullptr;
- DWORD Port = 0;
-
- char *Login = nullptr;
-
- // Password encryption definitions
- #define STARTCODEPSW 0x50
- #define ADDCODEPSW 0x0
- char *Passwd = nullptr;
-};
-
-//
-//================================== ACCOUNT DEFINITION ==================================
-//
-
-#define WAIT_FINISH WAIT_OBJECT_0+1
-
-// This structure is used to get semaphore-like synchronization:
-// Includes incrementing, decrementing DWORD value and if DWORD is zero, sets event
-class SCOUNTER
-{
- HANDLE Event;
- uint32_t Number = 0;
- CRITICAL_SECTION CounterCS;
-
-public:
- SCOUNTER();
- SCOUNTER(HANDLE InitializedEvent);
- ~SCOUNTER();
-
- __forceinline HANDLE GetEvent() const { return Event; }
-
- uint32_t GetNumber();
- uint32_t Inc();
- uint32_t Dec();
-};
-
-struct SCGuard
-{
- SCOUNTER &pSC;
-
- __forceinline SCGuard(SCOUNTER &sc) :
- pSC(sc)
- {
- sc.Inc();
- }
-
- __forceinline ~SCGuard()
- {
- pSC.Dec();
- }
-};
-
-// The single-writer/multiple-reader guard
-// compound synchronization object (SO)
-// Notices: Copyright (c) 1995-1997 Jeffrey Richter
-// Changes: majvan, only one process implementation,
-// hFinishEV event added- signals when we do not want to use this SO anymore
-
-class SWMRG
-{
- // This event guards access to the other objects
- // managed by this data structure and also indicates
- // whether any writer threads are writing.
- HANDLE hEventNoWriter;
-
- // This manual-reset event is signaled when
- // no reader threads are reading.
- HANDLE hEventNoReaders;
-
- // This value is used simply as a counter.
- // (the count is the number of reader threads)
- HANDLE hSemNumReaders;
-
- // The request is for not to enter critical section
- // for writing or reading due to going to delete guard
- HANDLE hFinishEV;
-
-public:
- SWMRG(wchar_t *Name = nullptr);
- ~SWMRG();
-
- uint32_t WaitToWrite(uint32_t dwTimeout = INFINITE);
- void DoneWriting();
-
- uint32_t WaitToRead(uint32_t dwTimeout = INFINITE);
- void DoneReading();
-
- void Stop()
- {
- ::SetEvent(hFinishEV);
- }
-};
-
-struct SReadGuard
-{
- SWMRG &pSO;
- uint32_t dwError;
-
- SReadGuard(SWMRG &so, uint32_t timeout = INFINITE) :
- pSO(so)
- {
- dwError = so.WaitToRead(timeout);
- }
-
- ~SReadGuard()
- {
- Uninit();
- }
-
- bool Succeeded() const
- {
- return dwError == WAIT_OBJECT_0;
- }
-
- void Uninit()
- {
- if (dwError == WAIT_OBJECT_0) {
- pSO.DoneReading();
- dwError = WAIT_FINISH;
- }
- }
-
- operator uint32_t() const { return dwError; }
-};
-
-struct SWriteGuard
-{
- SWMRG &pSO;
- uint32_t dwError;
-
- SWriteGuard(SWMRG &so, uint32_t timeout = INFINITE) :
- pSO(so)
- {
- dwError = so.WaitToWrite(timeout);
- }
-
- ~SWriteGuard()
- {
- Uninit();
- }
-
- bool Succeeded() const
- {
- return dwError == WAIT_OBJECT_0;
- }
-
- void Uninit()
- {
- if (dwError == WAIT_OBJECT_0) {
- pSO.DoneWriting();
- dwError = WAIT_FINISH;
- }
- }
-
- operator uint32_t() const { return dwError; }
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// CAccount - basic email account class
-
-struct CAccount : public MZeroedObject
-{
- #define YAMN_ACCOUNTFILEVERSION 2 //version of standard file format (YAMN book file format)
-
- // If changes are made in this structure, version is changed.
- // So then YAMN does not initialzie your structure, if version does not matches.
-
- BOOL AbleToWork; // This is set to TRUE by default. When it is needed to stop working on this account, YAMN sets this to zero.
-
- struct YAMN_PROTOPLUGIN *Plugin; // free access, because this member should not be changed. The same as YAMN_PLUGIN structure
-
- char *Name; // access only through AccountAccessSO
-
- CServer *Server; //access only through AccountAccessSO
-
- WORD Interval; //access only through AccountAccessSO
-
- // YAMN account flags (set by user)
- #define YAMN_ACC_ENA 0x00000001 //Enables account. If account is disabled, no countdown is performed
- #define YAMN_ACC_POPN 0x00000002 //Shows one popup per one new mail or for N mails
- #define YAMN_ACC_APOP 0x00000004 //Use APOP authentication
- #define YAMN_ACC_SSL23 0x00000008 //Use SSLv2,3
- #define YAMN_ACC_NOTLS 0x00000010 //Don't try StartTLS (STLS) even available
- #define YAMN_ACC_BODY 0x00000020 //Always retrieve body of the message
- DWORD Flags; //access only through AccountAccessSO
-
- // YAMN account flags (set by plugin)
- #define YAMN_ACC_BROWSE 0x00000001 //Can browse mails. On this account we can run mailbrowser window
- #define YAMN_ACC_POPUP 0x00000002 //Popups of new mail belonging to this account can be showed
- DWORD AbilityFlags;
-
- // YAMN account status flags
- #define YAMN_ACC_ST0 0x00000001 // Check (countdown) when Offline
- #define YAMN_ACC_ST1 0x00000002 // Check (countdown) when Online
- #define YAMN_ACC_ST2 0x00000004 // Check (countdown) when Away
- #define YAMN_ACC_ST3 0x00000008 // Check (countdown) when Not available
- #define YAMN_ACC_ST4 0x00000010 // Check (countdown) when Occupied
- #define YAMN_ACC_ST5 0x00000020 // Check (countdown) when DND
- #define YAMN_ACC_ST6 0x00000040 // Check (countdown) when Free for chat
- #define YAMN_ACC_ST7 0x00000080 // Check (countdown) when Invisible
-
- #define YAMN_ACC_STARTA 0x00010000 // Check on start anyway
- #define YAMN_ACC_STARTS 0x00020000 // Check on start regarding to status setting
- #define YAMN_ACC_FORCE 0x00040000 // Check when "check new mail" item pressed (it is called forced checking)
- DWORD StatusFlags; // access only through AccountAccessSO
-
- // Plugin flags. Use this DWORD if you want YAMN to store it to YAMN book file. You can set here any value
- DWORD PluginFlags;
-
- YAMN_NOTIFICATION NewMailN; //access only through AccountAccessSO
- YAMN_NOTIFICATION NoNewMailN; //access only through AccountAccessSO
- YAMN_NOTIFICATION BadConnectN; //access only through AccountAccessSO
-
- SYSTEMTIME LastChecked; //last check, access only through AccountAccessSO
- SYSTEMTIME LastSChecked; //last check (successfull), access only through AccountAccessSO
- SYSTEMTIME LastSynchronised; //last synchronisation (successfull), access only through AccountAccessSO
- SYSTEMTIME LastMail; //last check when new mail detected, access only through AccountAccessSO
-
- TCHAR Status[255]; //access only through GetStatusFcn() and SetStatusFcn() functions
-
- DWORD TimeLeft; //access only through AccountAccessSO
-
- HANDLE Mails; //access only through MessagesAccessSO
-
- // Account members are mostly the same, but there can be protocol (POP3,IMAP...) special features.
- // To use them, only inherit this class and add your own features.
- // First idea was to add pointer to void, where plugin can store its own values.
- // But this solution is better in my opinion.
-
- // This is event with counter. Event is signaled when no threads are using account (and will not be using)
- // Very usefull for account delete operation
- SCOUNTER UsingThreads;
-
- // We have to achieve, that only one thread can write to account and more threads can read.
- // Writing to account means that we change account parameters
- // Reading from account meands we read account parameters
- // Use WaitToRead(), ReadDone(), WaitToWrite(), WriteDone() synchronization functions
- // For plugins, this is a pointer to void. It does not matter for plugin what is this variable for,
- // because plugin works only with synchronization routines. And why is this void * ? It is because
- // plugin does not need to include headers for SWMRG structures...
- SWMRG AccountAccessSO;
-
- // We have to achieve, that only one thread can write to account mails and more threads can read.
- // While some thread writes mails, other thread can write to account. This can be small problem, but it never appears in YAMN.
- // But you should think about this note if you want to add some features in the future
- // Writing to messages means any changes to message queue or message data
- // Reading from messages means reading message queue (browsing through all messages) or reading message data
- // Use MsgsWaitToRead(),MsgsReadDone(),MsgsWaitToWrite(),MsgsWriteDone() synchronization functions
- SWMRG MessagesAccessSO;
-
- //For clist contact notification
- MCONTACT hContact;
- BOOL isCounting;
-
- CAccount *Next;
-
- void CheckMail();
- void RefreshContact();
-};
-
-#endif
+/* + * This file defines all needed parameters for one account. + * Other plugin can use this (so YAMN does not check it and another plugin can inform YAMN about new mail e.g.), + * this can be usefull for plugins like MSN (Hotmail notify) + * + * (c) majvan 2002-2004 + */ + +#ifndef __ACCOUNT_H +#define __ACCOUNT_H + +#include <windows.h> +#include <tchar.h> + + // + //================================== OTHER DEFINITIONS ======================================== + // + +enum +{ + // Error codes returned from functions (services) working with account book files + EACC_SYSTEM = 1, //use GetLastError() to retrieve detailed information about error + EACC_ALLOC, //problem with memory allocation + EACC_FILECOMPATIBILITY, //file is corrupted + EACC_ENDOFFILE, //unexpected end of file occured + EACC_FILEVERSION, //file should be YAMN book format, but newer version that expected + EACC_FILESIZE, //file has wrong size +}; + +enum +{ + // Status of account + // used in messages WM_YAMN_CHANGESTATUS + // used also in function GetStatus and SetStatus + ACC_IDLE = 0, //account is IDLE (no work is performed with account) + ACC_FINDING, //DNS lookup for account + ACC_CONNECTING, //connecting in progress + ACC_LOGGING, //logging in progress + ACC_WORKING, //working + ACC_DISCONNECTING, //disconnecting from server +}; + +#define YAMN_ACC_MSG 0x00000002 // Shows dialog +#define YAMN_ACC_ICO 0x00000004 // Shows system tray icon (1) +#define YAMN_ACC_ICOB 0x00000008 // not used now, enables tray icon flashing (1) +#define YAMN_ACC_APP 0x00000010 // Runs application (1) +#define YAMN_ACC_POP 0x00000020 // Shows popup +#define YAMN_ACC_POPC 0x00000040 // Use custom colors in popup +#define YAMN_ACC_MSGP 0x00000080 // Persistant messgage. This means, when an situation occurs (e.g. new mail) and message is displayed, it is not destroyed when YAMN_ACC_MSG is not set +#define YAMN_ACC_KBN 0x00000100 // Use Keyboard notify +#define YAMN_ACC_CONT 0x00000200 // Use Contact notify +#define YAMN_ACC_CONTNICK 0x00000400 // Use Contact Nick replacement +#define YAMN_ACC_CONTNOEVENT 0x00000800 // Suppress event for this contact + +struct YAMN_NOTIFICATION +{ + //(1) - usable only in newmail notification + DWORD Flags = 0; + + COLORREF PopupB = 0; + COLORREF PopupT = 0; + DWORD PopupTime = 0; + WCHAR *App = nullptr; + WCHAR *AppParam = nullptr; + + // These parameters are not stored in standard YAMN book file and therefore must be set by plugin + char *Sound = nullptr; + HICON TrayIcon1 = nullptr; + HICON TrayIcon2 = nullptr; +}; + +struct CServer +{ + char *Name = nullptr; + DWORD Port = 0; + + char *Login = nullptr; + + // Password encryption definitions + #define STARTCODEPSW 0x50 + #define ADDCODEPSW 0x0 + char *Passwd = nullptr; +}; + +// +//================================== ACCOUNT DEFINITION ================================== +// + +#define WAIT_FINISH WAIT_OBJECT_0+1 + +// This structure is used to get semaphore-like synchronization: +// Includes incrementing, decrementing DWORD value and if DWORD is zero, sets event +class SCOUNTER +{ + HANDLE Event; + uint32_t Number = 0; + CRITICAL_SECTION CounterCS; + +public: + SCOUNTER(); + SCOUNTER(HANDLE InitializedEvent); + ~SCOUNTER(); + + __forceinline HANDLE GetEvent() const { return Event; } + + uint32_t GetNumber(); + uint32_t Inc(); + uint32_t Dec(); +}; + +struct SCGuard +{ + SCOUNTER &pSC; + + __forceinline SCGuard(SCOUNTER &sc) : + pSC(sc) + { + sc.Inc(); + } + + __forceinline ~SCGuard() + { + pSC.Dec(); + } +}; + +// The single-writer/multiple-reader guard +// compound synchronization object (SO) +// Notices: Copyright (c) 1995-1997 Jeffrey Richter +// Changes: majvan, only one process implementation, +// hFinishEV event added- signals when we do not want to use this SO anymore + +class SWMRG +{ + // This event guards access to the other objects + // managed by this data structure and also indicates + // whether any writer threads are writing. + HANDLE hEventNoWriter; + + // This manual-reset event is signaled when + // no reader threads are reading. + HANDLE hEventNoReaders; + + // This value is used simply as a counter. + // (the count is the number of reader threads) + HANDLE hSemNumReaders; + + // The request is for not to enter critical section + // for writing or reading due to going to delete guard + HANDLE hFinishEV; + +public: + SWMRG(wchar_t *Name = nullptr); + ~SWMRG(); + + uint32_t WaitToWrite(uint32_t dwTimeout = INFINITE); + void DoneWriting(); + + uint32_t WaitToRead(uint32_t dwTimeout = INFINITE); + void DoneReading(); + + void Stop() + { + ::SetEvent(hFinishEV); + } +}; + +struct SReadGuard +{ + SWMRG &pSO; + uint32_t dwError; + + SReadGuard(SWMRG &so, uint32_t timeout = INFINITE) : + pSO(so) + { + dwError = so.WaitToRead(timeout); + } + + ~SReadGuard() + { + Uninit(); + } + + bool Succeeded() const + { + return dwError == WAIT_OBJECT_0; + } + + void Uninit() + { + if (dwError == WAIT_OBJECT_0) { + pSO.DoneReading(); + dwError = WAIT_FINISH; + } + } + + operator uint32_t() const { return dwError; } +}; + +struct SWriteGuard +{ + SWMRG &pSO; + uint32_t dwError; + + SWriteGuard(SWMRG &so, uint32_t timeout = INFINITE) : + pSO(so) + { + dwError = so.WaitToWrite(timeout); + } + + ~SWriteGuard() + { + Uninit(); + } + + bool Succeeded() const + { + return dwError == WAIT_OBJECT_0; + } + + void Uninit() + { + if (dwError == WAIT_OBJECT_0) { + pSO.DoneWriting(); + dwError = WAIT_FINISH; + } + } + + operator uint32_t() const { return dwError; } +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// CAccount - basic email account class + +struct CAccount : public MZeroedObject +{ + #define YAMN_ACCOUNTFILEVERSION 2 //version of standard file format (YAMN book file format) + + // If changes are made in this structure, version is changed. + // So then YAMN does not initialzie your structure, if version does not matches. + + BOOL AbleToWork; // This is set to TRUE by default. When it is needed to stop working on this account, YAMN sets this to zero. + + struct YAMN_PROTOPLUGIN *Plugin; // free access, because this member should not be changed. The same as YAMN_PLUGIN structure + + char *Name; // access only through AccountAccessSO + + CServer *Server; //access only through AccountAccessSO + + WORD Interval; //access only through AccountAccessSO + + // YAMN account flags (set by user) + #define YAMN_ACC_ENA 0x00000001 //Enables account. If account is disabled, no countdown is performed + #define YAMN_ACC_POPN 0x00000002 //Shows one popup per one new mail or for N mails + #define YAMN_ACC_APOP 0x00000004 //Use APOP authentication + #define YAMN_ACC_SSL23 0x00000008 //Use SSLv2,3 + #define YAMN_ACC_NOTLS 0x00000010 //Don't try StartTLS (STLS) even available + #define YAMN_ACC_BODY 0x00000020 //Always retrieve body of the message + DWORD Flags; //access only through AccountAccessSO + + // YAMN account flags (set by plugin) + #define YAMN_ACC_BROWSE 0x00000001 //Can browse mails. On this account we can run mailbrowser window + #define YAMN_ACC_POPUP 0x00000002 //Popups of new mail belonging to this account can be showed + DWORD AbilityFlags; + + // YAMN account status flags + #define YAMN_ACC_ST0 0x00000001 // Check (countdown) when Offline + #define YAMN_ACC_ST1 0x00000002 // Check (countdown) when Online + #define YAMN_ACC_ST2 0x00000004 // Check (countdown) when Away + #define YAMN_ACC_ST3 0x00000008 // Check (countdown) when Not available + #define YAMN_ACC_ST4 0x00000010 // Check (countdown) when Occupied + #define YAMN_ACC_ST5 0x00000020 // Check (countdown) when DND + #define YAMN_ACC_ST6 0x00000040 // Check (countdown) when Free for chat + #define YAMN_ACC_ST7 0x00000080 // Check (countdown) when Invisible + + #define YAMN_ACC_STARTA 0x00010000 // Check on start anyway + #define YAMN_ACC_STARTS 0x00020000 // Check on start regarding to status setting + #define YAMN_ACC_FORCE 0x00040000 // Check when "check new mail" item pressed (it is called forced checking) + DWORD StatusFlags; // access only through AccountAccessSO + + // Plugin flags. Use this DWORD if you want YAMN to store it to YAMN book file. You can set here any value + DWORD PluginFlags; + + YAMN_NOTIFICATION NewMailN; //access only through AccountAccessSO + YAMN_NOTIFICATION NoNewMailN; //access only through AccountAccessSO + YAMN_NOTIFICATION BadConnectN; //access only through AccountAccessSO + + SYSTEMTIME LastChecked; //last check, access only through AccountAccessSO + SYSTEMTIME LastSChecked; //last check (successfull), access only through AccountAccessSO + SYSTEMTIME LastSynchronised; //last synchronisation (successfull), access only through AccountAccessSO + SYSTEMTIME LastMail; //last check when new mail detected, access only through AccountAccessSO + + TCHAR Status[255]; //access only through GetStatusFcn() and SetStatusFcn() functions + + DWORD TimeLeft; //access only through AccountAccessSO + + HANDLE Mails; //access only through MessagesAccessSO + + // Account members are mostly the same, but there can be protocol (POP3,IMAP...) special features. + // To use them, only inherit this class and add your own features. + // First idea was to add pointer to void, where plugin can store its own values. + // But this solution is better in my opinion. + + // This is event with counter. Event is signaled when no threads are using account (and will not be using) + // Very usefull for account delete operation + SCOUNTER UsingThreads; + + // We have to achieve, that only one thread can write to account and more threads can read. + // Writing to account means that we change account parameters + // Reading from account meands we read account parameters + // Use WaitToRead(), ReadDone(), WaitToWrite(), WriteDone() synchronization functions + // For plugins, this is a pointer to void. It does not matter for plugin what is this variable for, + // because plugin works only with synchronization routines. And why is this void * ? It is because + // plugin does not need to include headers for SWMRG structures... + SWMRG AccountAccessSO; + + // We have to achieve, that only one thread can write to account mails and more threads can read. + // While some thread writes mails, other thread can write to account. This can be small problem, but it never appears in YAMN. + // But you should think about this note if you want to add some features in the future + // Writing to messages means any changes to message queue or message data + // Reading from messages means reading message queue (browsing through all messages) or reading message data + // Use MsgsWaitToRead(),MsgsReadDone(),MsgsWaitToWrite(),MsgsWriteDone() synchronization functions + SWMRG MessagesAccessSO; + + //For clist contact notification + MCONTACT hContact; + BOOL isCounting; + + CAccount *Next; + + void CheckMail(); + void RefreshContact(); +}; + +#endif diff --git a/protocols/YAMN/src/browser/mailbrowser.cpp b/protocols/YAMN/src/browser/mailbrowser.cpp index 73fd293288..15c3310589 100644 --- a/protocols/YAMN/src/browser/mailbrowser.cpp +++ b/protocols/YAMN/src/browser/mailbrowser.cpp @@ -1819,8 +1819,6 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR mir_snwprintf(DeleteMsg, TranslateT("Do you really want to delete %d selected mails?"), Total);
if (IDOK == MessageBox(hDlg, DeleteMsg, TranslateT("Delete confirmation"), MB_OKCANCEL | MB_ICONWARNING)) {
- struct DeleteParam ParamToDeleteMails = { YAMN_DELETEVERSION, ThreadRunningEV, ActualAccount, nullptr };
-
// Find if there's mail marked to delete, which was deleted before
SWriteGuard swm(ActualAccount->MessagesAccessSO);
if (swm.Succeeded()) {
@@ -1832,12 +1830,12 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg, UINT msg, WPARAM wParam, LPAR continue;
}
}
+
// Set flag to marked mails that they can be deleted
SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails, YAMN_MSG_DISPLAY | YAMN_MSG_USERDELETE, 0, YAMN_MSG_DELETEOK, 1);
+
// Create new thread which deletes marked mails.
- HANDLE NewThread = mir_forkthread(ActualAccount->Plugin->Fcn->DeleteMailsFcnPtr, &ParamToDeleteMails);
- if (NewThread != nullptr)
- WaitForSingleObject(ThreadRunningEV, INFINITE);
+ mir_forkthread(ActualAccount->Plugin->Fcn->DeleteMailsFcnPtr, new DeleteParam(ActualAccount, 0));
}
}
else // else mark messages that they are not to be deleted
diff --git a/plugins/ExternalAPI/m_mails.h b/protocols/YAMN/src/mails/mails.h index 7b765273f4..8f800ec318 100644 --- a/plugins/ExternalAPI/m_mails.h +++ b/protocols/YAMN/src/mails/mails.h @@ -1,224 +1,222 @@ -#ifndef __MAILS_H
-#define __MAILS_H
-
-#include <windows.h>
-#include <tchar.h>
-#include "m_account.h"
-
-//
-//================================== OTHER DEFINITIONS ========================================
-//
-
-struct CShortNames
-{
- char *Value;
- char *ValueNick;
- CShortNames *Next;
-};
-
-struct CMimeNames
-{
- WCHAR *Value;
- WCHAR *ValueNick;
- CMimeNames *Next;
-};
-
-//this header is used in to get non-unicode data from mime header
-struct CShortHeader
-{
- char *From;
- char *FromNick;
- char *ReturnPath;
- char *ReturnPathNick;
- char *Subject;
- CShortNames *To;
- CShortNames *Cc;
- CShortNames *Bcc;
- char *Date;
- char Priority;
- char *Body;
-
- int CP;
-};
-
-//this header is used in miranda to store final results of mime reading in Unicode
-struct CHeader
-{
- ~CHeader();
-
- CMStringW wszFrom;
- CMStringW wszFromNick;
- CMStringW wszReturnPath;
- CMStringW wszReturnPathNick;
- CMStringW wszSubject;
- CMimeNames *To = 0;
- CMimeNames *Cc = 0;
- CMimeNames *Bcc = 0;
- CMStringW wszDate;
- TCHAR Priority = 0;
- CMStringW wszBody;
-};
-
-struct CMimeItem
-{
- char *name = nullptr;
- char *value = nullptr;
- CMimeItem *Next = nullptr;
-};
-
-// this is plugin-independent
-typedef struct CMailData
-{
- DWORD Size = 0;
- int CP = -1;
-
- CMimeItem *TranslatedHeader = nullptr; // MIME items
- CMimeItem *Additional = nullptr; // MIME items not read from server (custom, for filter plugins etc.)
- char *Body = nullptr; // Message body
-};
-
-typedef struct CMimeMsgQueue
-{
- char *ID; //The ID of mail. This ID identifies every mail in the account, so plugin should set it
-
- DWORD Number;
-
-#define YAMN_MSG_ANY 0xffffffff //any mail
-
-//The difference between new and unseen: when new mail is found in account, it becomes unseen and new. But in the next check, if the same mail is found, it is not new.
-//However, when user was not near computer, he does not know about this mail- it is unseen. After user accepts, that he saw new mails, it becomes seen.
-#define YAMN_MSG_NEW 0x80000000 //this mail is new
-#define YAMN_MSG_UNSEEN 0x40000000 //this mail is mailbrowser unseen
-#define YAMN_MSG_DISPLAY 0x20000000 //this mail can be displayed in mailbrowser
-#define YAMN_MSG_POPUP 0x10000000 //this mail can be displayed in popup and can invoke a popup
-#define YAMN_MSG_SYSTRAY 0x08000000 //this mail can invoke systray icon
-#define YAMN_MSG_BROWSER 0x04000000 //this mail can run mailbrowser
-#define YAMN_MSG_DISPLAYC 0x02000000 //this mail is inserted to browser mail counter system (the "Account - xx new mails, yy total" phrase)
-#define YAMN_MSG_POPUPC 0x01000000 //this mail is inserted to popup counter system (the "Account - xx new mails, yy total" phrase)
-
-#define YAMN_MSG_SOUND 0x00800000 //this mail can "play sound"
-#define YAMN_MSG_APP 0x00400000 //this mail can "launch application"
-#define YAMN_MSG_NEVENT 0x00100000 //this mail can launch Miranda "new mail" event
-
-#define YAMN_MSG_VIRTUAL 0x00080000 //this mail is not real- does not exists
-
-#define YAMN_MSG_FILTERED 0x00040000 //this mail has been filtered
-
-#define YAMN_MSG_DELETETRASH 0x00020000 //this mail should be moved to the trash bin rather than really deleting from mailbox (this is only switch doing nothing, perhaps usefull for filter plugins)
-#define YAMN_MSG_DELETED 0x00010000 //this mail is already deleted from server (also must be set virtual flag) (when doing synchronizations between 2 queues, YAMN then does not touch this mail)
-#define YAMN_MSG_MEMDELETE 0x00008000 //this mail will be deleted immidiatelly from memory (and disk) when deleted from server (some opposite of YAMN_MSG_DELETED)
-#define YAMN_MSG_USERDELETE 0x00004000 //this mail is about to delete from server (user deletes manually)
-#define YAMN_MSG_AUTODELETE 0x00002000 //this mail is about to delete from server (plugin marks it for deleting)
-#define YAMN_MSG_DELETEOK 0x00001000 //this mail is confirmed to delete (this flag must be set to delete this mail)
-
-#define YAMN_MSG_BODYREQUESTED 0x00000800 //user requested (part of) the body. In POP3 it should be (TOP <nr> <lines>)
-#define YAMN_MSG_BODYRECEIVED 0x00000200 //(part of) the body.received;
-#define YAMN_MSG_STAYUNSEEN 0x00000400 //this mail stays unseen while user does not really see it
-
-#define YAMN_MSG_DELETE (YAMN_MSG_USERDELETE | YAMN_MSG_AUTODELETE)
-
-#define YAMN_MSG_NORMALNEW (YAMN_MSG_NEW | YAMN_MSG_UNSEEN | YAMN_MSG_BROWSER | YAMN_MSG_DISPLAY | YAMN_MSG_DISPLAYC | YAMN_MSG_POPUP | YAMN_MSG_POPUPC | YAMN_MSG_SYSTRAY | YAMN_MSG_SOUND | YAMN_MSG_APP | YAMN_MSG_NEVENT | YAMN_MSG_MEMDELETE | YAMN_MSG_STAYUNSEEN)
-
-#define YAMN_MSG_FLAGSSET(maildata,flag) ((maildata & flag)==flag)
-
-#define YAMN_MSG_SPAML1 1 //spam level 1: notify, show in another color in mail browser
-#define YAMN_MSG_SPAML2 2 //spam level 2: do not notify, show in another color in mail browser
-#define YAMN_MSG_SPAML3 3 //spam level 3: delete, show in another color in mail browser that it was deleted, you do not need to set YAMN_MSG_AUTODELETE
-#define YAMN_MSG_SPAML4 4 //spam level 4: delete, do not show, you do not need to set YAMN_MSG_AUTODELETE
-#define YAMN_MSG_SPAMMASK 0x0000000F
-
-#define YAMN_MSG_SPAML(maildata,level) ((maildata & YAMN_MSG_SPAMMASK)==level)
- DWORD Flags;
-//Plugins can read mail data, but it can be NULL!!! So plugin should use Load and Save services to load or save data and Unload to release data from memory
- CMailData *MailData;
-//Here YAMN stores its own informations about this mail. Not usefull for plugins...
-// void *YAMNData;
- HWND MsgWindow;
-//plugins can store here its own data
- void *PluginData;
-
- CMimeMsgQueue(): ID(nullptr), Number(0), Flags(0), MailData(nullptr), MsgWindow(nullptr), PluginData(nullptr), Next(nullptr){}
- ~CMimeMsgQueue() {}
-
- struct CMimeMsgQueue *Next;
-} YAMNMAIL,*HYAMNMAIL;
-#define LoadedMailData(x) (x->MailData!=nullptr)
-
-//
-//================================== FUNCTIONS DEFINITIONS ========================================
-//
-
-//typedef void (WINAPI *YAMN_SENDMESSAGEFCN)(UINT,WPARAM,LPARAM);
-typedef void (WINAPI *YAMN_SYNCHROMIMEMSGSFCN)(CAccount *,HYAMNMAIL *,HYAMNMAIL *,HYAMNMAIL *,HYAMNMAIL *);
-typedef void (WINAPI *YAMN_TRANSLATEHEADERFCN)(char *,int,struct CMimeItem **);
-typedef void (WINAPI *YAMN_APPENDQUEUEFCN)(HYAMNMAIL,HYAMNMAIL);
-typedef void (WINAPI *YAMN_DELETEMIMEQUEUEFCN)(CAccount *,HYAMNMAIL);
-typedef void (WINAPI *YAMN_DELETEMIMEMESSAGEFCN)(HYAMNMAIL *,HYAMNMAIL,int);
-typedef HYAMNMAIL (WINAPI *YAMN_FINDMIMEMESSAGEFCN)(HYAMNMAIL,char *);
-typedef HYAMNMAIL (WINAPI *YAMN_CREATENEWDELETEQUEUEFCN)(HYAMNMAIL);
-typedef void (WINAPI *YAMN_SETREMOVEQUEUEFLAGSFCN)(HYAMNMAIL,DWORD,DWORD,DWORD,int);
-
-//
-//================================== QUICK FUNCTION CALL DEFINITIONS ========================================
-//
-
-//These are defininitions for YAMN exported functions. Your plugin can use them.
-//pYAMNFcn is global variable, it is pointer to your structure containing YAMN functions.
-//It is something similar like pluginLink variable in Miranda plugin. If you use
-//this name of variable, you have already defined these functions and you can use them.
-//It's similar to Miranda's CreateService function.
-
-//How to use YAMN functions:
-//Create a structure containing pointer to functions you want to use in your plugin
-//This structure can look something like this:
-//
-// struct
-// {
-// YAMN_SYNCHROMIMEMSGSFCN SynchroMessagesFcn;
-// YAMN_APPENDQUEUEFCN AppendQueueFcn;
-// } *pYAMNMailFcn;
-//
-//then you have to fill this structure with pointers...
-//you have to use YAMN service to get pointer, like this (I wrote here all functions you may need,
-//you can copy to your sources only those you need):
-//
-// pYAMNMailFcn->SynchroMessagesFcn=(YAMN_SYNCHROMIMEMSGSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SYNCHROMIMEMSGSID,0);
-// pYAMNMailFcn->TranslateHeaderFcn=(YAMN_TRANSLATEHEADERFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_TRANSLATEHEADERID,0);
-// pYAMNMailFcn->AppendQueueFcn=(YAMN_APPENDQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_APPENDQUEUEID,0);
-// pYAMNMailFcn->DeleteMessagesToEndFcn=(YAMN_DELETEMIMEQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_DELETEMIMEQUEUEID,0);
-// pYAMNMailFcn->DeleteMessageFromQueueFcn=(YAMN_DELETEMIMEMESSAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_DELETEMIMEMESSAGEID,0);
-// pYAMNMailFcn->FindMessageByIDFcn=(YAMN_FINDMIMEMESSAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_FINDMIMEMESSAGEID,0);
-// pYAMNMailFcn->CreateNewDeleteQueueFcn=(YAMN_CREATENEWDELETEQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_CREATENEWDELETEQUEUEID,0);
-// pYAMNMailFcn->SetRemoveQueueFlagsFcn=(YAMN_SETREMOVEQUEUEFLAGSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SETREMOVEQUEUEFLAGSID,0);
-//
-//
-//and in your plugin just simply use e.g.:
-//
-// DeleteMIMEQueue(MyAccount,OldMessages); //this command deletes all messages in the mail queue OldMessages
-//
-
-#define YAMN_SYNCHROMIMEMSGSID "YAMN/SynchroMessages"
-#define YAMN_TRANSLATEHEADERID "YAMN/TranslateHeader"
-#define YAMN_APPENDQUEUEID "YAMN/AppendQueue"
-#define YAMN_DELETEMIMEQUEUEID "YAMN/DeleteMIMEQueue"
-#define YAMN_DELETEMIMEMESSAGEID "YAMN/DeleteMIMEMessage"
-#define YAMN_FINDMIMEMESSAGEID "YAMN/FindMIMEMessageByID"
-#define YAMN_CREATENEWDELETEQUEUEID "YAMN/CreateNewDeleteQueue"
-#define YAMN_SETREMOVEQUEUEFLAGSID "YAMN/SetRemoveQueueFlags"
-
-#define YAMN_FLAG_REMOVE 0
-#define YAMN_FLAG_SET 1
-
-
-#define SynchroMessages(a,b,c,d,e) pYAMNMailFcn->SynchroMessagesFcn(a,b,c,d,e)
-#define TranslateHeader(a,b,c) pYAMNMailFcn->TranslateHeaderFcn(a,b,c)
-#define AppendQueue(x,y) pYAMNMailFcn->AppendQueueFcn(x,y)
-#define DeleteMIMEQueue(x,y) pYAMNMailFcn->DeleteMessagesToEndFcn(x,y)
-#define DeleteMIMEMessage(x,y) pYAMNMailFcn->DeleteMessageFromQueueFcn(x,y,0)
-#define DeleteMIMEMessageEx(x,y,z) pYAMNMailFcn->DeleteMessageFromQueueFcn(x,y,z)
-#define FindMIMEMessageByID(x,y) pYAMNMailFcn->FindMessageByIDFcn(x,y)
-#define CreateNewDeleteQueue(x) pYAMNMailFcn->CreateNewDeleteQueueFcn(x)
-#define SetQueueFlags(a,b,c,d) pYAMNMailFcn->SetRemoveQueueFlagsFcn(a,b,c,d,1)
-#define RemoveQueueFlags(a,b,c,d) pYAMNMailFcn->SetRemoveQueueFlagsFcn(a,b,c,d,0)
-
-#endif
+#ifndef __MAILS_H +#define __MAILS_H + +struct CAccount; + +// +//================================== OTHER DEFINITIONS ======================================== +// + +struct CShortNames +{ + char *Value; + char *ValueNick; + CShortNames *Next; +}; + +struct CMimeNames +{ + WCHAR *Value; + WCHAR *ValueNick; + CMimeNames *Next; +}; + +//this header is used in to get non-unicode data from mime header +struct CShortHeader +{ + char *From; + char *FromNick; + char *ReturnPath; + char *ReturnPathNick; + char *Subject; + CShortNames *To; + CShortNames *Cc; + CShortNames *Bcc; + char *Date; + char Priority; + char *Body; + + int CP; +}; + +//this header is used in miranda to store final results of mime reading in Unicode +struct CHeader +{ + ~CHeader(); + + CMStringW wszFrom; + CMStringW wszFromNick; + CMStringW wszReturnPath; + CMStringW wszReturnPathNick; + CMStringW wszSubject; + CMimeNames *To = 0; + CMimeNames *Cc = 0; + CMimeNames *Bcc = 0; + CMStringW wszDate; + TCHAR Priority = 0; + CMStringW wszBody; +}; + +struct CMimeItem +{ + char *name = nullptr; + char *value = nullptr; + CMimeItem *Next = nullptr; +}; + +// this is plugin-independent +typedef struct CMailData +{ + DWORD Size = 0; + int CP = -1; + + CMimeItem *TranslatedHeader = nullptr; // MIME items + CMimeItem *Additional = nullptr; // MIME items not read from server (custom, for filter plugins etc.) + char *Body = nullptr; // Message body +}; + +typedef struct CMimeMsgQueue +{ + char *ID; //The ID of mail. This ID identifies every mail in the account, so plugin should set it + + DWORD Number; + +#define YAMN_MSG_ANY 0xffffffff //any mail + +//The difference between new and unseen: when new mail is found in account, it becomes unseen and new. But in the next check, if the same mail is found, it is not new. +//However, when user was not near computer, he does not know about this mail- it is unseen. After user accepts, that he saw new mails, it becomes seen. +#define YAMN_MSG_NEW 0x80000000 //this mail is new +#define YAMN_MSG_UNSEEN 0x40000000 //this mail is mailbrowser unseen +#define YAMN_MSG_DISPLAY 0x20000000 //this mail can be displayed in mailbrowser +#define YAMN_MSG_POPUP 0x10000000 //this mail can be displayed in popup and can invoke a popup +#define YAMN_MSG_SYSTRAY 0x08000000 //this mail can invoke systray icon +#define YAMN_MSG_BROWSER 0x04000000 //this mail can run mailbrowser +#define YAMN_MSG_DISPLAYC 0x02000000 //this mail is inserted to browser mail counter system (the "Account - xx new mails, yy total" phrase) +#define YAMN_MSG_POPUPC 0x01000000 //this mail is inserted to popup counter system (the "Account - xx new mails, yy total" phrase) + +#define YAMN_MSG_SOUND 0x00800000 //this mail can "play sound" +#define YAMN_MSG_APP 0x00400000 //this mail can "launch application" +#define YAMN_MSG_NEVENT 0x00100000 //this mail can launch Miranda "new mail" event + +#define YAMN_MSG_VIRTUAL 0x00080000 //this mail is not real- does not exists + +#define YAMN_MSG_FILTERED 0x00040000 //this mail has been filtered + +#define YAMN_MSG_DELETETRASH 0x00020000 //this mail should be moved to the trash bin rather than really deleting from mailbox (this is only switch doing nothing, perhaps usefull for filter plugins) +#define YAMN_MSG_DELETED 0x00010000 //this mail is already deleted from server (also must be set virtual flag) (when doing synchronizations between 2 queues, YAMN then does not touch this mail) +#define YAMN_MSG_MEMDELETE 0x00008000 //this mail will be deleted immidiatelly from memory (and disk) when deleted from server (some opposite of YAMN_MSG_DELETED) +#define YAMN_MSG_USERDELETE 0x00004000 //this mail is about to delete from server (user deletes manually) +#define YAMN_MSG_AUTODELETE 0x00002000 //this mail is about to delete from server (plugin marks it for deleting) +#define YAMN_MSG_DELETEOK 0x00001000 //this mail is confirmed to delete (this flag must be set to delete this mail) + +#define YAMN_MSG_BODYREQUESTED 0x00000800 //user requested (part of) the body. In POP3 it should be (TOP <nr> <lines>) +#define YAMN_MSG_BODYRECEIVED 0x00000200 //(part of) the body.received; +#define YAMN_MSG_STAYUNSEEN 0x00000400 //this mail stays unseen while user does not really see it + +#define YAMN_MSG_DELETE (YAMN_MSG_USERDELETE | YAMN_MSG_AUTODELETE) + +#define YAMN_MSG_NORMALNEW (YAMN_MSG_NEW | YAMN_MSG_UNSEEN | YAMN_MSG_BROWSER | YAMN_MSG_DISPLAY | YAMN_MSG_DISPLAYC | YAMN_MSG_POPUP | YAMN_MSG_POPUPC | YAMN_MSG_SYSTRAY | YAMN_MSG_SOUND | YAMN_MSG_APP | YAMN_MSG_NEVENT | YAMN_MSG_MEMDELETE | YAMN_MSG_STAYUNSEEN) + +#define YAMN_MSG_FLAGSSET(maildata,flag) ((maildata & flag)==flag) + +#define YAMN_MSG_SPAML1 1 //spam level 1: notify, show in another color in mail browser +#define YAMN_MSG_SPAML2 2 //spam level 2: do not notify, show in another color in mail browser +#define YAMN_MSG_SPAML3 3 //spam level 3: delete, show in another color in mail browser that it was deleted, you do not need to set YAMN_MSG_AUTODELETE +#define YAMN_MSG_SPAML4 4 //spam level 4: delete, do not show, you do not need to set YAMN_MSG_AUTODELETE +#define YAMN_MSG_SPAMMASK 0x0000000F + +#define YAMN_MSG_SPAML(maildata,level) ((maildata & YAMN_MSG_SPAMMASK)==level) + DWORD Flags; +//Plugins can read mail data, but it can be NULL!!! So plugin should use Load and Save services to load or save data and Unload to release data from memory + CMailData *MailData; +//Here YAMN stores its own informations about this mail. Not usefull for plugins... +// void *YAMNData; + HWND MsgWindow; +//plugins can store here its own data + void *PluginData; + + CMimeMsgQueue(): ID(nullptr), Number(0), Flags(0), MailData(nullptr), MsgWindow(nullptr), PluginData(nullptr), Next(nullptr){} + ~CMimeMsgQueue() {} + + struct CMimeMsgQueue *Next; +} YAMNMAIL,*HYAMNMAIL; +#define LoadedMailData(x) (x->MailData!=nullptr) + +// +//================================== FUNCTIONS DEFINITIONS ======================================== +// + +//typedef void (WINAPI *YAMN_SENDMESSAGEFCN)(UINT,WPARAM,LPARAM); +typedef void (WINAPI *YAMN_SYNCHROMIMEMSGSFCN)(CAccount *,HYAMNMAIL *,HYAMNMAIL *,HYAMNMAIL *,HYAMNMAIL *); +typedef void (WINAPI *YAMN_TRANSLATEHEADERFCN)(char *,int,struct CMimeItem **); +typedef void (WINAPI *YAMN_APPENDQUEUEFCN)(HYAMNMAIL,HYAMNMAIL); +typedef void (WINAPI *YAMN_DELETEMIMEQUEUEFCN)(CAccount *,HYAMNMAIL); +typedef void (WINAPI *YAMN_DELETEMIMEMESSAGEFCN)(HYAMNMAIL *,HYAMNMAIL,int); +typedef HYAMNMAIL (WINAPI *YAMN_FINDMIMEMESSAGEFCN)(HYAMNMAIL,char *); +typedef HYAMNMAIL (WINAPI *YAMN_CREATENEWDELETEQUEUEFCN)(HYAMNMAIL); +typedef void (WINAPI *YAMN_SETREMOVEQUEUEFLAGSFCN)(HYAMNMAIL,DWORD,DWORD,DWORD,int); + +// +//================================== QUICK FUNCTION CALL DEFINITIONS ======================================== +// + +//These are defininitions for YAMN exported functions. Your plugin can use them. +//pYAMNFcn is global variable, it is pointer to your structure containing YAMN functions. +//It is something similar like pluginLink variable in Miranda plugin. If you use +//this name of variable, you have already defined these functions and you can use them. +//It's similar to Miranda's CreateService function. + +//How to use YAMN functions: +//Create a structure containing pointer to functions you want to use in your plugin +//This structure can look something like this: +// +// struct +// { +// YAMN_SYNCHROMIMEMSGSFCN SynchroMessagesFcn; +// YAMN_APPENDQUEUEFCN AppendQueueFcn; +// } *pYAMNMailFcn; +// +//then you have to fill this structure with pointers... +//you have to use YAMN service to get pointer, like this (I wrote here all functions you may need, +//you can copy to your sources only those you need): +// +// pYAMNMailFcn->SynchroMessagesFcn=(YAMN_SYNCHROMIMEMSGSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SYNCHROMIMEMSGSID,0); +// pYAMNMailFcn->TranslateHeaderFcn=(YAMN_TRANSLATEHEADERFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_TRANSLATEHEADERID,0); +// pYAMNMailFcn->AppendQueueFcn=(YAMN_APPENDQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_APPENDQUEUEID,0); +// pYAMNMailFcn->DeleteMessagesToEndFcn=(YAMN_DELETEMIMEQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_DELETEMIMEQUEUEID,0); +// pYAMNMailFcn->DeleteMessageFromQueueFcn=(YAMN_DELETEMIMEMESSAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_DELETEMIMEMESSAGEID,0); +// pYAMNMailFcn->FindMessageByIDFcn=(YAMN_FINDMIMEMESSAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_FINDMIMEMESSAGEID,0); +// pYAMNMailFcn->CreateNewDeleteQueueFcn=(YAMN_CREATENEWDELETEQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_CREATENEWDELETEQUEUEID,0); +// pYAMNMailFcn->SetRemoveQueueFlagsFcn=(YAMN_SETREMOVEQUEUEFLAGSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SETREMOVEQUEUEFLAGSID,0); +// +// +//and in your plugin just simply use e.g.: +// +// DeleteMIMEQueue(MyAccount,OldMessages); //this command deletes all messages in the mail queue OldMessages +// + +#define YAMN_SYNCHROMIMEMSGSID "YAMN/SynchroMessages" +#define YAMN_TRANSLATEHEADERID "YAMN/TranslateHeader" +#define YAMN_APPENDQUEUEID "YAMN/AppendQueue" +#define YAMN_DELETEMIMEQUEUEID "YAMN/DeleteMIMEQueue" +#define YAMN_DELETEMIMEMESSAGEID "YAMN/DeleteMIMEMessage" +#define YAMN_FINDMIMEMESSAGEID "YAMN/FindMIMEMessageByID" +#define YAMN_CREATENEWDELETEQUEUEID "YAMN/CreateNewDeleteQueue" +#define YAMN_SETREMOVEQUEUEFLAGSID "YAMN/SetRemoveQueueFlags" + +#define YAMN_FLAG_REMOVE 0 +#define YAMN_FLAG_SET 1 + + +#define SynchroMessages(a,b,c,d,e) pYAMNMailFcn->SynchroMessagesFcn(a,b,c,d,e) +#define TranslateHeader(a,b,c) pYAMNMailFcn->TranslateHeaderFcn(a,b,c) +#define AppendQueue(x,y) pYAMNMailFcn->AppendQueueFcn(x,y) +#define DeleteMIMEQueue(x,y) pYAMNMailFcn->DeleteMessagesToEndFcn(x,y) +#define DeleteMIMEMessage(x,y) pYAMNMailFcn->DeleteMessageFromQueueFcn(x,y,0) +#define DeleteMIMEMessageEx(x,y,z) pYAMNMailFcn->DeleteMessageFromQueueFcn(x,y,z) +#define FindMIMEMessageByID(x,y) pYAMNMailFcn->FindMessageByIDFcn(x,y) +#define CreateNewDeleteQueue(x) pYAMNMailFcn->CreateNewDeleteQueueFcn(x) +#define SetQueueFlags(a,b,c,d) pYAMNMailFcn->SetRemoveQueueFlagsFcn(a,b,c,d,1) +#define RemoveQueueFlags(a,b,c,d) pYAMNMailFcn->SetRemoveQueueFlagsFcn(a,b,c,d,0) + +#endif diff --git a/protocols/YAMN/src/main.cpp b/protocols/YAMN/src/main.cpp index d165acd93e..ab7214294a 100644 --- a/protocols/YAMN/src/main.cpp +++ b/protocols/YAMN/src/main.cpp @@ -53,7 +53,8 @@ PLUGININFOEX pluginInfoEx = { };
CMPlugin::CMPlugin() :
- PLUGIN<CMPlugin>(YAMN_DBMODULE, pluginInfoEx)
+ PLUGIN<CMPlugin>(YAMN_DBMODULE, pluginInfoEx),
+ bForceCheck(YAMN_DBMODULE, "ForceCheck", false)
{
RegisterProtocol(PROTOTYPE_VIRTUAL);
SetUniqueId("Id");
diff --git a/protocols/YAMN/src/proto/pop3/pop3comm.cpp b/protocols/YAMN/src/proto/pop3/pop3comm.cpp index 9067cb4ace..c336fe155d 100644 --- a/protocols/YAMN/src/proto/pop3/pop3comm.cpp +++ b/protocols/YAMN/src/proto/pop3/pop3comm.cpp @@ -18,28 +18,28 @@ HANDLE hNetLib = nullptr; SCOUNTER CPOP3Account::AccountWriterSO;
// Creates new CPOP3Account structure
-CAccount *WINAPI CreatePOP3Account(YAMN_PROTOPLUGIN *Plugin);
+CAccount* MIR_CDECL CreatePOP3Account(YAMN_PROTOPLUGIN *Plugin);
// Deletes CPOP3Account structure
-void WINAPI DeletePOP3Account(CAccount *Which);
+void MIR_CDECL DeletePOP3Account(CAccount *Which);
// Sets stop flag to account
-void WINAPI StopPOP3Account(CAccount *Which);
+void MIR_CDECL StopPOP3Account(CAccount *Which);
// Function registers standard functions for YAMN
int RegisterPOP3Plugin(WPARAM, LPARAM);
// Unloads all variables created on heap (delete[])
-DWORD WINAPI UnLoadPOP3(void *);
+DWORD MIR_CDECL UnLoadPOP3(void *);
// Function stores plugin's data for account to file
-DWORD WINAPI WritePOP3Options(HANDLE, CAccount *);
+DWORD MIR_CDECL WritePOP3Options(HANDLE, CAccount *);
// Function reads plugin's data for account from file
-DWORD WINAPI ReadPOP3Options(CAccount *, char **, char *);
+DWORD MIR_CDECL ReadPOP3Options(CAccount *, char **, char *);
// Creates new mail for an account
-HYAMNMAIL WINAPI CreatePOP3Mail(CAccount *Account);
+HYAMNMAIL MIR_CDECL CreatePOP3Mail(CAccount *Account);
// Function does all needed work when connection failed or any error occured
// Creates structure containing error code, closes internet session, runs "bad connect" function
@@ -47,7 +47,7 @@ static void PostErrorProc(CPOP3Account *ActualAccount, void *ParamToBadConnect, // Checks POP3 account and stores all info to account. It deletes old mails=> synchro
// WhichTemp- pointer to strucure containing needed information
-DWORD WINAPI SynchroPOP3(CheckParam *WhichTemp);
+void MIR_CDECL SynchroPOP3(CheckParam *WhichTemp);
// Deletes mails from POP3 server
// WhichTemp- structure containing needed information (queued messages to delete)
@@ -56,10 +56,10 @@ void __cdecl DeleteMailsPOP3(void *param); // Function makes readable message about error. It sends it back to YAMN, so YAMN then
// can show it to the message window
-wchar_t *WINAPI GetErrorString(DWORD Code);
+wchar_t *MIR_CDECL GetErrorString(DWORD Code);
// Function deletes string allocated in GetErrorString
-void WINAPI DeleteErrorString(LPVOID String);
+void MIR_CDECL DeleteErrorString(LPVOID String);
// Extracts info from result of POP3's STAT command
// stream- source string
@@ -143,7 +143,7 @@ CPOP3Account::~CPOP3Account() CloseHandle(UseInternetFree);
}
-CAccount *WINAPI CreatePOP3Account(YAMN_PROTOPLUGIN *)
+CAccount* MIR_CDECL CreatePOP3Account(YAMN_PROTOPLUGIN *)
{
// First, we should check whether CAccountVersion matches.
// But this is internal plugin, so YAMN's CAccount structure and our CAccount structure are
@@ -155,12 +155,12 @@ CAccount *WINAPI CreatePOP3Account(YAMN_PROTOPLUGIN *) return new CPOP3Account();
}
-void WINAPI DeletePOP3Account(CAccount *Which)
+void MIR_CDECL DeletePOP3Account(CAccount *Which)
{
delete (CPOP3Account *)Which;
}
-void WINAPI StopPOP3Account(CAccount *Which)
+void MIR_CDECL StopPOP3Account(CAccount *Which)
{
((CPOP3Account *)Which)->Client.Stopped = TRUE;
if (((CPOP3Account *)Which)->Client.NetClient != nullptr) // we should inform also network client. Usefull only when network client implements this feature
@@ -244,14 +244,14 @@ int RegisterPOP3Plugin(WPARAM, LPARAM) return 0;
}
-DWORD WINAPI UnLoadPOP3(void *)
+DWORD MIR_CDECL UnLoadPOP3(void *)
{
Netlib_CloseHandle(hNetLib); hNetLib = nullptr;
return 1;
}
// Function writes POP3 accounts using YAMN exported functions
-DWORD WINAPI WritePOP3Accounts()
+DWORD MIR_CDECL WritePOP3Accounts()
{
uint32_t ReturnValue = WriteAccountsToFile(POP3Plugin, wszFileName);
if (ReturnValue == EACC_SYSTEM) {
@@ -263,7 +263,7 @@ DWORD WINAPI WritePOP3Accounts() return ReturnValue;
}
-DWORD WINAPI WritePOP3Options(HANDLE File, CAccount *Which)
+DWORD MIR_CDECL WritePOP3Options(HANDLE File, CAccount *Which)
{
DWORD WrittenBytes;
uint32_t Ver = POP3_FILEVERSION;
@@ -274,7 +274,7 @@ DWORD WINAPI WritePOP3Options(HANDLE File, CAccount *Which) return 0;
}
-DWORD WINAPI ReadPOP3Options(CAccount *Which, char **Parser, char *End)
+DWORD MIR_CDECL ReadPOP3Options(CAccount *Which, char **Parser, char *End)
{
uint32_t Ver;
#ifdef DEBUG_FILEREAD
@@ -298,7 +298,7 @@ DWORD WINAPI ReadPOP3Options(CAccount *Which, char **Parser, char *End) return 0;
}
-HYAMNMAIL WINAPI CreatePOP3Mail(CAccount *Account)
+HYAMNMAIL MIR_CDECL CreatePOP3Mail(CAccount *Account)
{
HYAMNMAIL NewMail;
// First, we should check whether MAILDATA matches.
@@ -378,7 +378,7 @@ static void PostErrorProc(CPOP3Account *ActualAccount, void *ParamToBadConnectio }
// Checks POP3 account and synchronizes it
-DWORD WINAPI SynchroPOP3(CheckParam *WhichTemp)
+void MIR_CDECL SynchroPOP3(CheckParam *WhichTemp)
{
CPop3Client *MyClient;
HYAMNMAIL NewMails = nullptr, MsgQueuePtr = nullptr;
@@ -390,16 +390,15 @@ DWORD WINAPI SynchroPOP3(CheckParam *WhichTemp) ptrA ServerName, ServerLogin, ServerPasswd;
uint32_t ServerPort, Flags, NFlags, NNFlags;
- auto *ActualAccount = (CPOP3Account *)WhichTemp->AccountParam; // copy address of structure from calling thread to stack of this thread
+ auto *ActualAccount = (CPOP3Account *)WhichTemp->AccountParam;
+ auto CheckFlags = WhichTemp->Flags;
+ delete WhichTemp;
SCGuard sc(ActualAccount->UsingThreads);
- // Unblock YAMN, signal that we have copied all parameters from YAMN thread stack
- if (INVALID_HANDLE_VALUE != WhichTemp->ThreadRunningEV)
- SetEvent(WhichTemp->ThreadRunningEV);
{
SReadGuard sra(ActualAccount->AccountAccessSO);
if (!sra.Succeeded())
- return 0;
+ return;
MyClient = &ActualAccount->Client;
// Now, copy all needed information about account to local variables, so ActualAccount is not blocked in read mode during all connection process, which can last for several minutes.
@@ -420,7 +419,7 @@ DWORD WINAPI SynchroPOP3(CheckParam *WhichTemp) // the second one waiting for network access- the first one ends because we want to stop account, this one is released, but should be stopped as well).
if (!ActualAccount->AbleToWork) {
SetEvent(ActualAccount->UseInternetFree);
- return 0;
+ return;
}
UsingInternet = TRUE;
@@ -627,12 +626,8 @@ DWORD WINAPI SynchroPOP3(CheckParam *WhichTemp) }
// we are going to delete mails having SPAM flag level3 and 4 (see m_mails.h) set
- {
- struct DeleteParam ParamToDeleteMails = { YAMN_DELETEVERSION, INVALID_HANDLE_VALUE, ActualAccount, 0, (void *)POP3_DELETEFROMCHECK };
-
- // Delete mails from server. Here we should not be in write access for account's mails
- DeleteMailsPOP3(&ParamToDeleteMails);
- }
+ // Delete mails from server. Here we should not be in write access for account's mails
+ DeleteMailsPOP3(new DeleteParam(ActualAccount, POP3_DELETEFROMCHECK));
// if there is no waiting thread for internet connection close it
// else leave connection open
@@ -657,6 +652,8 @@ DWORD WINAPI SynchroPOP3(CheckParam *WhichTemp) }
YAMN_MAILBROWSERPARAM Param = { ActualAccount, NFlags, NNFlags, 0 };
+ if (CheckFlags & YAMN_FORCECHECK)
+ Param.nnflags |= YAMN_ACC_POP; // if force check, show popup anyway and if mailbrowser was opened, do not close
Param.nnflags |= YAMN_ACC_MSGP; // do not close browser if already open
RunMailBrowser(&Param);
@@ -702,9 +699,6 @@ DWORD WINAPI SynchroPOP3(CheckParam *WhichTemp) #ifdef DEBUG_COMM
DebugLog(CommFile, "</--------Communication-------->\n");
#endif
-
- // WriteAccounts();
- return 0;
}
void __cdecl DeleteMailsPOP3(void *param)
@@ -719,12 +713,10 @@ void __cdecl DeleteMailsPOP3(void *param) // copy address of structure from calling thread to stack of this thread
CPOP3Account *ActualAccount = (CPOP3Account *)WhichTemp->AccountParam;
- LPVOID YAMNParam = WhichTemp->BrowserParam;
- UINT_PTR POP3PluginParam = (UINT_PTR)WhichTemp->CustomParam;
+ int POP3PluginParam = WhichTemp->Flags;
+ delete WhichTemp;
SCGuard sc(ActualAccount->UsingThreads);
- if (INVALID_HANDLE_VALUE != WhichTemp->ThreadRunningEV)
- SetEvent(WhichTemp->ThreadRunningEV);
CPop3Client *MyClient;
{
@@ -736,7 +728,7 @@ void __cdecl DeleteMailsPOP3(void *param) if (nullptr == (DeleteMails = CreateNewDeleteQueueFcn((HYAMNMAIL)ActualAccount->Mails))) {
// We do not wait for free internet when calling from SynchroPOP3. It is because UseInternetFree is blocked
if (POP3_DELETEFROMCHECK != POP3PluginParam) {
- YAMN_MAILBROWSERPARAM Param = { ActualAccount, YAMN_ACC_MSGP, YAMN_ACC_MSGP, YAMNParam }; // Just update the window
+ YAMN_MAILBROWSERPARAM Param = { ActualAccount, YAMN_ACC_MSGP, YAMN_ACC_MSGP, 0 }; // Just update the window
RunMailBrowser(&Param);
}
return;
@@ -925,7 +917,7 @@ void __cdecl DeleteMailsPOP3(void *param) // else leave connection open
// if this functin was called from SynchroPOP3, then do not try to disconnect
if (POP3_DELETEFROMCHECK != POP3PluginParam) {
- YAMN_MAILBROWSERPARAM Param = { ActualAccount, NFlags, YAMN_ACC_MSGP, YAMNParam };
+ YAMN_MAILBROWSERPARAM Param = { ActualAccount, NFlags, YAMN_ACC_MSGP, 0 };
RunMailBrowser(&Param);
if (0 == ActualAccount->InternetQueries.GetNumber()) {
@@ -961,7 +953,7 @@ void __cdecl DeleteMailsPOP3(void *param) ActualAccount->Client.NetClient->Disconnect();
break;
default:
- PostErrorProc(ActualAccount, YAMNParam, POP3PluginParam, MyClient->SSL); // it closes internet connection too
+ PostErrorProc(ActualAccount, 0, POP3PluginParam, MyClient->SSL); // it closes internet connection too
}
if (UsingInternet && (POP3_DELETEFROMCHECK != POP3PluginParam)) // if our thread still uses internet and it is needed to release internet
@@ -1122,7 +1114,7 @@ void ExtractList(char *stream, int len, HYAMNMAIL queue) }
}
-wchar_t *WINAPI GetErrorString(DWORD Code)
+wchar_t *MIR_CDECL GetErrorString(DWORD Code)
{
static wchar_t *POP3Errors[] =
{
@@ -1177,7 +1169,7 @@ wchar_t *WINAPI GetErrorString(DWORD Code) return ErrorString;
}
-void WINAPI DeleteErrorString(LPVOID String)
+void MIR_CDECL DeleteErrorString(LPVOID String)
{
delete (char *)String;
}
diff --git a/protocols/YAMN/src/proto/pop3/pop3opt.cpp b/protocols/YAMN/src/proto/pop3/pop3opt.cpp index 2372b6f6c2..f557f6daa7 100644 --- a/protocols/YAMN/src/proto/pop3/pop3opt.cpp +++ b/protocols/YAMN/src/proto/pop3/pop3opt.cpp @@ -709,7 +709,7 @@ class CPopupOptsDlg : public CBaseOptionsDlg UCHAR ActualStatus;
CCtrlCombo cmbAccount, cmbCP;
- CCtrlCheck chkCol, chkFcol, chkNcol, chkPop, chkFpop, chkNpop;
+ CCtrlCheck chkCol, chkFcol, chkNcol, chkPop, chkFpop, chkNpop, chkForce;
CCtrlButton btnPreview;
void DlgShowAccountPopup()
@@ -810,9 +810,12 @@ public: chkFpop(this, IDC_CHECKFPOP),
chkNcol(this, IDC_CHECKNCOL),
chkNpop(this, IDC_CHECKNPOP),
+ chkForce(this, IDC_FORCECHECK),
btnPreview(this, IDC_PREVIEW),
cmbAccount(this, IDC_COMBOACCOUNT)
{
+ CreateLink(chkForce, g_plugin.bForceCheck);
+
chkPop.OnChange = Callback(this, &CPopupOptsDlg::onChange_Pop);
chkFpop.OnChange = Callback(this, &CPopupOptsDlg::onChange_Fpop);
chkNpop.OnChange = Callback(this, &CPopupOptsDlg::onChange_Npop);
diff --git a/plugins/ExternalAPI/m_protoplugin.h b/protocols/YAMN/src/protoplugin.h index d651563882..28b5a777fa 100644 --- a/plugins/ExternalAPI/m_protoplugin.h +++ b/protocols/YAMN/src/protoplugin.h @@ -1,215 +1,195 @@ -#ifndef __M_PROTOPLUGIN_H
-#define __M_PROTOPLUGIN_H
-
-#include <windows.h>
-#include "m_account.h" // for account import functions
-#include "m_mails.h" // for mail import functions
-
-//
-// ================================== OTHER DEFINITIONS ========================================
-//
-
-// structure is used to give parameters to Check, Synchro or Timeout function
-struct CheckParam
-{
- // Your plugin should use this definition
-#define YAMN_CHECKVERSION 2
- // Version of this structure. Please verify your version in your plugin
- int Ver;
- // Event that new Check thread must set to signal calling thread that "I've copied all parameters from stack"
- // IMPORTANT!!!: Although version #defined in your plugin is not the same, your plugin MUST signal this event
- // in any way. YAMN is waiting for this event. If you do not signal it, YAMN is blocked.
- HANDLE ThreadRunningEV;
-
- // ActualAccount- the only parameter used in Check function and should contain all needed information I think :)
- CAccount *AccountParam;
-};
-
-// structure is used to give parameters to DeleteMails function
-struct DeleteParam
-{
- // Your plugin should use this definition
-#define YAMN_DELETEVERSION 1
- // Version of this structure. Please verify your version in your plugin
- DWORD Ver;
- // Event that new Delete thread must set to signal calling thread that it copied all parameters from stack
- // IMPORTANT!!!: Although version #defined in your plugin is not the same, your plugin MUST signal this event
- // in any way. YAMN is waiting for this event. If you do not signal it, YAMN is blocked.
- HANDLE ThreadRunningEV;
- // ActualAccount- which account to delete
- CAccount *AccountParam;
- // YAMN writes here some informations that are needed to pass to mail browser function (or bad connection or no new mail)
- void *BrowserParam;
- // Calling thread can write here its own parameter. Usefull when protocol calls its own delete function. YAMN always sets this parameter to NULL
- void *CustomParam;
-};
-
-//
-// ================================== IMPORTED FUNCTIONS ==================================
-//
-
-#ifndef YAMN_STANDARDFCN
-typedef DWORD(WINAPI *YAMN_STANDARDFCN)(LPVOID);
-#endif
-typedef struct CYAMNVariables *(WINAPI *YAMN_GETVARIABLESFCN)(DWORD);
-typedef CAccount *(WINAPI *YAMN_NEWACCOUNTFCN)(struct YAMN_PROTOPLUGIN *);
-typedef void (WINAPI *YAMN_STOPACCOUNTFCN)(CAccount *);
-typedef void (WINAPI *YAMN_DELETEACCOUNTFCN)(CAccount *);
-typedef DWORD(WINAPI *YAMN_WRITEPLUGINOPTS)(HANDLE File, CAccount *);
-typedef DWORD(WINAPI *YAMN_READPLUGINOPTS)(CAccount *, char **, char *);
-typedef DWORD(WINAPI *YAMN_CHECKFCN)(struct CheckParam *);
-typedef void(__cdecl *YAMN_DELETEFCN)(void *);
-typedef TCHAR* (WINAPI *YAMN_GETERRORSTRINGWFCN)(DWORD);
-typedef char* (WINAPI *YAMN_GETERRORSTRINGAFCN)(DWORD);
-typedef void (WINAPI *YAMN_DELETEERRORSTRINGFCN)(LPVOID);
-typedef DWORD(WINAPI *YAMN_WRITEACCOUNTSFCN)();
-
-struct YAMN_PROTOIMPORTFCN
-{
- // Note: not all of these functions are needed to be implemented in your protocol plugin. Those
- // functions, which are not implemented, you have to set to NULL.
-
- // Function is called to construct protocol defined account
- // This is VERY IMPORTANT for YAMN and plugin to cooperate:
- // Imagine following situation. YAMN wants to add new account (it is possible e.g.
- // when loading accounts from file), so it has to call protocol constructor.
- // It calls NewAccount function and plugin creates new account and returns
- // its handle (pointer in fact). That means new account is created with plugin features
- // (it is created inherited account, not base class).
- YAMN_NEWACCOUNTFCN NewAccountFcnPtr;
-
- // Function is called to delete protocol defined variables to inherited CAccount structure
- YAMN_DELETEACCOUNTFCN DeleteAccountFcnPtr;
-
- // Function is called when user requests not tu run account longer. (E.g. when closing Miranda)
- YAMN_STOPACCOUNTFCN StopAccountFcnPtr;
-
- // Function is called when plugin should write its own info into book file
- YAMN_WRITEPLUGINOPTS WritePluginOptsFcnPtr;
-
- // Function is called when plugin should read its own info from book file
- YAMN_READPLUGINOPTS ReadPluginOptsFcnPtr;
-
- // Function is called to synchronise account (delete old mails and get the new ones)
- YAMN_CHECKFCN SynchroFcnPtr;
-
- // Function is called when timer timed out- it can be the same as SynchroFcnPtr
- YAMN_CHECKFCN TimeoutFcnPtr;
-
- // Function is called when forced checking- it can be the same as SynchroFcnPtr
- YAMN_CHECKFCN ForceCheckFcnPtr;
-
- // Function is called when user wants to delete mails
- YAMN_DELETEFCN DeleteMailsFcnPtr;
-
- // Function is called when YAMN wants to get error description. Note the parameter given in
- // this function is in fact the same as your CheckFcnPtr, DeleteMailsFcnPtr etc. returns to YAMN.
- // If you want, you may return pointer to some structure, which includes more information about
- // error than only one DWORD. And then, you can in your function create Unicode string containing
- // all your error code. YAMN copies this string into its own buffer. Your error code and pointer
- // can be deleted in DeleteErrorStringFcnPtr, which is called by YAMN
- YAMN_GETERRORSTRINGWFCN GetErrorStringWFcnPtr;
-
- // This is the same as previous one, but plugin returns normal string (not Unicode). YAMN first
- // looks, if your plugin has implemented GetErrorStringWFcnPtr. If not, it looks for this function
- // So as you (of course) wait, you implemnt only one of these functions or no one of them.
- YAMN_GETERRORSTRINGAFCN GetErrorStringAFcnPtr;
-
- // Deletes error string that was allocated in your GetErrorStringXFcnPtr. Parameter to this fcn is
- // Unicode or normal string. Therefore parameter is defined as LPVOID, but your plugin knows if it is
- // Unicode or not...
- // If NULL, YAMN does nothing with string
- YAMN_DELETEERRORSTRINGFCN DeleteErrorStringFcnPtr;
-
- // Function is called to notify plugin, that it is quite good to store account status (and mails)
- YAMN_WRITEACCOUNTSFCN WriteAccountsFcnPtr;
-
- // Function is called when user wants to view mails
- // not used now, in the future
- YAMN_STANDARDFCN ViewMailsFcnPtr;
-
- // Function is called when application exits. Plugin should unload
- YAMN_STANDARDFCN UnLoadFcn;
-};
-
-typedef HYAMNMAIL(WINAPI *YAMN_NEWMAILFCN)(CAccount *);
-typedef void (WINAPI *YAMN_DELETEMAILFCN)(HYAMNMAIL);
-typedef DWORD(WINAPI *YAMN_WRITEMAILOPTS)(HANDLE File, HYAMNMAIL);
-typedef DWORD(WINAPI *YAMN_READMAILOPTS)(HYAMNMAIL, char **, char *);
-
-struct YAMN_MAILIMPORTFCN
-{
- // Note: not all of these functions are needed to be implemented in your protocol plugin. Those
- // functions, which are not implemented, you have to set to NULL.
-
- // Function is called to construct protocol defined account
- // This is VERY IMPORTANT for YAMN and plugin to cooperate:
- // Imagine following situation. YAMN wants to add new account (it is possible e.g.
- // when loading accounts from file), so it has to call protocol constructor.
- // It calls NewAccount function and plugin creates new account and returns
- // its handle (pointer in fact). That means new account is created with plugin features
- // (it is created inherited account, not base class).
- YAMN_NEWMAILFCN NewMailFcnPtr;
-
- // Function is called to delete protocol defined variables to inherited CAccount structure
- YAMN_DELETEMAILFCN DeleteMailFcnPtr;
-
- // Function is called when plugin should write its own info into book file
- YAMN_WRITEMAILOPTS WriteMailOptsFcnPtr;
-
- // Function is called when plugin should read its own info from book file
- YAMN_READMAILOPTS ReadMailOptsFcnPtr;
-};
-
-//
-// ================================== PROTOCOL PLUGIN REGISTRATION STRUCTURES ==================================
-//
-
-struct YAMN_PROTOREGISTRATION
-{
- // Name of plugin
- // this member CANNOT be NULL. Just write here description, i.e. "Yahoo Mail 1.2"
- char *Name;
-
- // The version of plugin. CANNOT be NULL.
- char *Ver;
-
- // Plugin copyright
- // Write here your copyright if you want (or NULL)
- char *Copyright;
-
- // Plugin description. Can be NULL.
- char *Description;
-
- // Your contact (email). Can be NULL.
- char *Email;
-
- // The web page. Can be NULL.
- char *WWW;
-};
-
-struct YAMN_PROTOPLUGIN
-{
- // Pointer to first protocol plugin account
- CAccount *FirstAccount = 0;
-
- // We prevent browsing through accounts (chained list) from deleting or adding any account
- // If we want to delete or add, we must have "write" access to AccountBrowserSO
- // Note that accounts can be changed during AccountBrowser is in "read" mode, because we do not add or delete account.
- SWMRG AccountBrowserSO;
-
- // All needed other info from plugin
- YAMN_PROTOREGISTRATION *PluginInfo;
-
- // Imported functions
- YAMN_PROTOIMPORTFCN *Fcn = 0;
- YAMN_MAILIMPORTFCN *MailFcn = 0;
-};
-
-struct YAMN_PROTOPLUGINQUEUE
-{
- YAMN_PROTOPLUGIN *Plugin;
- YAMN_PROTOPLUGINQUEUE *Next;
-};
-
-#endif
+#ifndef __M_PROTOPLUGIN_H +#define __M_PROTOPLUGIN_H + +// +// ================================== OTHER DEFINITIONS ======================================== +// + +// structure is used to give parameters to Check, Synchro or Timeout function +struct CheckParam +{ + CheckParam(CAccount *_1, int _2) : + AccountParam(_1), + Flags(_2) + {} + + // ActualAccount- the only parameter used in Check function and should contain all needed information I think :) + CAccount *AccountParam; + + // I thought it, but this is needed, too + #define YAMN_NORMALCHECK 0 + #define YAMN_FORCECHECK 1 + int Flags; +}; + +// structure is used to give parameters to DeleteMails function +typedef struct CheckParam DeleteParam; + +// +// ================================== IMPORTED FUNCTIONS ================================== +// + +typedef DWORD (MIR_CDECL *YAMN_STANDARDFCN)(LPVOID); +typedef CAccount* (MIR_CDECL *YAMN_NEWACCOUNTFCN)(struct YAMN_PROTOPLUGIN *); +typedef void (MIR_CDECL *YAMN_STOPACCOUNTFCN)(CAccount *); +typedef void (MIR_CDECL *YAMN_DELETEACCOUNTFCN)(CAccount *); +typedef DWORD (MIR_CDECL *YAMN_WRITEPLUGINOPTS)(HANDLE File, CAccount *); +typedef DWORD (MIR_CDECL *YAMN_READPLUGINOPTS)(CAccount *, char **, char *); +typedef void (MIR_CDECL *YAMN_CHECKFCN)(CheckParam *); +typedef void (MIR_CDECL *YAMN_DELETEFCN)(void *); +typedef TCHAR* (MIR_CDECL *YAMN_GETERRORSTRINGWFCN)(DWORD); +typedef char* (MIR_CDECL *YAMN_GETERRORSTRINGAFCN)(DWORD); +typedef void (MIR_CDECL *YAMN_DELETEERRORSTRINGFCN)(LPVOID); +typedef DWORD (MIR_CDECL *YAMN_WRITEACCOUNTSFCN)(); + +typedef struct CYAMNVariables* (MIR_CDECL *YAMN_GETVARIABLESFCN)(DWORD); + +struct YAMN_PROTOIMPORTFCN +{ + // Note: not all of these functions are needed to be implemented in your protocol plugin. Those + // functions, which are not implemented, you have to set to NULL. + + // Function is called to construct protocol defined account + // This is VERY IMPORTANT for YAMN and plugin to cooperate: + // Imagine following situation. YAMN wants to add new account (it is possible e.g. + // when loading accounts from file), so it has to call protocol constructor. + // It calls NewAccount function and plugin creates new account and returns + // its handle (pointer in fact). That means new account is created with plugin features + // (it is created inherited account, not base class). + YAMN_NEWACCOUNTFCN NewAccountFcnPtr; + + // Function is called to delete protocol defined variables to inherited CAccount structure + YAMN_DELETEACCOUNTFCN DeleteAccountFcnPtr; + + // Function is called when user requests not tu run account longer. (E.g. when closing Miranda) + YAMN_STOPACCOUNTFCN StopAccountFcnPtr; + + // Function is called when plugin should write its own info into book file + YAMN_WRITEPLUGINOPTS WritePluginOptsFcnPtr; + + // Function is called when plugin should read its own info from book file + YAMN_READPLUGINOPTS ReadPluginOptsFcnPtr; + + // Function is called to synchronise account (delete old mails and get the new ones) + YAMN_CHECKFCN SynchroFcnPtr; + + // Function is called when timer timed out- it can be the same as SynchroFcnPtr + YAMN_CHECKFCN TimeoutFcnPtr; + + // Function is called when forced checking- it can be the same as SynchroFcnPtr + YAMN_CHECKFCN ForceCheckFcnPtr; + + // Function is called when user wants to delete mails + YAMN_DELETEFCN DeleteMailsFcnPtr; + + // Function is called when YAMN wants to get error description. Note the parameter given in + // this function is in fact the same as your CheckFcnPtr, DeleteMailsFcnPtr etc. returns to YAMN. + // If you want, you may return pointer to some structure, which includes more information about + // error than only one DWORD. And then, you can in your function create Unicode string containing + // all your error code. YAMN copies this string into its own buffer. Your error code and pointer + // can be deleted in DeleteErrorStringFcnPtr, which is called by YAMN + YAMN_GETERRORSTRINGWFCN GetErrorStringWFcnPtr; + + // This is the same as previous one, but plugin returns normal string (not Unicode). YAMN first + // looks, if your plugin has implemented GetErrorStringWFcnPtr. If not, it looks for this function + // So as you (of course) wait, you implemnt only one of these functions or no one of them. + YAMN_GETERRORSTRINGAFCN GetErrorStringAFcnPtr; + + // Deletes error string that was allocated in your GetErrorStringXFcnPtr. Parameter to this fcn is + // Unicode or normal string. Therefore parameter is defined as LPVOID, but your plugin knows if it is + // Unicode or not... + // If NULL, YAMN does nothing with string + YAMN_DELETEERRORSTRINGFCN DeleteErrorStringFcnPtr; + + // Function is called to notify plugin, that it is quite good to store account status (and mails) + YAMN_WRITEACCOUNTSFCN WriteAccountsFcnPtr; + + // Function is called when user wants to view mails + // not used now, in the future + YAMN_STANDARDFCN ViewMailsFcnPtr; + + // Function is called when application exits. Plugin should unload + YAMN_STANDARDFCN UnLoadFcn; +}; + +typedef HYAMNMAIL (MIR_CDECL *YAMN_NEWMAILFCN)(CAccount *); +typedef void (MIR_CDECL *YAMN_DELETEMAILFCN)(HYAMNMAIL); +typedef DWORD (MIR_CDECL *YAMN_WRITEMAILOPTS)(HANDLE File, HYAMNMAIL); +typedef DWORD (MIR_CDECL *YAMN_READMAILOPTS)(HYAMNMAIL, char **, char *); + +struct YAMN_MAILIMPORTFCN +{ + // Note: not all of these functions are needed to be implemented in your protocol plugin. Those + // functions, which are not implemented, you have to set to NULL. + + // Function is called to construct protocol defined account + // This is VERY IMPORTANT for YAMN and plugin to cooperate: + // Imagine following situation. YAMN wants to add new account (it is possible e.g. + // when loading accounts from file), so it has to call protocol constructor. + // It calls NewAccount function and plugin creates new account and returns + // its handle (pointer in fact). That means new account is created with plugin features + // (it is created inherited account, not base class). + YAMN_NEWMAILFCN NewMailFcnPtr; + + // Function is called to delete protocol defined variables to inherited CAccount structure + YAMN_DELETEMAILFCN DeleteMailFcnPtr; + + // Function is called when plugin should write its own info into book file + YAMN_WRITEMAILOPTS WriteMailOptsFcnPtr; + + // Function is called when plugin should read its own info from book file + YAMN_READMAILOPTS ReadMailOptsFcnPtr; +}; + +// +// ================================== PROTOCOL PLUGIN REGISTRATION STRUCTURES ================================== +// + +struct YAMN_PROTOREGISTRATION +{ + // Name of plugin + // this member CANNOT be NULL. Just write here description, i.e. "Yahoo Mail 1.2" + char *Name; + + // The version of plugin. CANNOT be NULL. + char *Ver; + + // Plugin copyright + // Write here your copyright if you want (or NULL) + char *Copyright; + + // Plugin description. Can be NULL. + char *Description; + + // Your contact (email). Can be NULL. + char *Email; + + // The web page. Can be NULL. + char *WWW; +}; + +struct YAMN_PROTOPLUGIN +{ + // Pointer to first protocol plugin account + CAccount *FirstAccount = 0; + + // We prevent browsing through accounts (chained list) from deleting or adding any account + // If we want to delete or add, we must have "write" access to AccountBrowserSO + // Note that accounts can be changed during AccountBrowser is in "read" mode, because we do not add or delete account. + SWMRG AccountBrowserSO; + + // All needed other info from plugin + YAMN_PROTOREGISTRATION *PluginInfo; + + // Imported functions + YAMN_PROTOIMPORTFCN *Fcn = 0; + YAMN_MAILIMPORTFCN *MailFcn = 0; +}; + +struct YAMN_PROTOPLUGINQUEUE +{ + YAMN_PROTOPLUGIN *Plugin; + YAMN_PROTOPLUGINQUEUE *Next; +}; + +#endif diff --git a/protocols/YAMN/src/resource.h b/protocols/YAMN/src/resource.h index 81894659cc..b1633a9caf 100644 --- a/protocols/YAMN/src/resource.h +++ b/protocols/YAMN/src/resource.h @@ -96,14 +96,15 @@ #define IDC_PREVIEW 1402
#define IDC_BTNADD 1403
#define IDC_EDITNAME 1404
+#define IDC_FORCECHECK 1407
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 144
+#define _APS_NEXT_RESOURCE_VALUE 145
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1407
+#define _APS_NEXT_CONTROL_VALUE 1408
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/protocols/YAMN/src/services.cpp b/protocols/YAMN/src/services.cpp index 51c8b85e4b..ee4476bf41 100644 --- a/protocols/YAMN/src/services.cpp +++ b/protocols/YAMN/src/services.cpp @@ -65,11 +65,6 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) return 0;
if (CAccount *ActualAccount = FindAccountByContact(POP3Plugin, hContact)) {
- // we use event to signal, that running thread has all needed stack parameters copied
- HANDLE ThreadRunningEV;
- if (nullptr == (ThreadRunningEV = CreateEvent(nullptr, FALSE, FALSE, nullptr)))
- return 0;
-
// 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;
@@ -78,14 +73,9 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) SReadGuard sra(ActualAccount->AccountAccessSO);
if (sra.Succeeded()) {
// account cannot be forced to check
- if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) {
- DWORD tid;
- CheckParam ParamToPlugin = { YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount };
- if (CreateThread(nullptr, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, &ParamToPlugin, 0, &tid))
- WaitForSingleObject(ThreadRunningEV, INFINITE);
- }
+ if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE))
+ mir_forkThread<CheckParam>(ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, new CheckParam(ActualAccount, g_plugin.CheckFlags()));
}
- CloseHandle(ThreadRunningEV);
}
return 0;
}
diff --git a/protocols/YAMN/src/stdafx.h b/protocols/YAMN/src/stdafx.h index cdeea26edc..aa88d18df9 100644 --- a/protocols/YAMN/src/stdafx.h +++ b/protocols/YAMN/src/stdafx.h @@ -26,16 +26,22 @@ #include <m_toptoolbar.h>
#include <m_kbdnotify.h>
#include <m_yamn.h>
-#include <m_protoplugin.h>
#include <m_folders.h>
-#include "main.h"
#include "mails/decode.h"
-#include "browser/browser.h"
-#include "resource.h"
+#include "mails/mails.h"
+
+#include "account.h"
+#include "protoplugin.h"
+
+#include "main.h"
#include "debug.h"
+
+#include "resource.h"
#include "version.h"
+#include "browser/browser.h"
+
#include "proto/netlib.h"
#include "proto/pop3/pop3.h"
#include "proto/pop3/pop3comm.h"
@@ -44,12 +50,16 @@ struct CMPlugin : public PLUGIN<CMPlugin> {
CMPlugin();
+ CMOption<bool> bForceCheck;
+ __forceinline bool CheckFlags() {
+ return bForceCheck ? YAMN_FORCECHECK : YAMN_NORMALCHECK;
+ }
+
int Load() override;
int Unload() override;
};
// From services.cpp
-void AccountMailCheck(CAccount *ActualAccount);
void CreateServiceFunctions(void);
void HookEvents(void);
@@ -100,7 +110,7 @@ uint32_t WriteStringToFile(HANDLE File, char *Source); uint32_t WriteStringToFileW(HANDLE File, wchar_t *Source);
DWORD WriteMessagesToFile(HANDLE File, CAccount *Which);
-DWORD WINAPI WritePOP3Accounts();
+DWORD MIR_CDECL WritePOP3Accounts();
void __cdecl DeleteAccountInBackground(void *Which);
int StopAccounts(YAMN_PROTOPLUGIN *Plugin);
diff --git a/protocols/YAMN/src/yamn.cpp b/protocols/YAMN/src/yamn.cpp index efc19e4136..d95721e6fb 100644 --- a/protocols/YAMN/src/yamn.cpp +++ b/protocols/YAMN/src/yamn.cpp @@ -33,11 +33,6 @@ HANDLE WriteToFileEV; void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
{
- // we use event to signal, that running thread has all needed stack parameters copied
- HANDLE ThreadRunningEV = CreateEvent(nullptr, FALSE, FALSE, nullptr);
- if (ThreadRunningEV == nullptr)
- return;
-
// if we want to close miranda, we get event and do not run checking anymore
if (WAIT_OBJECT_0 == WaitForSingleObject(ExitEV, 0))
return;
@@ -80,17 +75,8 @@ void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) WindowList_BroadcastAsync(YAMNVar.MessageWnds, WM_YAMN_CHANGETIME, (WPARAM)ActualAccount, (LPARAM)ActualAccount->TimeLeft);
if (!ActualAccount->TimeLeft) {
- struct CheckParam ParamToPlugin = {YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount };
-
ActualAccount->TimeLeft = ActualAccount->Interval;
-
- DWORD tid;
- HANDLE NewThread = CreateThread(nullptr, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->TimeoutFcnPtr, &ParamToPlugin, 0, &tid);
- if (NewThread == nullptr)
- continue;
-
- WaitForSingleObject(ThreadRunningEV, INFINITE);
- CloseHandle(NewThread);
+ mir_forkthread((pThreadFunc)ActualAccount->Plugin->Fcn->TimeoutFcnPtr, new CheckParam(ActualAccount, YAMN_NORMALCHECK));
}
}
@@ -107,47 +93,31 @@ ChangeIsCountingStatusLabel: }
}
}
- CloseHandle(ThreadRunningEV);
}
INT_PTR ForceCheckSvc(WPARAM, LPARAM)
{
- // we use event to signal, that running thread has all needed stack parameters copied
- HANDLE ThreadRunningEV = CreateEvent(nullptr, FALSE, FALSE, nullptr);
- if (ThreadRunningEV == nullptr)
- return 0;
-
// 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);
-
- for (YAMN_PROTOPLUGINQUEUE *ActualPlugin = FirstProtoPlugin; ActualPlugin != nullptr; ActualPlugin = ActualPlugin->Next) {
- SReadGuard srb(ActualPlugin->Plugin->AccountBrowserSO);
- for (auto *ActualAccount = ActualPlugin->Plugin->FirstAccount; ActualAccount != nullptr; ActualAccount = ActualAccount->Next) {
- if (ActualAccount->Plugin->Fcn == nullptr) //account not inited
- continue;
-
- SReadGuard sra(ActualAccount->AccountAccessSO);
- if (!sra.Succeeded())
- continue;
+ mir_cslock lck(PluginRegCS);
- if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) { //account cannot be forced to check
- if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr == nullptr)
- continue;
+ for (auto *ActualPlugin = FirstProtoPlugin; ActualPlugin != nullptr; ActualPlugin = ActualPlugin->Next) {
+ SReadGuard srb(ActualPlugin->Plugin->AccountBrowserSO);
+ for (auto *ActualAccount = ActualPlugin->Plugin->FirstAccount; ActualAccount != nullptr; ActualAccount = ActualAccount->Next) {
+ if (ActualAccount->Plugin->Fcn == nullptr) //account not inited
+ continue;
- DWORD tid;
- CheckParam ParamToPlugin = { YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount };
- if (nullptr == CreateThread(nullptr, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, &ParamToPlugin, 0, &tid))
- continue;
+ SReadGuard sra(ActualAccount->AccountAccessSO);
+ if (!sra.Succeeded())
+ continue;
- WaitForSingleObject(ThreadRunningEV, INFINITE);
- }
- }
+ // account cannot be forced to check
+ if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE))
+ if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr)
+ mir_forkThread<CheckParam>(ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, new CheckParam(ActualAccount, g_plugin.CheckFlags()));
}
}
-
- CloseHandle(ThreadRunningEV);
return 1;
}
|