From 4b6899c098f97960bf58456313ac8d643336dcd0 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Sun, 14 Oct 2012 09:45:11 +0000 Subject: YAMN: folders restructurization git-svn-id: http://svn.miranda-ng.org/main/trunk@1919 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/YAMN/ChangeLog.txt | 243 -- protocols/YAMN/YAMN_10.vcxproj | 64 +- protocols/YAMN/YAMN_10.vcxproj.filters | 74 +- protocols/YAMN/YAMNopts.cpp | 2 - protocols/YAMN/account.cpp | 1309 ---------- protocols/YAMN/browser/badconnect.cpp | 345 --- protocols/YAMN/browser/m_browser.h | 42 - protocols/YAMN/browser/mailbrowser.cpp | 2605 -------------------- protocols/YAMN/debug.cpp | 139 -- protocols/YAMN/debug.h | 67 - protocols/YAMN/docs/ChangeLog.txt | 243 ++ protocols/YAMN/docs/yamn-translation.txt | 184 ++ protocols/YAMN/filter/Base/AggressiveOptimize.h | 168 -- protocols/YAMN/filter/Base/Base.dsp | 108 - protocols/YAMN/filter/Base/Base.mak | 229 -- protocols/YAMN/filter/Base/debug.cpp | 73 - protocols/YAMN/filter/Base/docs/base-readme.txt | 63 - protocols/YAMN/filter/Base/maindll.cpp | 238 -- protocols/YAMN/filter/Simple/AggressiveOptimize.h | 168 -- .../YAMN/filter/Simple/docs/simple-readme.txt | 51 - protocols/YAMN/filter/Simple/maindll.cpp | 132 - protocols/YAMN/filter/Simple/simple.dsp | 105 - protocols/YAMN/filter/Simple/simple.mak | 207 -- protocols/YAMN/filter/readme.txt | 1 - protocols/YAMN/filterplugin.cpp | 204 -- protocols/YAMN/icons/iconttbup.ico | Bin 1150 -> 0 bytes protocols/YAMN/icons/icoyamn1.ico | Bin 1150 -> 0 bytes protocols/YAMN/icons/icoyamn2.ico | Bin 1150 -> 0 bytes protocols/YAMN/icons/proto_YAMN.rc | 19 - protocols/YAMN/icons/proto_YAMN_10.vcxproj | 142 -- protocols/YAMN/icons/proto_YAMN_10.vcxproj.filters | 37 - protocols/YAMN/icons/resource.h | 2 - protocols/YAMN/include/IcoLib.h | 26 - protocols/YAMN/mails/decode.cpp | 558 ----- protocols/YAMN/mails/m_decode.h | 25 - protocols/YAMN/mails/mails.cpp | 499 ---- protocols/YAMN/mails/mime.cpp | 732 ------ protocols/YAMN/mails/test/header.txt | 28 - protocols/YAMN/mails/test/header2.txt | 97 - protocols/YAMN/mails/test/readme.txt | 4 - protocols/YAMN/mails/test/test.cpp | 42 - protocols/YAMN/mails/test/test.dsp | 112 - protocols/YAMN/mails/test/test.dsw | 29 - protocols/YAMN/main.cpp | 517 ---- protocols/YAMN/main.h | 51 - protocols/YAMN/proto/md5.c | 260 -- protocols/YAMN/proto/md5.h | 27 - protocols/YAMN/proto/netclient.h | 22 - protocols/YAMN/proto/netlib.cpp | 271 -- protocols/YAMN/proto/netlib.h | 55 - protocols/YAMN/proto/pop3/pop3.cpp | 370 --- protocols/YAMN/proto/pop3/pop3.h | 66 - protocols/YAMN/proto/pop3/pop3comm.cpp | 1563 ------------ protocols/YAMN/proto/pop3/pop3comm.h | 97 - protocols/YAMN/proto/pop3/pop3opt.cpp | 1556 ------------ protocols/YAMN/proto/pop3/pop3opt.h | 40 - protocols/YAMN/proto_yamn/proto_YAMN_10.vcxproj | 131 + .../YAMN/proto_yamn/proto_YAMN_10.vcxproj.filters | 22 + protocols/YAMN/proto_yamn/res/icoaway.ico | Bin 0 -> 2038 bytes protocols/YAMN/proto_yamn/res/icooccupied.ico | Bin 0 -> 2038 bytes protocols/YAMN/proto_yamn/res/icooffline.ico | Bin 0 -> 2038 bytes protocols/YAMN/proto_yamn/res/icoonline.ico | Bin 0 -> 2038 bytes protocols/YAMN/proto_yamn/res/proto_YAMN.rc | 16 + protocols/YAMN/proto_yamn/src/resource.h | 20 + protocols/YAMN/protoplugin.cpp | 197 -- protocols/YAMN/res/YAMN.rc | 337 +++ protocols/YAMN/res/iconeutral.ico | Bin 0 -> 2038 bytes protocols/YAMN/res/iconttbdown.ico | Bin 0 -> 2038 bytes protocols/YAMN/res/icooffline.ico | Bin 0 -> 2038 bytes protocols/YAMN/res/icoyamn3.ico | Bin 0 -> 2038 bytes protocols/YAMN/res/yamn_ver.rc | 76 + protocols/YAMN/resources/YAMN.rc | 344 --- protocols/YAMN/resources/iconeutral.ico | Bin 1150 -> 0 bytes protocols/YAMN/resources/iconttbdown.ico | Bin 1150 -> 0 bytes protocols/YAMN/resources/icooffline.ico | Bin 1150 -> 0 bytes protocols/YAMN/resources/icoyamn3.ico | Bin 1150 -> 0 bytes protocols/YAMN/resources/resource.h | 129 - protocols/YAMN/resources/yamn.bmp | Bin 502 -> 0 bytes protocols/YAMN/resources/yamn_ver.rc | 77 - protocols/YAMN/services.cpp | 496 ---- protocols/YAMN/src/YAMNopts.cpp | 2 + protocols/YAMN/src/account.cpp | 1309 ++++++++++ protocols/YAMN/src/browser/badconnect.cpp | 345 +++ protocols/YAMN/src/browser/m_browser.h | 42 + protocols/YAMN/src/browser/mailbrowser.cpp | 2605 ++++++++++++++++++++ protocols/YAMN/src/debug.cpp | 139 ++ protocols/YAMN/src/debug.h | 67 + protocols/YAMN/src/filterplugin.cpp | 204 ++ protocols/YAMN/src/mails/decode.cpp | 558 +++++ protocols/YAMN/src/mails/m_decode.h | 25 + protocols/YAMN/src/mails/mails.cpp | 499 ++++ protocols/YAMN/src/mails/mime.cpp | 732 ++++++ protocols/YAMN/src/main.cpp | 505 ++++ protocols/YAMN/src/main.h | 51 + protocols/YAMN/src/proto/md5.c | 259 ++ protocols/YAMN/src/proto/md5.h | 27 + protocols/YAMN/src/proto/netclient.h | 22 + protocols/YAMN/src/proto/netlib.cpp | 271 ++ protocols/YAMN/src/proto/netlib.h | 55 + protocols/YAMN/src/proto/pop3/pop3.cpp | 370 +++ protocols/YAMN/src/proto/pop3/pop3.h | 66 + protocols/YAMN/src/proto/pop3/pop3comm.cpp | 1563 ++++++++++++ protocols/YAMN/src/proto/pop3/pop3comm.h | 97 + protocols/YAMN/src/proto/pop3/pop3opt.cpp | 1556 ++++++++++++ protocols/YAMN/src/proto/pop3/pop3opt.h | 40 + protocols/YAMN/src/protoplugin.cpp | 197 ++ protocols/YAMN/src/resource.h | 128 + protocols/YAMN/src/services.cpp | 496 ++++ protocols/YAMN/src/synchro.cpp | 359 +++ protocols/YAMN/src/version.h | 3 + protocols/YAMN/src/yamn.cpp | 333 +++ protocols/YAMN/src/yamn.h | 271 ++ protocols/YAMN/synchro.cpp | 359 --- protocols/YAMN/version.h | 3 - protocols/YAMN/yamn-translation.txt | 184 -- protocols/YAMN/yamn.cpp | 333 --- protocols/YAMN/yamn.h | 274 -- 117 files changed, 14281 insertions(+), 16224 deletions(-) delete mode 100644 protocols/YAMN/ChangeLog.txt delete mode 100644 protocols/YAMN/YAMNopts.cpp delete mode 100644 protocols/YAMN/account.cpp delete mode 100644 protocols/YAMN/browser/badconnect.cpp delete mode 100644 protocols/YAMN/browser/m_browser.h delete mode 100644 protocols/YAMN/browser/mailbrowser.cpp delete mode 100644 protocols/YAMN/debug.cpp delete mode 100644 protocols/YAMN/debug.h create mode 100644 protocols/YAMN/docs/ChangeLog.txt create mode 100644 protocols/YAMN/docs/yamn-translation.txt delete mode 100644 protocols/YAMN/filter/Base/AggressiveOptimize.h delete mode 100644 protocols/YAMN/filter/Base/Base.dsp delete mode 100644 protocols/YAMN/filter/Base/Base.mak delete mode 100644 protocols/YAMN/filter/Base/debug.cpp delete mode 100644 protocols/YAMN/filter/Base/docs/base-readme.txt delete mode 100644 protocols/YAMN/filter/Base/maindll.cpp delete mode 100644 protocols/YAMN/filter/Simple/AggressiveOptimize.h delete mode 100644 protocols/YAMN/filter/Simple/docs/simple-readme.txt delete mode 100644 protocols/YAMN/filter/Simple/maindll.cpp delete mode 100644 protocols/YAMN/filter/Simple/simple.dsp delete mode 100644 protocols/YAMN/filter/Simple/simple.mak delete mode 100644 protocols/YAMN/filter/readme.txt delete mode 100644 protocols/YAMN/filterplugin.cpp delete mode 100644 protocols/YAMN/icons/iconttbup.ico delete mode 100644 protocols/YAMN/icons/icoyamn1.ico delete mode 100644 protocols/YAMN/icons/icoyamn2.ico delete mode 100644 protocols/YAMN/icons/proto_YAMN.rc delete mode 100644 protocols/YAMN/icons/proto_YAMN_10.vcxproj delete mode 100644 protocols/YAMN/icons/proto_YAMN_10.vcxproj.filters delete mode 100644 protocols/YAMN/icons/resource.h delete mode 100644 protocols/YAMN/include/IcoLib.h delete mode 100644 protocols/YAMN/mails/decode.cpp delete mode 100644 protocols/YAMN/mails/m_decode.h delete mode 100644 protocols/YAMN/mails/mails.cpp delete mode 100644 protocols/YAMN/mails/mime.cpp delete mode 100644 protocols/YAMN/mails/test/header.txt delete mode 100644 protocols/YAMN/mails/test/header2.txt delete mode 100644 protocols/YAMN/mails/test/readme.txt delete mode 100644 protocols/YAMN/mails/test/test.cpp delete mode 100644 protocols/YAMN/mails/test/test.dsp delete mode 100644 protocols/YAMN/mails/test/test.dsw delete mode 100644 protocols/YAMN/main.cpp delete mode 100644 protocols/YAMN/main.h delete mode 100644 protocols/YAMN/proto/md5.c delete mode 100644 protocols/YAMN/proto/md5.h delete mode 100644 protocols/YAMN/proto/netclient.h delete mode 100644 protocols/YAMN/proto/netlib.cpp delete mode 100644 protocols/YAMN/proto/netlib.h delete mode 100644 protocols/YAMN/proto/pop3/pop3.cpp delete mode 100644 protocols/YAMN/proto/pop3/pop3.h delete mode 100644 protocols/YAMN/proto/pop3/pop3comm.cpp delete mode 100644 protocols/YAMN/proto/pop3/pop3comm.h delete mode 100644 protocols/YAMN/proto/pop3/pop3opt.cpp delete mode 100644 protocols/YAMN/proto/pop3/pop3opt.h create mode 100644 protocols/YAMN/proto_yamn/proto_YAMN_10.vcxproj create mode 100644 protocols/YAMN/proto_yamn/proto_YAMN_10.vcxproj.filters create mode 100644 protocols/YAMN/proto_yamn/res/icoaway.ico create mode 100644 protocols/YAMN/proto_yamn/res/icooccupied.ico create mode 100644 protocols/YAMN/proto_yamn/res/icooffline.ico create mode 100644 protocols/YAMN/proto_yamn/res/icoonline.ico create mode 100644 protocols/YAMN/proto_yamn/res/proto_YAMN.rc create mode 100644 protocols/YAMN/proto_yamn/src/resource.h delete mode 100644 protocols/YAMN/protoplugin.cpp create mode 100644 protocols/YAMN/res/YAMN.rc create mode 100644 protocols/YAMN/res/iconeutral.ico create mode 100644 protocols/YAMN/res/iconttbdown.ico create mode 100644 protocols/YAMN/res/icooffline.ico create mode 100644 protocols/YAMN/res/icoyamn3.ico create mode 100644 protocols/YAMN/res/yamn_ver.rc delete mode 100644 protocols/YAMN/resources/YAMN.rc delete mode 100644 protocols/YAMN/resources/iconeutral.ico delete mode 100644 protocols/YAMN/resources/iconttbdown.ico delete mode 100644 protocols/YAMN/resources/icooffline.ico delete mode 100644 protocols/YAMN/resources/icoyamn3.ico delete mode 100644 protocols/YAMN/resources/resource.h delete mode 100644 protocols/YAMN/resources/yamn.bmp delete mode 100644 protocols/YAMN/resources/yamn_ver.rc delete mode 100644 protocols/YAMN/services.cpp create mode 100644 protocols/YAMN/src/YAMNopts.cpp create mode 100644 protocols/YAMN/src/account.cpp create mode 100644 protocols/YAMN/src/browser/badconnect.cpp create mode 100644 protocols/YAMN/src/browser/m_browser.h create mode 100644 protocols/YAMN/src/browser/mailbrowser.cpp create mode 100644 protocols/YAMN/src/debug.cpp create mode 100644 protocols/YAMN/src/debug.h create mode 100644 protocols/YAMN/src/filterplugin.cpp create mode 100644 protocols/YAMN/src/mails/decode.cpp create mode 100644 protocols/YAMN/src/mails/m_decode.h create mode 100644 protocols/YAMN/src/mails/mails.cpp create mode 100644 protocols/YAMN/src/mails/mime.cpp create mode 100644 protocols/YAMN/src/main.cpp create mode 100644 protocols/YAMN/src/main.h create mode 100644 protocols/YAMN/src/proto/md5.c create mode 100644 protocols/YAMN/src/proto/md5.h create mode 100644 protocols/YAMN/src/proto/netclient.h create mode 100644 protocols/YAMN/src/proto/netlib.cpp create mode 100644 protocols/YAMN/src/proto/netlib.h create mode 100644 protocols/YAMN/src/proto/pop3/pop3.cpp create mode 100644 protocols/YAMN/src/proto/pop3/pop3.h create mode 100644 protocols/YAMN/src/proto/pop3/pop3comm.cpp create mode 100644 protocols/YAMN/src/proto/pop3/pop3comm.h create mode 100644 protocols/YAMN/src/proto/pop3/pop3opt.cpp create mode 100644 protocols/YAMN/src/proto/pop3/pop3opt.h create mode 100644 protocols/YAMN/src/protoplugin.cpp create mode 100644 protocols/YAMN/src/resource.h create mode 100644 protocols/YAMN/src/services.cpp create mode 100644 protocols/YAMN/src/synchro.cpp create mode 100644 protocols/YAMN/src/version.h create mode 100644 protocols/YAMN/src/yamn.cpp create mode 100644 protocols/YAMN/src/yamn.h delete mode 100644 protocols/YAMN/synchro.cpp delete mode 100644 protocols/YAMN/version.h delete mode 100644 protocols/YAMN/yamn-translation.txt delete mode 100644 protocols/YAMN/yamn.cpp delete mode 100644 protocols/YAMN/yamn.h (limited to 'protocols') diff --git a/protocols/YAMN/ChangeLog.txt b/protocols/YAMN/ChangeLog.txt deleted file mode 100644 index 6a85810ab2..0000000000 --- a/protocols/YAMN/ChangeLog.txt +++ /dev/null @@ -1,243 +0,0 @@ -0.1.2.5 -======= -! fix many memory leaks patch by Merlin -* x64 support by Merlin -* Resource patch by mataes (for translations) - -0.1.2.4 -======= -* Only show popup tab if popup plugin is present -! Wrong time displayed in mailbrower (fix by y_b) - -0.1.2.3 -======= -* New design for the options pages (Thanks Eyecue) - -0.1.2.2 -======= -* using, with updater, the correct file id in file listing (yamn 2in1) -+ added folders plugin support -+ Support for miranda 0.8 - -0.1.2.1 -======= -! Don't close MailBrowser when e-mails are updated if it is manually open -+ Discard the new Event when message is shown or is deleted from the server -+ Option to disable the CList events per account -+ Contact status change also happens when e-mail are being deleted - -0.1.2.0 -======= -! patch by TioDuke for icolib and status and status icons handling. Thanks! -! code cleaning (properly destroy services and hooks) -+ Contact status changes accordingly the action (Ready, Working, Error) - -0.1.1.0 -======= -+ Show message is open in new thread -+ Click on individual new e-mail popups shows the message window - -0.1.0.2 -============ -+ Pressing "Space" key will show the selected message -! Delete message is done by DELETE key, not by '.' -! removed some repeated code -! "Ok" and "Select All" buttons in mail browser are translatable - -0.1.0.1 -============ -+ Message body shown in separate edit box. -+ Support for Content-transfer-encoding: Quoted-Printable and base64 -+ Recursive Content-type: multipart/ support -+ Option to auto retrieve body - -0.0.1.11 -============ -+ Option to use yamn as a protocol. -* Patch by Tioduke (code cleaning) -! Fixed the crash parsing invalid "Date" header (SPAMs or silly e-mail client) (y_b) -! ShowMessage dialog follows Content-type header to chose the codepage (y_b) -+ Only supported codepages are shown in the options (y_b) -+ Enhance codepages support (y_b) - -0.0.1.10 -============ -! Icons are based on single bitmap image (y_b) -* Show full feaders on double click in mailbrowser (y_b) -* Dates are shown localized and sorted correctly (y_b) -* To show long/short date and seconds (y_b) -! Solved a rare/random crash on unstable connection (y_b) -! Enabled tabstop on new tabcontrol and reordered tabstop in option pages (y_b) -* Enable TAB selection in mailbrowser dialog (patch by -pv-) -+ introducing 2in1 build - can be used both in win9x and NT/XP -* Options redesign. - -0.0.1.9 -============ -* Patch by Perf (visual patch) - -0.0.1.8 -============ -+ add ctr-A to select all mails -+ del key delete selected mail -+ add a select all button - -0.0.1.7 -============ -* Change options dialog (use tabsrmm uxtheme) -! Invert back and text color for no new mail popup in option page. -* New default icon reworked by Faith Healer. - -0.0.1.6 -============ -* Try to update all icons when changing in icolib. -! Allow scrolling in list of email account. (Patch by Jazzy) -! Memory leak in stls fix (y_b) - -0.0.1.5 -============ -! Bug fix with help.dll problem. (Patch by Jazzy) - (http://developer.berlios.de/bugs/?func=detailbug&bug_id=6692&group_id=3292) -! Remove merge in agressiveoptimize.h - -0.0.1.4 -============ -! Option page bug (patch by y_b) -* Allow to edit the application text - -0.0.1.3 -============ -! Bug fix with new icolib - -0.0.1.2 -============ -! Bug fix with updater and stable version -+ Using new m_icolib.h -+ New context menu entry to launch application -+ Patch by y_b -{ - + Start TLS support - + Better icolib support - + SSL Logging -} - -0.0.1.1 -============ -! Bug fix on left click popup. - -0.0.1.0 -============ -Time for release. - -0.0.0.18 -============ -! Visual bug in option page -! Recompilation for win 9x users. - -0.0.0.17 -============ -* Redesign option page to have only one entry in plugins options -! Bug fix when there is no date set in the header (spam mails) (Thx Egres) - -0.0.0.16 -============ -* Right click on error popup close the popup. -! Missing break; in nonewmail popup in switch. -+ Add option to rename contact according to new mail. -! Patch by pescuma on delete accounts - -0.0.0.15 -============ -! Fixed dismiss event by right click on new mail popup crash -* Change string for the status choose button -! use CallServiceSync() instead of CallService() for adding clistevent (now icon blinks) - -0.0.0.14 -============ -! Tooltip on the clist event will now show correct text -! Remove the messagebox on double clik on mail -* Change options dialog add dialog for status choose. - -0.0.0.13 -============ -+ Use of event count for the keyboard flashing - -0.0.0.12 -============ -- Remove message body retrieving due to bug. - -0.0.0.11 -============ -+ Add a function to retrieve the whole mail source. -+ Show the mail source when double clicking on it in mail browser. -+ Add a version resource. - -0.0.0.10 -============ -+ Now able to pass hContact handle to popup so can show avatar if set. -* Change folder structure in svn SDK\import replace by include - -0.0.0.9 -============ -+ Sorting asc and desc of the mail browser listview -+ Use the format yyyy-mm-dd hh:mm:ss for date comparaison in sorting -+ Doubleclick on list view to show the mail body but it seems to be empty :( - -0.0.0.8 -============ -+ Add date field in mail browser -* Modify the tooltip text for the clist event (add account name) -* Rename Contact member of CAccount by hContact since it is an HANDLE -+ Updater support for BETA -* Using the right headers (no more the one in SDK) - -0.0.0.7 -============ -+ Added changelog txt file. -+ Check presence of icolib to choose the right icon to show in clist -+ Status message will show all message pending in mail box (until they get retrieve by your email client) - -0.0.0.6 -============ -* Options page redesign. -+ Right click on popup close the clist event too. -+ Update status message if no new mail. -+ Right click on popup^with no new mail close the popup. -* No more delete of contact (avoid group affectation bug). - -0.0.0.5 -============ -+ Add contact context menu entry to check for new mail. -+ Catch double click event on contact to shown the mail browser. - -0.0.0.4 -============ -+ Add per account option to be show as contact or not. -+ Gestion de la suppression d'un compte -+ Use of the status message for showing number of emails. -+ Refresh yamn contact on the click on apply in options dialog. -* Better condition for the ^contact loop (ouuppsss) - -0.0.0.3 -============ -+ Now account are shown as a contact. -+ Source code modification and use of yamn.h -+ Wait the event moduleloaded before loading the icons (support icolib). - -0.0.0.2 -============ -+ Use of patch by Q (From file listing) (Memory cleaning, empty mail browser even if there are mails, yamn freeze sometime) -+ Use of thread access function. -+ Possibility to change toptoolbar icons via icolib. -+ Icon in main menu entry (Asked by a7) -+ New Icons set by Manudevil. -+ Change version number to be compatible with updater plugin - -0.01 -============ - -+ icolib support. -+ keyboard flash support (just 10 sec) (thx TioDuke) needs Keyboard Notify Ext. 1.5.4.4 -+ list of email can be sorted. -* left click on popup shows email list. -* better toptoolbar support. \ No newline at end of file diff --git a/protocols/YAMN/YAMN_10.vcxproj b/protocols/YAMN/YAMN_10.vcxproj index 92ae1576da..3f563a0435 100644 --- a/protocols/YAMN/YAMN_10.vcxproj +++ b/protocols/YAMN/YAMN_10.vcxproj @@ -178,46 +178,38 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + - - - - - - - - - - - - + + diff --git a/protocols/YAMN/YAMN_10.vcxproj.filters b/protocols/YAMN/YAMN_10.vcxproj.filters index 9ad0a75aab..9b91a6595f 100644 --- a/protocols/YAMN/YAMN_10.vcxproj.filters +++ b/protocols/YAMN/YAMN_10.vcxproj.filters @@ -23,108 +23,90 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files\Mail browser, dialogs - + Source Files\Mail browser, dialogs - + Source Files\Mails - + Source Files\Mails - + Source Files\Mails - + Source Files\POP3 plugin - + Source Files\POP3 plugin - + Source Files\POP3 plugin - + Source Files\POP3 plugin - + Source Files\POP3 plugin - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - - - + Resource Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + - + Resource Files - + Resource Files diff --git a/protocols/YAMN/YAMNopts.cpp b/protocols/YAMN/YAMNopts.cpp deleted file mode 100644 index 99a8091366..0000000000 --- a/protocols/YAMN/YAMNopts.cpp +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/protocols/YAMN/account.cpp b/protocols/YAMN/account.cpp deleted file mode 100644 index d1de8b8e4c..0000000000 --- a/protocols/YAMN/account.cpp +++ /dev/null @@ -1,1309 +0,0 @@ -/* - * This code implements manipulation with accounts - * such as reading accounts from file, writing them to file, - * finding account by name etc. - * - * (c) majvan 2002-2004 - */ - -#include "yamn.h" -#include "m_mails.h" -#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) || defined(DEBUG_SYNCHRO) - #include -#endif - -//Account status CS -//When we check some account, thread should change status of account to idle, connecting etc. -//So if we want to read status, we have to successfully write and then read. -CRITICAL_SECTION AccountStatusCS; - -//File Writing CS -//When 2 threads want to write to file... -CRITICAL_SECTION FileWritingCS; - -struct CExportedFunctions AccountExportedFcn[]= -{ - {YAMN_GETSTATUSID,(void *)GetStatusFcn}, - {YAMN_SETSTATUSID,(void *)SetStatusFcn}, -}; - -struct CExportedServices AccountExportedSvc[]= -{ - {MS_YAMN_CREATEPLUGINACCOUNT,CreatePluginAccountSvc}, - {MS_YAMN_DELETEPLUGINACCOUNT,DeletePluginAccountSvc}, - {MS_YAMN_FINDACCOUNTBYNAME,FindAccountByNameSvc}, - {MS_YAMN_GETNEXTFREEACCOUNT,GetNextFreeAccountSvc}, - {MS_YAMN_DELETEACCOUNT,DeletePluginAccountSvc}, - {MS_YAMN_READACCOUNTS,AddAccountsFromFileSvc}, - {MS_YAMN_WRITEACCOUNTS,WriteAccountsToFileSvc}, -}; - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -INT_PTR CreatePluginAccountSvc(WPARAM wParam,LPARAM lParam) -{ - HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; - DWORD AccountVersion=(DWORD)lParam; - HACCOUNT NewAccount; - -//test if we are going to initialize members of suitable structure (structures of plugin and YAMN must match) - if (AccountVersion!=YAMN_ACCOUNTVERSION) - return NULL; - - if (Plugin!=NULL) - { - if (Plugin->Fcn->NewAccountFcnPtr!=NULL) - { -//Let plugin create its own structure, which can be derived from CAccount structure - NewAccount=Plugin->Fcn->NewAccountFcnPtr(Plugin,YAMN_ACCOUNTVERSION); - NewAccount->Plugin=Plugin; - } - else - { -//We suggest plugin uses standard CAccount structure, so we create it - NewAccount=new struct CAccount; - NewAccount->Plugin=Plugin; - } -//If not created successfully - if (NewAccount==NULL) - return NULL; -//Init every members of structure, used by YAMN - InitAccount(NewAccount); - - return (INT_PTR)NewAccount; - } - return NULL; -} - -INT_PTR DeletePluginAccountSvc(WPARAM wParam,LPARAM) -{ - HACCOUNT OldAccount=(HACCOUNT)wParam; - - if (OldAccount->Plugin->Fcn!=NULL) - { -//Deinit every members and allocated fields of structure used by YAMN - DeInitAccount(OldAccount); - if (OldAccount->Plugin->Fcn->DeleteAccountFcnPtr!=NULL) - { -//Let plugin delete its own CAccount derived structure - OldAccount->Plugin->Fcn->DeleteAccountFcnPtr(OldAccount); - } - else - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeletePluginAccountSvc:delete OldAccount\n"); -#endif - delete OldAccount; //consider account as standard YAMN HACCOUNT and use its own destructor - } - return 1; - } - delete OldAccount; //consider account as standard YAMN HACCOUNT, not initialized before and use its own destructor - return 1; -} - -int InitAccount(HACCOUNT Which) -{ -//initialize synchronizing objects - Which->AccountAccessSO=new SWMRG; - SWMRGInitialize(Which->AccountAccessSO,NULL); - Which->MessagesAccessSO=new SWMRG; - SWMRGInitialize(Which->MessagesAccessSO,NULL); - Which->UsingThreads=new SCOUNTER; - SWMRGInitialize(Which->MessagesAccessSO,NULL); - -//zero memory, where timestamps are stored - ZeroMemory(&Which->LastChecked,sizeof(Which->LastChecked)); - ZeroMemory(&Which->LastSChecked,sizeof(Which->LastSChecked)); - ZeroMemory(&Which->LastSynchronised,sizeof(Which->LastSynchronised)); - ZeroMemory(&Which->LastMail,sizeof(Which->LastMail)); - - Which->Name=NULL; - Which->Mails=NULL; - Which->Interval=0; - Which->Flags=0; - Which->StatusFlags=0; - Which->Next=NULL; - - Which->Server=new struct CServer; - Which->AbleToWork=TRUE; - - return 1; -} - -void DeInitAccount(HACCOUNT Which) -{ -//delete YAMN allocated fields - if (Which->Name!=NULL) - delete[] Which->Name; - if (Which->Server->Name!=NULL) - delete[] Which->Server->Name; - if (Which->Server->Login!=NULL) - delete[] Which->Server->Login; - if (Which->Server->Passwd!=NULL) - delete[] Which->Server->Passwd; - if (Which->Server!=NULL) - delete[] Which->Server; - - SWMRGDelete(Which->AccountAccessSO); - delete Which->AccountAccessSO; - SWMRGDelete(Which->MessagesAccessSO); - delete Which->MessagesAccessSO; - delete Which->UsingThreads; - DeleteMessagesToEndFcn(Which,(HYAMNMAIL)Which->Mails); -} - -void StopSignalFcn(HACCOUNT Which) -//set event that we are going to delete account -{ -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tStopSignalFcn:stop account: %x\n",Which); -#endif - Which->AbleToWork=FALSE; -//do not use synchronizing objects anymore -//any access to these objects then ends with WAIT_FAILED - SetEvent(Which->AccountAccessSO->hFinishEV); - SetEvent(Which->MessagesAccessSO->hFinishEV); -} - -void CodeDecodeString(char *Dest,BOOL Encrypt) -{ - TCHAR Code=STARTCODEPSW; - - if (Dest==NULL) - return; - - for (;*Dest!=(TCHAR)0;Dest++) - { - if (Encrypt) - *Dest=*Dest+Code; - else - *Dest=*Dest-Code; - Code+=(TCHAR)ADDCODEPSW; - } -} - -static DWORD PostFileToMemory(HANDLE File,char **MemFile,char **End) -{ - DWORD FileSize,ReadBytes; - if (!(FileSize=GetFileSize(File,NULL))) { - CloseHandle(File); - return EACC_FILESIZE; - } - - //allocate space in memory, where we copy the whole file - if (NULL==(*MemFile = new char[FileSize])) - { - CloseHandle(File); - return EACC_ALLOC; - } - - //copy file to memory - if (!ReadFile(File,(LPVOID)*MemFile,FileSize,&ReadBytes,NULL)) - { - CloseHandle(File); - delete[] *MemFile; - return EACC_SYSTEM; - } - CloseHandle(File); - *End = *MemFile + FileSize; - return 0; -} - -DWORD FileToMemory(TCHAR *FileName,char **MemFile,char **End) -{ - HANDLE hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) - return EACC_SYSTEM; - - return PostFileToMemory(hFile, MemFile, End); -} - -#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) -DWORD ReadStringFromMemory(char **Parser,TCHAR *End,char **StoreTo,TCHAR *DebugString) -{ -//This is the debug version of ReadStringFromMemory function. This version shows MessageBox where -//read string is displayed - TCHAR *Dest,*Finder; - DWORD Size; - TCHAR Debug[65536]; - - Finder=*Parser; - while((*Finder!=(TCHAR)0) && (Finder<=End)) Finder++; - _stprintf(Debug,_T("%s: %s,length is %d, remaining %d chars"),DebugString,*Parser,Finder-*Parser,End-Finder); - MessageBox(NULL,Debug,_T("debug"),MB_OK); - if (Finder>=End) - return EACC_FILECOMPATIBILITY; - if (Size=Finder-*Parser) - { - if (NULL==(Dest=*StoreTo=new TCHAR[Size+1])) - return EACC_ALLOC; - for (;*Parser<=Finder;(*Parser)++,Dest++) - *Dest=**Parser; - } - else - { - *StoreTo=NULL; - (*Parser)++; - } - return 0; -} -#endif - -DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo) -{ - char *Dest,*Finder; - DWORD Size; - - Finder=*Parser; - while((*Finder!=(TCHAR)0) && (Finder<=End)) Finder++; - if (Finder>=End) - return EACC_FILECOMPATIBILITY; - if (Size=Finder-*Parser) - { - if (NULL==(Dest=*StoreTo=new char[Size+1])) - return EACC_ALLOC; - for (;*Parser<=Finder;(*Parser)++,Dest++) - *Dest=**Parser; - } - else - { - *StoreTo=NULL; - (*Parser)++; - } - return 0; -} - - #if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) -DWORD ReadStringFromMemoryW(WCHAR **Parser,TCHAR *End,WCHAR **StoreTo,WCHAR *DebugString) -{ -//This is the debug version of ReadStringFromMemoryW function. This version shows MessageBox where -//read string is displayed - WCHAR *Dest,*Finder; - DWORD Size; - WCHAR Debug[65536]; - - Finder=*Parser; - while((*Finder!=(WCHAR)0) && (Finder<=(WCHAR *)End)) Finder++; - swprintf(Debug,L"%s: %s,length is %d, remaining %d chars",DebugString,*Parser,Finder-*Parser,(WCHAR *)End-Finder); - MessageBoxW(NULL,Debug,L"debug",MB_OK); - if (Finder>=(WCHAR *)End) - return EACC_FILECOMPATIBILITY; - if (Size=Finder-*Parser) - { - if (NULL==(Dest=*StoreTo=new WCHAR[Size+1])) - return EACC_ALLOC; - for (;*Parser<=Finder;(*Parser)++,Dest++) - *Dest=**Parser; - } - else - { - *StoreTo=NULL; - (*Parser)++; - } - return 0; -} - #endif //if defined(DEBUG...) - -DWORD ReadStringFromMemoryW(WCHAR **Parser,WCHAR *End,WCHAR **StoreTo) -{ - WCHAR *Dest,*Finder; - DWORD Size; - - Finder=*Parser; - while((*Finder!=(WCHAR)0) && (Finder<=(WCHAR *)End)) Finder++; - if (Finder>=(WCHAR *)End) - return EACC_FILECOMPATIBILITY; - if (Size=Finder-*Parser) - { - if (NULL==(Dest=*StoreTo=new WCHAR[Size+1])) - return EACC_ALLOC; - for (;*Parser<=Finder;(*Parser)++,Dest++) - *Dest=**Parser; - } - else - { - *StoreTo=NULL; - (*Parser)++; - } - return 0; -} - -static DWORD ReadNotificationFromMemory(char **Parser,char *End,YAMN_NOTIFICATION *Which) -{ - DWORD Stat; -#ifdef DEBUG_FILEREAD - TCHAR Debug[65536]; -#endif - - Which->Flags=*(DWORD *)(*Parser); - (*Parser)+=sizeof(DWORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("NFlags: %04x, remaining %d chars"),Which->Flags,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - - Which->PopUpB=*(COLORREF *)(*Parser); - (*Parser)+=sizeof(COLORREF); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("PopUpB: %04x, remaining %d chars"),Which->PopUpB,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - Which->PopUpT=*(COLORREF *)(*Parser); - (*Parser)+=sizeof(COLORREF); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("PopUpT: %04x, remaining %d chars"),Which->PopUpT,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - Which->PopUpTime=*(DWORD *)(*Parser); - (*Parser)+=sizeof(DWORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("PopUpTime: %04x, remaining %d chars"),Which->PopUpTime,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemoryW((WCHAR **)Parser,(WCHAR*)End,&Which->App,L"App")) -#else - if (Stat=ReadStringFromMemoryW((WCHAR **)Parser,(WCHAR*)End,&Which->App)) -#endif - return Stat; -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemoryW((WCHAR **)Parser,(WCHAR*)End,&Which->AppParam,L"AppParam")) -#else - if (Stat=ReadStringFromMemoryW((WCHAR **)Parser,(WCHAR*)End,&Which->AppParam)) -#endif - return Stat; - return 0; -} - -DWORD ReadMessagesFromMemory(HACCOUNT Which,char **Parser,char *End) -{ - char *Finder; - DWORD Size,Stat; - HYAMNMAIL ActualMail=NULL; - struct CMimeItem *items; - char *ReadString; - -#ifdef DEBUG_FILEREAD - MessageBox(NULL,_T("going to read messages, if any..."),_T("debug"),MB_OK); -#endif - do - { - Finder=*Parser; - while((*Finder!=(TCHAR)0) && (Finder<=End)) Finder++; - if (Finder>=End) - return EACC_FILECOMPATIBILITY; - if (Size=Finder-*Parser) - { - if (Which->Mails==NULL) //First message in queue - { - if (NULL==(Which->Mails=ActualMail=CreateAccountMail(Which))) - return EACC_ALLOC; - } - else - { - if (NULL==(ActualMail->Next=CreateAccountMail(Which))) { - return EACC_ALLOC; - } - ActualMail=ActualMail->Next; - } - items=NULL; -#ifdef DEBUG_FILEREADMESSAGES - if (Stat=ReadStringFromMemory(Parser,End,&ActualMail->ID,_T("ID"))) -#else - if (Stat=ReadStringFromMemory(Parser,End,&ActualMail->ID)) -#endif - return Stat; -// ActualMail->MailData=new MAILDATA; !!! mem leake !!! this is alloc by CreateAccountMail, no need for doubble alloc !!!! - - ActualMail->MailData->Size=*(DWORD *)(*Parser); - (*Parser)+=sizeof(DWORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; - ActualMail->Flags=*(DWORD *)(*Parser); - (*Parser)+=sizeof(DWORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; - ActualMail->Number=*(DWORD *)(*Parser); - (*Parser)+=sizeof(DWORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; - - if ((NULL!=Which->Plugin->MailFcn) && (NULL!=Which->Plugin->MailFcn->ReadMailOptsFcnPtr)) - Which->Plugin->MailFcn->ReadMailOptsFcnPtr(ActualMail,Parser,End); //read plugin mail settings from file - - do - { -#if defined(DEBUG_FILEREADMESSAGES) || defined(DEBUG_FILEREAD) - if (Stat=ReadStringFromMemory(Parser,End,&ReadString,_T("Name"))) -#else - if (Stat=ReadStringFromMemory(Parser,End,&ReadString)) -#endif - return Stat; - if (ReadString==NULL) - break; - -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%s",ReadString); -#endif - - if (items==NULL) - items=ActualMail->MailData->TranslatedHeader=new struct CMimeItem; - else - { - items->Next=new struct CMimeItem; - items=items->Next; - } - if (items==NULL) - return EACC_ALLOC; - items->name=ReadString; - -#ifdef DEBUG_FILEREADMESSAGES - if (Stat=ReadStringFromMemory(Parser,End,&ReadString,_T("Value"))) -#else - if (Stat=ReadStringFromMemory(Parser,End,&ReadString)) -#endif - return Stat; - items->value=ReadString; -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%s\n",ReadString); -#endif - }while(1); - } - else - break; //no next messages, new account! - - }while(1); - (*Parser)++; - return 0; -} - -DWORD ReadAccountFromMemory(HACCOUNT Which,char **Parser,char *End) -{ - DWORD Stat; -#ifdef DEBUG_FILEREAD - TCHAR Debug[65536]; -#endif - //Read name of account - -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemory(Parser,End,&Which->Name,_T("Name"))) -#else - if (Stat=ReadStringFromMemory(Parser,End,&Which->Name)) -#endif - return Stat; - if (Which->Name==NULL) - return EACC_FILECOMPATIBILITY; - - //Read server parameters -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Name,_T("Server"))) -#else - if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Name)) -#endif - return Stat; - Which->Server->Port=*(WORD *)(*Parser); - (*Parser)+=sizeof(WORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("Port: %d, remaining %d chars"),Which->Server->Port,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Login,_T("Login"))) -#else - if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Login)) -#endif - return Stat; -#ifdef DEBUG_FILEREAD - if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Passwd,_T("Password"))) -#else - if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Passwd)) -#endif - return Stat; - CodeDecodeString(Which->Server->Passwd,FALSE); - - //Read account flags - Which->Flags=*(DWORD *)(*Parser); - (*Parser)+=sizeof(DWORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("Flags: %04x, remaining %d chars"),Which->Flags,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - Which->StatusFlags=*(DWORD *)(*Parser); - (*Parser)+=sizeof(DWORD); -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("STFlags: %04x, remaining %d chars"),Which->StatusFlags,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - Which->PluginFlags=*(DWORD *)(*Parser); - (*Parser)+=sizeof(DWORD); -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("PFlags: %04x, remaining %d chars"),Which->PluginFlags,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - - //Read account miscellaneous parameters - Which->Interval=*(WORD *)(*Parser); - Which->TimeLeft=Which->Interval; //check on loading - (*Parser)+=sizeof(WORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("Interval: %d, remaining %d chars"),Which->Interval,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - - //Read notification parameters - if (Stat=ReadNotificationFromMemory(Parser,End,&Which->NewMailN)) - return Stat; - if (Stat=ReadNotificationFromMemory(Parser,End,&Which->NoNewMailN)) - return Stat; - if (Stat=ReadNotificationFromMemory(Parser,End,&Which->BadConnectN)) - return Stat; - - //Let plugin read its own data stored in file - if (Which->Plugin->Fcn!=NULL && Which->Plugin->Fcn->ReadPluginOptsFcnPtr!=NULL) - if (Stat=Which->Plugin->Fcn->ReadPluginOptsFcnPtr(Which,Parser,End)) - return Stat; - //Read mails -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write wait\n"); -#endif - WaitToWriteFcn(Which->MessagesAccessSO); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write enter\n"); -#endif - if (Stat=ReadMessagesFromMemory(Which,Parser,End)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write done\n"); -#endif - WriteDoneFcn(Which->MessagesAccessSO); - return Stat; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write done\n"); -#endif - WriteDoneFcn(Which->MessagesAccessSO); - - //Read timestamps - Which->LastChecked=*(SYSTEMTIME *)(*Parser); - (*Parser)+=sizeof(SYSTEMTIME); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("LastChecked: %04x, remaining %d chars"),Which->LastChecked,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - Which->LastSChecked=*(SYSTEMTIME *)(*Parser); - (*Parser)+=sizeof(SYSTEMTIME); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("LastSChecked: %04x, remaining %d chars"),Which->LastSChecked,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - Which->LastSynchronised=*(SYSTEMTIME *)(*Parser); - (*Parser)+=sizeof(SYSTEMTIME); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("LastSynchronised: %04x, remaining %d chars"),Which->LastSynchronised,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - Which->LastMail=*(SYSTEMTIME *)(*Parser); - (*Parser)+=sizeof(SYSTEMTIME); - if (*Parser>End) //WARNING! There's only > at the end of testing - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("LastMail: %04x, remaining %d chars"),Which->LastMail,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - if (*Parser==End) - return EACC_ENDOFFILE; - return 0; - -} - -static INT_PTR PerformAccountReading(HYAMNPROTOPLUGIN Plugin,char *MemFile,char *End) -{ - //Retrieve info for account from memory - char *Parser; - DWORD Ver,Stat; - - HACCOUNT ActualAccount,FirstAllocatedAccount; - - Ver=*(DWORD *)MemFile; - if (Ver>YAMN_ACCOUNTFILEVERSION) - { - delete[] MemFile; - return EACC_FILEVERSION; - } - Parser=MemFile+sizeof(Ver); - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write wait\n"); -#endif - SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write enter\n"); -#endif - if (NULL==(ActualAccount=(HACCOUNT)CallService(MS_YAMN_GETNEXTFREEACCOUNT,(WPARAM)Plugin,(LPARAM)YAMN_ACCOUNTVERSION))) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n"); -#endif - SWMRGDoneWriting(Plugin->AccountBrowserSO); - delete[] MemFile; - return EACC_ALLOC; - } - FirstAllocatedAccount=ActualAccount; - - do - { - HACCOUNT Temp; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write wait\n"); -#endif - WaitToWriteFcn(ActualAccount->AccountAccessSO); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write enter\n"); -#endif - Stat=ReadAccountFromMemory(ActualAccount,&Parser,End); - - if (ActualAccount->StatusFlags & (YAMN_ACC_STARTA | YAMN_ACC_STARTS)) - ActualAccount->TimeLeft=1; //check on loading - - if (Stat && (Stat!=EACC_ENDOFFILE)) - { - for (ActualAccount=FirstAllocatedAccount;ActualAccount!=NULL;ActualAccount=Temp) - { - Temp=ActualAccount->Next; - delete ActualAccount; - } - delete[] MemFile; - if (Plugin->FirstAccount==FirstAllocatedAccount) - Plugin->FirstAccount=NULL; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write done\n"); -#endif - SWMRGDoneWriting(Plugin->AccountBrowserSO); - return (INT_PTR)Stat; - } - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write done\n"); -#endif - WriteDoneFcn(ActualAccount->AccountAccessSO); - - if ((Stat!=EACC_ENDOFFILE) && (NULL==(ActualAccount=(HACCOUNT)CallService(MS_YAMN_GETNEXTFREEACCOUNT,(WPARAM)Plugin,(LPARAM)YAMN_ACCOUNTVERSION)))) - { - for (ActualAccount=FirstAllocatedAccount;ActualAccount!=NULL;ActualAccount=Temp) - { - Temp=ActualAccount->Next; - delete ActualAccount; - } - delete[] MemFile; - if (Plugin->FirstAccount==FirstAllocatedAccount) - Plugin->FirstAccount=NULL; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n"); -#endif - SWMRGDoneWriting(Plugin->AccountBrowserSO); - return EACC_ALLOC; - } - }while(Stat!=EACC_ENDOFFILE); - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n"); -#endif - SWMRGDoneWriting(Plugin->AccountBrowserSO); - delete[] MemFile; - - return 0; -} - -// Add accounts from file to memory -INT_PTR AddAccountsFromFileSvc(WPARAM wParam,LPARAM lParam) -{ - char *MemFile,*End; - DWORD Stat = FileToMemory(( TCHAR* )lParam, &MemFile, &End); - if ( Stat != NO_ERROR ) - return (INT_PTR)Stat; - - return PerformAccountReading((HYAMNPROTOPLUGIN)wParam,MemFile,End); -} - -DWORD WriteStringToFile(HANDLE File,char *Source) -{ - DWORD Length,WrittenBytes; - char null = 0; - - if ((Source==NULL) || !(Length=(DWORD)strlen(Source))) { - if (!WriteFile(File,&null,1,&WrittenBytes,NULL)) { - CloseHandle(File); - return EACC_SYSTEM; - } - } - else if (!WriteFile(File,Source,(Length+1),&WrittenBytes,NULL)) { - CloseHandle(File); - return EACC_SYSTEM; - } - return 0; -} - -DWORD WriteStringToFileW(HANDLE File,WCHAR *Source) -{ - DWORD Length,WrittenBytes; - WCHAR null=(WCHAR)0; - - if ((Source==NULL) || !(Length=(DWORD)wcslen(Source))) - { - if (!WriteFile(File,&null,sizeof(WCHAR),&WrittenBytes,NULL)) - { - CloseHandle(File); - return EACC_SYSTEM; - } - } - else if (!WriteFile(File,Source,(Length+1)*sizeof(WCHAR),&WrittenBytes,NULL)) - return EACC_SYSTEM; - return 0; -} - -DWORD WriteMessagesToFile(HANDLE File,HACCOUNT Which) -{ - DWORD WrittenBytes,Stat; - HYAMNMAIL ActualMail=(HYAMNMAIL)Which->Mails; - struct CMimeItem *items; - - while(ActualMail!=NULL) - { - if (Stat=WriteStringToFile(File,ActualMail->ID)) - return Stat; - if (!WriteFile(File,(char *)&ActualMail->MailData->Size,sizeof(ActualMail->MailData->Size),&WrittenBytes,NULL) || - !WriteFile(File,(char *)&ActualMail->Flags,sizeof(ActualMail->Flags),&WrittenBytes,NULL) || - !WriteFile(File,(char *)&ActualMail->Number,sizeof(ActualMail->Number),&WrittenBytes,NULL)) - return EACC_SYSTEM; - if ((NULL!=Which->Plugin->MailFcn) && (NULL!=Which->Plugin->MailFcn->WriteMailOptsFcnPtr)) - Which->Plugin->MailFcn->WriteMailOptsFcnPtr(File,ActualMail); //write plugin mail options to file - for (items=ActualMail->MailData->TranslatedHeader;items!=NULL;items=items->Next) - { - if (Stat=WriteStringToFile(File,items->name)) - return Stat; - if (Stat=WriteStringToFile(File,items->value)) - return Stat; - } - if (Stat=WriteStringToFile(File,"")) - return Stat; - ActualMail=ActualMail->Next; - } - if (Stat=WriteStringToFile(File,"")) - return Stat; - return 0; -} - -static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin,HANDLE File) -{ - DWORD WrittenBytes,Stat; - HACCOUNT ActualAccount; - DWORD Ver=YAMN_ACCOUNTFILEVERSION; - BOOL Writed=FALSE; - DWORD ReturnValue=0,EnterCode; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read wait\n"); -#endif - SWMRGWaitToRead(Plugin->AccountBrowserSO,INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read enter\n"); -#endif - try - { - for (ActualAccount=Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=ActualAccount->Next) - { -/* TCHAR DEBUG[100]; - Beep(3000,100);Sleep(200); - _stprintf(DEBUG,_T("Browsing account %s"),ActualAccount->Name==NULL ? _T("(null)") : ActualAccount->Name); - MessageBox(NULL,DEBUG,_T("debug- WriteAccount..."),MB_OK); -*/ -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait\n"); -#endif - EnterCode=WaitToReadFcn(ActualAccount->AccountAccessSO); - if (EnterCode==WAIT_FINISH) //account is about to delete - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait failed\n"); -#endif - ActualAccount=ActualAccount->Next; - continue; - } - if (EnterCode==WAIT_FAILED) //account is deleted - break; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read enter\n"); -#endif - if ((ActualAccount->Name==NULL) || (*ActualAccount->Name==(TCHAR)0)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); -#endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - continue; - } - - if (!Writed && !WriteFile(File,&Ver,sizeof(Ver),&WrittenBytes,NULL)) - throw (DWORD)EACC_SYSTEM; - Writed=TRUE; - - if (Stat=WriteStringToFile(File,ActualAccount->Name)) - throw (DWORD)Stat; - - if (Stat=WriteStringToFile(File,ActualAccount->Server->Name)) - throw (DWORD)Stat; - - if (!WriteFile(File,(char *)&ActualAccount->Server->Port,2,&WrittenBytes,NULL)) - throw (DWORD)EACC_SYSTEM; - - if ((Stat=WriteStringToFile(File,ActualAccount->Server->Login))) - throw (DWORD)Stat; - - CodeDecodeString(ActualAccount->Server->Passwd,TRUE); - - if (Stat=WriteStringToFile(File,ActualAccount->Server->Passwd)) - { - CodeDecodeString(ActualAccount->Server->Passwd,FALSE); - throw (DWORD)Stat; - } - CodeDecodeString(ActualAccount->Server->Passwd,FALSE); - - if ((!WriteFile(File,(char *)&ActualAccount->Flags,sizeof(DWORD),&WrittenBytes,NULL) || - (!WriteFile(File,(char *)&ActualAccount->StatusFlags,sizeof(DWORD),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->PluginFlags,sizeof(DWORD),&WrittenBytes,NULL)))) - throw (DWORD)EACC_SYSTEM; - - if (!WriteFile(File,(char *)&ActualAccount->Interval,sizeof(WORD),&WrittenBytes,NULL)) - throw (DWORD)EACC_SYSTEM; - - if ((!WriteFile(File,(char *)&ActualAccount->NewMailN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopUpB,sizeof(COLORREF),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopUpT,sizeof(COLORREF),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopUpTime,sizeof(DWORD),&WrittenBytes,NULL))) - throw (DWORD)EACC_SYSTEM; - - if ((Stat=WriteStringToFileW(File,ActualAccount->NewMailN.App)) || - (Stat=WriteStringToFileW(File,ActualAccount->NewMailN.AppParam))) - throw (DWORD)Stat; - - if ((!WriteFile(File,(char *)&ActualAccount->NoNewMailN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopUpB,sizeof(COLORREF),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopUpT,sizeof(COLORREF),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopUpTime,sizeof(DWORD),&WrittenBytes,NULL))) - throw (DWORD)EACC_SYSTEM; - - if ((Stat=WriteStringToFileW(File,ActualAccount->NoNewMailN.App)) || - (Stat=WriteStringToFileW(File,ActualAccount->NoNewMailN.AppParam))) - throw (DWORD)Stat; - - if ((!WriteFile(File,(char *)&ActualAccount->BadConnectN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopUpB,sizeof(COLORREF),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopUpT,sizeof(COLORREF),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopUpTime,sizeof(DWORD),&WrittenBytes,NULL))) - throw (DWORD)EACC_SYSTEM; - - if ((Stat=WriteStringToFileW(File,ActualAccount->BadConnectN.App)) || - (Stat=WriteStringToFileW(File,ActualAccount->BadConnectN.AppParam))) - throw (DWORD)Stat; - -//Let plugin write its own values into file - if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr!=NULL) - if (Stat=ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr(File,ActualAccount)) - throw (DWORD)Stat; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read wait\n"); -#endif - WaitToReadFcn(ActualAccount->MessagesAccessSO); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read enter\n"); -#endif - if (Stat=WriteMessagesToFile(File,ActualAccount)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n"); -#endif - ReadDoneFcn(ActualAccount->MessagesAccessSO); - throw (DWORD)Stat; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n"); -#endif - ReadDoneFcn(ActualAccount->MessagesAccessSO); - - if ((!WriteFile(File,(char *)&ActualAccount->LastChecked,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->LastSChecked,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->LastSynchronised,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&ActualAccount->LastMail,sizeof(SYSTEMTIME),&WrittenBytes,NULL))) - throw (DWORD)Stat; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); -#endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - } - } - catch(DWORD ErrorCode) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); -#endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - ReturnValue=ErrorCode; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read done\n"); -#endif - SWMRGDoneReading(Plugin->AccountBrowserSO); - CloseHandle(File); - return 0; -} - -//Writes accounts to file -INT_PTR WriteAccountsToFileSvc(WPARAM wParam,LPARAM lParam) -{ - HYAMNPROTOPLUGIN Plugin = ( HYAMNPROTOPLUGIN )wParam; - TCHAR* tszFileName = ( TCHAR* )lParam; - - EnterCriticalSection( &FileWritingCS ); - HANDLE hFile = CreateFile(tszFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); - if ( hFile == INVALID_HANDLE_VALUE ) { - LeaveCriticalSection(&FileWritingCS); - return EACC_SYSTEM; - } - - INT_PTR rv = PerformAccountWriting(Plugin, hFile); - LeaveCriticalSection(&FileWritingCS); - - return rv; -} - -INT_PTR FindAccountByNameSvc(WPARAM wParam,LPARAM lParam) -{ - HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; - char *SearchedAccount=(char *)lParam; - HACCOUNT Finder; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read wait\n"); -#endif - SWMRGWaitToRead(Plugin->AccountBrowserSO,INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read enter\n"); -#endif - for (Finder=Plugin->FirstAccount;Finder!=NULL;Finder=Finder->Next) - if ((Finder->Name!=NULL) && (0 == strcmp(SearchedAccount,Finder->Name))) - break; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read done\n"); -#endif - SWMRGDoneReading(Plugin->AccountBrowserSO); - return (INT_PTR)Finder; -} - -INT_PTR GetNextFreeAccountSvc(WPARAM wParam,LPARAM lParam) -{ - HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; - HACCOUNT Finder; - - if (Plugin->FirstAccount==NULL) - { - Plugin->FirstAccount=(HACCOUNT)CallService(MS_YAMN_CREATEPLUGINACCOUNT,wParam,lParam); - return (INT_PTR)Plugin->FirstAccount; - } - for (Finder=Plugin->FirstAccount;Finder->Next!=NULL;Finder=Finder->Next); - Finder->Next=(HACCOUNT)CallService(MS_YAMN_CREATEPLUGINACCOUNT,wParam,lParam); - return (INT_PTR)Finder->Next; -} - -/* -int FindPluginAccount(WPARAM wParam,LPARAM lParam) -{ - HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; - HACCOUNT Finder=(HACCOUNT)lParam; - - if (Finder=NULL) Finder=Plugin->FirstAccount; - -// for (;Finder!=NULL && Finder->PluginID!=Plugin->PluginInfo->PluginID;Finder=(HACCOUNT)Finder->Next); - return (int)Finder; -} -*/ -INT_PTR DeleteAccountSvc(WPARAM wParam,LPARAM lParam) -{ -//Deleting account works on these steps: -//1. set signal that account should stop activity (set event) -// setting this event we achieve, that any access to account is failed, -// so threads do not start any work with accounts (better saying threads of plugins should not start) -//2. wait to get write access to chained list of accounts -//3. we can write to chained list, so we change chain not to show to actual account -// now, any thread browsing list of accounts does not browse through actual account -// actual account seems to be hidden (it exists, but it is not in accounts chained list (chained list=queue)) -//Now, we should delete account from memory, BUT!!! -// Any thread can still be waked up and start asking account synchronizing object -// If account is deleted, asking about access to read account can throw memory exception (reading for -// a synchronizing object from memory, that was deleted) -//So, we cannot now delete account. We have to wait until we are sure no thread will be using account anymore -// (or to the end of Miranda, but problem is in allocated memory- it is allocated and Miranda is SMALLER, faster, easier, isn't it?) -// This deleting is achieved in 2 ways: -// We have event in UsingThreads synchronization objects. This event signals that no thread will use actual account -// 1. Any thread using account first increment UsingThread, so we know that account is used -// 2. If thread is about to close, it should decrement UsingThread -// 3. If thread creates another thread, that will use account, caller has to wait until the new thread does not -// increment UsingThreads (imagine that caller ends before the new thread set it: if no other thread is using -// account, account is automaticaly (decreasing UsingThreads) signaled as "not used" and we delete it. But then -// new thread is going to read account...). -//4. wait until UsingThread Event is signaled -//5. delete account from memory - - HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; - HACCOUNT Which=(HACCOUNT)lParam; - HACCOUNT Finder; - DWORD tid; - -//1. set stop signal - StopSignalFcn(Which); - WindowList_BroadcastAsync(YAMNVar.MessageWnds,WM_YAMN_STOPACCOUNT,(WPARAM)Which,(LPARAM)0); - if (Plugin->Fcn->StopAccountFcnPtr!=NULL) - Plugin->Fcn->StopAccountFcnPtr(Which); - -//2. wait to get write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write wait\n"); -#endif - SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write enter\n"); -#endif - -//3. remove from queue (chained list) - if (Plugin->FirstAccount==NULL) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write done\n"); -#endif - SWMRGDoneWriting(Plugin->AccountBrowserSO); - return 0; - } - if (Plugin->FirstAccount==Which) - { - Finder=Plugin->FirstAccount->Next; - Plugin->FirstAccount=Finder; - } - else - { - for (Finder=Plugin->FirstAccount;Which!=Finder->Next;Finder=Finder->Next); - Finder->Next=Finder->Next->Next; - } -//leave write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write done\n"); -#endif - SWMRGDoneWriting(Plugin->AccountBrowserSO); - -//4. wait while event "UsingThread" is not signaled -// And what to do, if this event will be signaled in 1 hour? (Although it's paranoia, because we have sent "delete signal", so -// other threads do not start any new work with actual account) We will wait in blocked state? -// No, of course not. We will create new thread, that will wait and additionally remove our thread in background. -//5. So, the last point (deleting from memory) is performed in new DeleteAccountInBackground thread - - if ((Plugin->Fcn!=NULL) && (Plugin->Fcn->WriteAccountsFcnPtr!=NULL)) - Plugin->Fcn->WriteAccountsFcnPtr(); - CloseHandle(CreateThread(NULL,0,DeleteAccountInBackground,(LPVOID)Which,0,&tid)); - -//Now, plugin can consider account as deleted, but plugin really can achieve deleting this account from memory when using -//event UsingThreads. - return 1; -} - -DWORD WINAPI DeleteAccountInBackground(LPVOID Value) -{ - HACCOUNT Which=(HACCOUNT)Value; - WaitForSingleObject(Which->UsingThreads->Event,INFINITE); - CallService(MS_YAMN_DELETEPLUGINACCOUNT,(WPARAM)Which,(LPARAM)0); - return 0; -} - -int StopAccounts(HYAMNPROTOPLUGIN Plugin) -{ - HACCOUNT Finder; - -//1. wait to get write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write wait\n"); -#endif - SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write enter\n"); -#endif - for (Finder=Plugin->FirstAccount;Finder!=NULL;Finder=Finder->Next) - { -//2. set stop signal - StopSignalFcn(Finder); - WindowList_BroadcastAsync(YAMNVar.MessageWnds,WM_YAMN_STOPACCOUNT,(WPARAM)Finder,(LPARAM)0); - if (Plugin->Fcn->StopAccountFcnPtr!=NULL) - Plugin->Fcn->StopAccountFcnPtr(Finder); - } - -//leave write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write done\n"); -#endif - SWMRGDoneWriting(Plugin->AccountBrowserSO); - -//Now, account is stopped. It can be removed from memory... - return 1; -} - -int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin,BOOL GetAccountBrowserAccess) -{ - HACCOUNT Finder; - - if (GetAccountBrowserAccess) - { -//1. wait to get write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write wait\n"); -#endif - SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write enter\n"); -#endif - } - for (Finder=Plugin->FirstAccount;Finder!=NULL;Finder=Finder->Next) - { -//2. wait for signal that account is not in use -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:waiting for UsingThreadEV %x (account %x)\n",Finder->UsingThreads,Finder); -#endif - WaitForSingleObject(Finder->UsingThreads->Event,INFINITE); - SetEvent(Finder->UsingThreads->Event); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:UsingThreadEV signaled\n"); -#endif - } - if (GetAccountBrowserAccess) - { -//leave write access -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write done\n"); -#endif - SWMRGDoneWriting(Plugin->AccountBrowserSO); - } - - return 1; -} - -int DeleteAccounts(HYAMNPROTOPLUGIN Plugin) -{ - HACCOUNT Finder; - - //1. wait to get write access - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write wait\n"); - #endif - SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write enter\n"); - #endif - - WaitForAllAccounts(Plugin,FALSE); - - for (Finder=Plugin->FirstAccount;Finder!=NULL;) - { - HACCOUNT Next = Finder->Next; - DeletePluginAccountSvc((WPARAM)Finder,(LPARAM)0); - Finder = Next; - } - - //leave write access - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write done\n"); - #endif - SWMRGDoneWriting(Plugin->AccountBrowserSO); - - return 1; -} - -void WINAPI GetStatusFcn(HACCOUNT Which,TCHAR *Value) -{ - if (Which==NULL) - return; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetStatus:AccountStatusCS-cs wait\n"); -#endif - EnterCriticalSection(&AccountStatusCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetStatus:AccountStatusCS-cs enter\n"); -#endif - lstrcpy(Value,Which->Status); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetStatus:AccountStatusCS-cs done\n"); -#endif - LeaveCriticalSection(&AccountStatusCS); - return; -} - -void WINAPI SetStatusFcn(HACCOUNT Which,TCHAR *Value) -{ - if (Which==NULL) - return; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSetStatus:AccountStatusCS-cs wait\n"); -#endif - EnterCriticalSection(&AccountStatusCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSetStatus:AccountStatusCS-cs enter\n"); -#endif - lstrcpy(Which->Status,Value); - WindowList_BroadcastAsync(YAMNVar.MessageWnds,WM_YAMN_CHANGESTATUS,(WPARAM)Which,(LPARAM)0); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSetStatus:AccountStatusCS-cs done\n"); -#endif - LeaveCriticalSection(&AccountStatusCS); -} - -/* -#ifdef DEBUG_ACCOUNTS -int GetAccounts() -{ - HACCOUNT Finder; - int cnt=0; - - for (Finder=Account;Finder!=NULL;Finder=Finder->Next) - cnt++; - return cnt; -} - -void WriteAccounts() -{ - HACCOUNT Finder; - - for (Finder=Account;Finder!=NULL;Finder=Finder->Next) - MessageBoxA(NULL,Finder->Name,"Browsing account",MB_OK); -} -#endif -*/ diff --git a/protocols/YAMN/browser/badconnect.cpp b/protocols/YAMN/browser/badconnect.cpp deleted file mode 100644 index 785508d066..0000000000 --- a/protocols/YAMN/browser/badconnect.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* - * This code implements window handling (connection error) - * - * (c) majvan 2002,2004 - */ - -#include "../yamn.h" -#include "../main.h" - -#define BADCONNECTTITLE "%s - connection error" -#define BADCONNECTMSG "An error occured. Error code: %d" - -//-------------------------------------------------------------------------------------------------- - -LRESULT CALLBACK BadConnectPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) -{ - DWORD PluginParam; - switch(msg) - { - case WM_COMMAND: - if ((HIWORD(wParam)==STN_CLICKED) && (CallService(MS_POPUP_GETPLUGINDATA,(WPARAM)hWnd,(LPARAM)&PluginParam))) //if clicked and it's new mail popup window - { - PROCESS_INFORMATION pi; - STARTUPINFOW si; - HACCOUNT ActualAccount; - - ZeroMemory(&si,sizeof(si)); - si.cb=sizeof(si); - ActualAccount=(HACCOUNT)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read wait\n"); -#endif - if (WAIT_OBJECT_0==WaitToReadFcn(ActualAccount->AccountAccessSO)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter\n"); -#endif - if (ActualAccount->BadConnectN.App!=NULL) - { - WCHAR *Command; - if (ActualAccount->BadConnectN.AppParam!=NULL) - Command=new WCHAR[wcslen(ActualAccount->BadConnectN.App)+wcslen(ActualAccount->BadConnectN.AppParam)+6]; - else - Command=new WCHAR[wcslen(ActualAccount->BadConnectN.App)+6]; - - if (Command!=NULL) - { - lstrcpyW(Command,L"\""); - lstrcatW(Command,ActualAccount->BadConnectN.App); - lstrcatW(Command,L"\" "); - if (ActualAccount->BadConnectN.AppParam!=NULL) - lstrcatW(Command,ActualAccount->BadConnectN.AppParam); - CreateProcessW(NULL,Command,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); - delete[] Command; - } - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read done\n"); -#endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - } -#ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter failed\n"); -#endif - SendMessage(hWnd,UM_DESTROYPOPUP,0,0); - } - break; - case UM_FREEPLUGINDATA: - //Here we'd free our own data, if we had it. - return FALSE; - case UM_INITPOPUP: - //This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups. - break; - case WM_CONTEXTMENU: - SendMessage(hWnd,UM_DESTROYPOPUP,0,0); - break; - case WM_NOTIFY: -/* switch(((LPNMHDR)lParam)->code) - { - case NM_CLICK: - { - } - } - break; -*/ default: - break; - } - return DefWindowProc(hWnd,msg,wParam,lParam); -} - -INT_PTR CALLBACK DlgProcYAMNBadConnection(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - switch(msg) - { - case WM_INITDIALOG: - { - BOOL ShowPopUp,ShowMsg,ShowIco; - HACCOUNT ActualAccount; - DWORD ErrorCode; - char* TitleStrA; - char *Message1A=NULL; - TCHAR *Message1W=NULL; - POPUPDATAT BadConnectPopUp; - - ActualAccount=((struct BadConnectionParam *)lParam)->account; - ErrorCode=((struct BadConnectionParam *)lParam)->errcode; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait\n"); -#endif - if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait failed\n"); -#endif - return FALSE; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read enter\n"); -#endif - TitleStrA = new char[strlen(ActualAccount->Name)+strlen(Translate(BADCONNECTTITLE))]; - wsprintfA(TitleStrA,Translate(BADCONNECTTITLE),ActualAccount->Name); - - ShowPopUp=ActualAccount->BadConnectN.Flags & YAMN_ACC_POP; - ShowMsg=ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG; - ShowIco=ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO; - - if (ShowPopUp) - { - BadConnectPopUp.lchContact=ActualAccount; - BadConnectPopUp.lchIcon=g_LoadIconEx(3); - BadConnectPopUp.colorBack=ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? ActualAccount->BadConnectN.PopUpB : GetSysColor(COLOR_BTNFACE); - BadConnectPopUp.colorText=ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? ActualAccount->BadConnectN.PopUpT : GetSysColor(COLOR_WINDOWTEXT); - BadConnectPopUp.iSeconds=ActualAccount->BadConnectN.PopUpTime; - - BadConnectPopUp.PluginWindowProc=BadConnectPopUpProc; - BadConnectPopUp.PluginData=0; //it's bad connect popup - lstrcpyn(BadConnectPopUp.lptzContactName,_A2T(ActualAccount->Name),SIZEOF(BadConnectPopUp.lptzContactName)); - } - - if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr!=NULL) - { - Message1W=ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode); - SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); - lstrcpyn(BadConnectPopUp.lptzText,Message1W,sizeof(BadConnectPopUp.lptzText)); - if (ShowPopUp) - PUAddPopUpT(&BadConnectPopUp); - } - else if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->GetErrorStringAFcnPtr!=NULL) - { - Message1W=ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode); - SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); - lstrcpyn(BadConnectPopUp.lptzText,Message1W,sizeof(BadConnectPopUp.lptzText)); - if (ShowPopUp) - PUAddPopUpT(&BadConnectPopUp); - } - else - { - Message1W=TranslateT("Unknown error"); - SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); - lstrcpyn(BadConnectPopUp.lptzText,Message1W,sizeof(BadConnectPopUp.lptzText)); - if (ShowPopUp) - PUAddPopUpT(&BadConnectPopUp); - } - - if (!ShowMsg && !ShowIco) - DestroyWindow(hDlg); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read done\n"); -#endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - - SetWindowTextA(hDlg, TitleStrA); - delete[] TitleStrA; - if (Message1A!=NULL) - delete[] Message1A; - if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr!=NULL && Message1A!=NULL) - ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr(Message1A); - if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr!=NULL && Message1W!=NULL) - ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr(Message1W); - return 0; - } - case WM_DESTROY: - { - NOTIFYICONDATA nid; - - ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); - nid.cbSize=sizeof(NOTIFYICONDATA); - nid.hWnd=hDlg; - nid.uID=0; - Shell_NotifyIcon(NIM_DELETE,&nid); - PostQuitMessage(0); - break; - } - case WM_YAMN_NOTIFYICON: - switch (lParam) - { - case WM_LBUTTONDBLCLK: - ShowWindow(hDlg,SW_SHOWNORMAL); - SetForegroundWindow(hDlg); - break; - } - return 0; - case WM_CHAR: - switch((TCHAR)wParam) - { - case 27: - case 13: - DestroyWindow(hDlg); - break; - } - break; - case WM_SYSCOMMAND: - switch(wParam) - { - case SC_CLOSE: - DestroyWindow(hDlg); - break; - } - case WM_COMMAND: - { - WORD wNotifyCode = HIWORD(wParam); - switch(LOWORD(wParam)) - { - case IDC_BTNOK: - DestroyWindow(hDlg); - break; - } - break; - } - } - return 0; -} - -DWORD WINAPI BadConnection(LPVOID Param) -{ - MSG msg; - HWND hBadConnect; - HACCOUNT ActualAccount; - struct BadConnectionParam MyParam; - NOTIFYICONDATA nid; - char *NotIconText = Translate(" - connection error"), *src; - TCHAR *dest; - int i; - - MyParam=*(struct BadConnectionParam *)Param; - ActualAccount=MyParam.account; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:Incrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); -#endif - SCIncFcn(ActualAccount->UsingThreads); - -// we will not use params in stack anymore - SetEvent(MyParam.ThreadRunningEV); - - __try - { - hBadConnect=CreateDialogParam(YAMNVar.hInst,MAKEINTRESOURCE(IDD_DLGBADCONNECT),NULL,DlgProcYAMNBadConnection,(LPARAM)&MyParam); - SendMessage(hBadConnect,WM_SETICON,ICON_BIG,(LPARAM)g_LoadIconEx(3)); - SendMessage(hBadConnect,WM_SETICON,ICON_SMALL,(LPARAM)g_LoadIconEx(3)); - - ZeroMemory(&nid,sizeof(nid)); - nid.cbSize=sizeof(NOTIFYICONDATA); - nid.hWnd=hBadConnect; - nid.hIcon=g_LoadIconEx(3); - nid.uID=0; - nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP; - nid.uCallbackMessage=WM_YAMN_NOTIFYICON; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait\n"); -#endif - if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait failed\n"); -#endif - return 0; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read enter\n"); -#endif - for (src=ActualAccount->Name,dest=nid.szTip,i=0;(*src!=(TCHAR)0) && (i+1BadConnectN.Flags & YAMN_ACC_SND) - CallService(MS_SKIN_PLAYSOUND,0,(LPARAM)YAMN_CONNECTFAILSOUND); - if (ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG) - ShowWindow(hBadConnect,SW_SHOWNORMAL); - if (ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO) - Shell_NotifyIcon(NIM_ADD,&nid); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read done\n"); -#endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - - UpdateWindow(hBadConnect); - while(GetMessage(&msg,NULL,0,0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - -// now, write to file. Why? Because we want to write when was new mail last checked - if ((ActualAccount->Plugin->Fcn!=NULL) && (ActualAccount->Plugin->Fcn->WriteAccountsFcnPtr!=NULL) && ActualAccount->AbleToWork) - ActualAccount->Plugin->Fcn->WriteAccountsFcnPtr(); - } - __finally - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"BadConnect:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); -#endif - SCDecFcn(ActualAccount->UsingThreads); - } - return 0; -} - - -INT_PTR RunBadConnectionSvc(WPARAM wParam,LPARAM lParam) -{ - DWORD tid; -//an event for successfull copy parameters to which point a pointer in stack for new thread - HANDLE ThreadRunningEV; - PYAMN_BADCONNECTIONPARAM Param=(PYAMN_BADCONNECTIONPARAM)wParam; - - if ((DWORD)lParam!=YAMN_BADCONNECTIONVERSION) - return 0; - - if (NULL!=(ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) - { - HANDLE NewThread; - - Param->ThreadRunningEV=ThreadRunningEV; - if (NULL!=(NewThread=CreateThread(NULL,0,BadConnection,Param,0,&tid))) - { - WaitForSingleObject(ThreadRunningEV,INFINITE); - CloseHandle(NewThread); - } - CloseHandle(ThreadRunningEV); - - return 1; - } - return 0; -} diff --git a/protocols/YAMN/browser/m_browser.h b/protocols/YAMN/browser/m_browser.h deleted file mode 100644 index 8b05e3d84a..0000000000 --- a/protocols/YAMN/browser/m_browser.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __MAILBROWSER_H -#define __MAILBROWSER_H - -#include "m_account.h" -#include "../debug.h" - -typedef struct MailBrowserWinParam -{ -#define YAMN_MAILBROWSERVERSION 1 - HANDLE ThreadRunningEV; - HACCOUNT account; - DWORD nflags; //flags YAMN_ACC_??? when new mails - DWORD nnflags; //flags YAMN_ACC_??? when no new mails - void *Param; -} YAMN_MAILBROWSERPARAM,*PYAMN_MAILBROWSERPARAM; - -typedef struct MailShowMsgWinParam -{ - HANDLE ThreadRunningEV; - HACCOUNT account; - HYAMNMAIL mail; -} YAMN_MAILSHOWPARAM, *PYAMN_MAILSHOWPARAM; - -typedef struct NoNewMailParam -{ -#define YAMN_NONEWMAILVERSION 1 - HANDLE ThreadRunningEV; - HACCOUNT account; - DWORD flags; - void *Param; -} YAMN_NONEWMAILPARAM,*PYAMN_NONEWMAILPARAM; - -typedef struct BadConnectionParam -{ -#define YAMN_BADCONNECTIONVERSION 1 - HANDLE ThreadRunningEV; - HACCOUNT account; - UINT_PTR errcode; - void *Param; -} YAMN_BADCONNECTIONPARAM,*PYAMN_BADCONNECTIONPARAM; - -#endif diff --git a/protocols/YAMN/browser/mailbrowser.cpp b/protocols/YAMN/browser/mailbrowser.cpp deleted file mode 100644 index 15b24d0356..0000000000 --- a/protocols/YAMN/browser/mailbrowser.cpp +++ /dev/null @@ -1,2605 +0,0 @@ -/* - * This code implements window handling (new mail) - * - * (c) majvan 2002-2004 - */ -/* There can be problems when compiling this file, because in this file - * we are using both unicode and no-unicode functions and compiler does not - * like it in one file - * When you got errors, try to comment the #define and compile, then - * put it back to uncommented and compile again :) - */ -#ifndef _WIN32_IE - #define _WIN32_IE 0x0400 -#endif -#ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0501 -#endif - -#include "../yamn.h" -#include "../main.h" - -#define TIMER_FLASHING 0x09061979 -#define MAILBROWSER_MINXSIZE 200 //min size of mail browser window -#define MAILBROWSER_MINYSIZE 130 - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- -char* s_MonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -bool bDate = false,bSub=false,bSize=false,bFrom=false; -int PosX=0,PosY=0,SizeX=460,SizeY=100; -int HeadSizeX = 0x2b2, HeadSizeY = 0x0b5, HeadPosX = 100, HeadPosY = 100; -int HeadSplitPos=250; // per-mils of the size -static int FromWidth=250,SubjectWidth=280,SizeWidth=50,SizeDate=205; -unsigned char optDateTime = (SHOWDATELONG | SHOWDATENOTODAY); - -static WNDPROC OldListViewSubclassProc; - -struct CMailNumbersSub -{ - int Total; //any mail - int New; //uses YAMN_MSG_NEW flag - int UnSeen; //uses YAMN_MSG_UNSEEN flag -// int Browser; //uses YAMN_MSG_BROWSER flag - int BrowserUC; //uses YAMN_MSG_BROWSER flag and YAMN_MSG_UNSEEN flag - int Display; //uses YAMN_MSG_DISPLAY flag - int DisplayTC; //uses YAMN_MSG_DISPLAY flag and YAMN_MSG_DISPLAYC flag - int DisplayUC; //uses YAMN_MSG_DISPLAY flag and YAMN_MSG_DISPLAYC flag and YAMN_MSG_UNSEEN flag - int PopUp; //uses YAMN_MSG_POPUP flag - int PopUpTC; //uses YAMN_MSG_POPUPC flag - int PopUpNC; //uses YAMN_MSG_POPUPC flag and YAMN_MSG_NEW flag - int PopUpRun; //uses YAMN_MSG_POPUP flag and YAMN_MSG_NEW flag - int PopUpSL2NC; //uses YAMN_MSG_SPAML2 flag and YAMN_MSG_NEW flag - int PopUpSL3NC; //uses YAMN_MSG_SPAML3 flag and YAMN_MSG_NEW flag -// int SysTray; //uses YAMN_MSG_SYSTRAY flag - int SysTrayUC; //uses YAMN_MSG_SYSTRAY flag and YAMN_MSG_UNSEEN flag -// int Sound; //uses YAMN_MSG_SOUND flag - int SoundNC; //uses YAMN_MSG_SOUND flag and YAMN_MSG_NEW flag -// int App; //uses YAMN_MSG_APP flag - int AppNC; //uses YAMN_MSG_APP flag and YAMN_MSG_NEW flag - int EventNC; //uses YAMN_MSG_NEVENT flag and YAMN_MSG_NEW flag -}; - -struct CMailNumbers -{ - struct CMailNumbersSub Real; - struct CMailNumbersSub Virtual; -}; - -struct CMailWinUserInfo -{ - HACCOUNT Account; - int TrayIconState; - BOOL UpdateMailsMessagesAccess; - BOOL Seen; - BOOL RunFirstTime; -}; - -struct CChangeContent -{ - DWORD nflags; - DWORD nnflags; -}; - -struct CUpdateMails -{ - struct CChangeContent *Flags; - BOOL Waiting; - HANDLE Copied; -}; -struct CSortList -{ - HWND hDlg; - int iSubItem; -}; - -//Retrieves HACCOUNT, whose mails are displayed in ListMails -// hLM- handle of dialog window -// returns handle of account -inline HACCOUNT GetWindowAccount(HWND hDialog); - -//Looks to mail flags and increment mail counter (e.g. if mail is new, increments the new mail counter -// msgq- mail, which increments the counters -// MN- counnters structure -void IncrementMailCounters(HYAMNMAIL msgq,struct CMailNumbers *MN); - -enum -{ - UPDATE_FAIL=0, //function failed - UPDATE_NONE, //none update has been performed - UPDATE_OK, //some changes occured, update performed -}; -//Just looks for mail changes in account and update the mail browser window -// hDlg- dialog handle -// ActualAccount- account handle -// nflags- flags what to do when new mail arrives -// nnflags- flags what to do when no new mail arrives -// returns one of UPDATE_XXX value(not implemented yet) -int UpdateMails(HWND hDlg,HACCOUNT ActualAccount,DWORD nflags,DWORD nnflags); - -//When new mail occurs, shows window, plays sound, runs application... -// hDlg- dialog handle. Dialog of mailbrowser is already created and actions are performed over this window -// ActualAccount- handle of account, whose mails are to be notified -// MN- statistics of mails in account -// nflags- what to do or not to do (e.g. to show mailbrowser window or prohibit to show) -// nflags- flags what to do when new mail arrives -// nnflags- flags what to do when no new mail arrives -void DoMailActions(HWND hDlg,HACCOUNT ActualAccount,struct CMailNumbers *MN,DWORD nflags,DWORD nnflags); - -//Looks for items in mailbrowser and if they were deleted, delete them from browser window -// hListView- handle of listview window -// ActualAccount- handle of account, whose mails are show -// MailNumbers- pointer to structure, in which function stores numbers of mails with some property -// returns one of UPDATE_XXX value (not implemented yet) -int ChangeExistingMailStatus(HWND hListView,HACCOUNT ActualAccount,struct CMailNumbers *MN); - -//Adds new mails to ListView and if any new, shows multi popup (every new message is new popup window created by popup plugin) -// hListView- handle of listview window -// ActualAccount- handle of account, whose mails are show -// NewMailPopUp- pointer to prepared structure for popup plugin, can be NULL if no popup show -// MailNumbers- pointer to structure, in which function stores numbers of mails with some property -// nflags- flags what to do when new mail arrives -// returns one of UPDATE_XXX value (not implemented yet) -int AddNewMailsToListView(HWND hListView,HACCOUNT ActualAccount,struct CMailNumbers *MailNumbers,DWORD nflags); - -//Window callback procedure for popup window (created by popup plugin) -LRESULT CALLBACK NewMailPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam); - -//Window callback procedure for popup window (created by popup plugin) -LRESULT CALLBACK NoNewMailPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam); - -//Dialog callback procedure for mail browser -INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam); - -//MailBrowser thread function creates window if needed, tray icon and plays sound -DWORD WINAPI MailBrowser(LPVOID Param); - -LRESULT CALLBACK ListViewSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); - -//Runs mail browser in new thread -INT_PTR RunMailBrowserSvc(WPARAM,LPARAM); - -#define YAMN_BROWSER_SHOWPOPUP 0x01 - - // list view items' order criteria - #define LVORDER_NOORDER -1 - #define LVORDER_STRING 0 - #define LVORDER_NUMERIC 1 - #define LVORDER_DATETIME 2 - - // list view order direction - #define LVORDER_ASCENDING 1 - #define LVORDER_NONE 0 - #define LVORDER_DESCENDING -1 - - // list view sort type - #define LVSORTPRIORITY_NONE -1 - - // List view column info. - typedef struct _SAMPLELISTVIEWCOLUMN - { - UINT uCXCol; // index - int nSortType; // sorting type (STRING = 0, NUMERIC, DATE, DATETIME) - int nSortOrder; // sorting order (ASCENDING = -1, NONE, DESCENDING) - int nPriority; // sort priority (-1 for none, 0, 1, ..., nColumns - 1 maximum) - TCHAR lpszName[128]; // column name - } SAMPLELISTVIEWCOLUMN; - - // Compare priority - typedef struct _LVCOMPAREINFO - { - int iIdx; // Index - int iPriority; // Priority - } LVCOMPAREINFO, *LPLVCOMPAREINFO; - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -LPARAM readItemLParam(HWND hwnd,DWORD iItem) -{ - LVITEM item; - - item.mask = LVIF_PARAM; - item.iItem = iItem; - item.iSubItem = 0; - SendMessage(hwnd,LVM_GETITEM,0,(LPARAM)&item); - return item.lParam; -} - -inline HACCOUNT GetWindowAccount(HWND hDlg) -{ - struct CMailWinUserInfo *mwui; - - if (NULL==(mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER))) - return NULL; - return mwui->Account; -} - -void IncrementMailCounters(HYAMNMAIL msgq,struct CMailNumbers *MN) -{ - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.Total++; - else - MN->Real.Total++; - - if (msgq->Flags & YAMN_MSG_NEW) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.New++; - else - MN->Real.New++; - if (msgq->Flags & YAMN_MSG_UNSEEN) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.UnSeen++; - else - MN->Real.UnSeen++; - if ((msgq->Flags & (YAMN_MSG_UNSEEN | YAMN_MSG_BROWSER)) == (YAMN_MSG_UNSEEN | YAMN_MSG_BROWSER)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.BrowserUC++; - else - MN->Real.BrowserUC++; - if (msgq->Flags & YAMN_MSG_DISPLAY) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.Display++; - else - MN->Real.Display++; - if ((msgq->Flags & (YAMN_MSG_DISPLAYC | YAMN_MSG_DISPLAY)) == (YAMN_MSG_DISPLAYC | YAMN_MSG_DISPLAY)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.DisplayTC++; - else - MN->Real.DisplayTC++; - if ((msgq->Flags & (YAMN_MSG_UNSEEN | YAMN_MSG_DISPLAYC | YAMN_MSG_DISPLAY)) == (YAMN_MSG_UNSEEN | YAMN_MSG_DISPLAYC | YAMN_MSG_DISPLAY)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.DisplayUC++; - else - MN->Real.DisplayUC++; - if (msgq->Flags & YAMN_MSG_POPUP) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.PopUp++; - else - MN->Real.PopUp++; - if ((msgq->Flags & YAMN_MSG_POPUPC) == YAMN_MSG_POPUPC) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.PopUpTC++; - else - MN->Real.PopUpTC++; - if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_POPUPC)) == (YAMN_MSG_NEW | YAMN_MSG_POPUPC)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.PopUpNC++; - else - MN->Real.PopUpNC++; - if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_POPUP)) == (YAMN_MSG_NEW | YAMN_MSG_POPUP)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.PopUpRun++; - else - MN->Real.PopUpRun++; - if ((msgq->Flags & YAMN_MSG_NEW) && YAMN_MSG_SPAML(msgq->Flags,YAMN_MSG_SPAML2)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.PopUpSL2NC++; - else - MN->Real.PopUpSL2NC++; - if ((msgq->Flags & YAMN_MSG_NEW) && YAMN_MSG_SPAML(msgq->Flags,YAMN_MSG_SPAML3)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.PopUpSL3NC++; - else - MN->Real.PopUpSL3NC++; -/* if (msgq->MailData->Flags & YAMN_MSG_SYSTRAY) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.SysTray++; - else - MN->Real.SysTray++; -*/ if ((msgq->Flags & (YAMN_MSG_UNSEEN | YAMN_MSG_SYSTRAY)) == (YAMN_MSG_UNSEEN|YAMN_MSG_SYSTRAY)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.SysTrayUC++; - else - MN->Real.SysTrayUC++; -/* if (msgq->MailData->Flags & YAMN_MSG_SOUND) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.Sound++; - else - MN->Real.Sound++; -*/ if ((msgq->Flags & (YAMN_MSG_NEW|YAMN_MSG_SOUND)) == (YAMN_MSG_NEW|YAMN_MSG_SOUND)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.SoundNC++; - else - MN->Real.SoundNC++; -/* if (msgq->MailData->Flags & YAMN_MSG_APP) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.App++; - else - MN->Real.App++; -*/ if ((msgq->Flags & (YAMN_MSG_NEW|YAMN_MSG_APP)) == (YAMN_MSG_NEW|YAMN_MSG_APP)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.AppNC++; - else - MN->Real.AppNC++; - if ((msgq->Flags & (YAMN_MSG_NEW|YAMN_MSG_NEVENT)) == (YAMN_MSG_NEW|YAMN_MSG_NEVENT)) - if (msgq->Flags & YAMN_MSG_VIRTUAL) - MN->Virtual.EventNC++; - else - MN->Real.EventNC++; -} - -int UpdateMails(HWND hDlg,HACCOUNT ActualAccount,DWORD nflags,DWORD nnflags) -{ -#define MAILBROWSERTITLE "%s - %d new mail messages, %d total" - - struct CMailWinUserInfo *mwui; - struct CMailNumbers MN; - - HYAMNMAIL msgq; - BOOL Loaded; - BOOL RunMailBrowser,RunPopUps; - - mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER); - //now we ensure read access for account and write access for its mails - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read wait failed\n"); - #endif - PostMessage(hDlg,WM_DESTROY,(WPARAM)0,(LPARAM)0); - - return UPDATE_FAIL; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read enter\n"); - #endif - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UpdateMails:ActualAccountMsgsSO-write wait\n"); - #endif - if (WAIT_OBJECT_0!=WaitToWriteFcn(ActualAccount->MessagesAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UpdateMails:ActualAccountMsgsSO-write wait failed\n"); - DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - - PostMessage(hDlg,WM_DESTROY,(WPARAM)0,(LPARAM)0); - return UPDATE_FAIL; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UpdateMails:ActualAccountMsgsSO-write enter\n"); - #endif - - ZeroMemory(&MN,sizeof(MN)); - - for (msgq=(HYAMNMAIL)ActualAccount->Mails;msgq!=NULL;msgq=msgq->Next) - { - if (!LoadedMailData(msgq)) //check if mail is already in memory - { - Loaded=false; - if (NULL==LoadMailData(msgq)) //if we could not load mail to memory, consider this mail deleted and do not display it - continue; - } - else - Loaded=true; - - IncrementMailCounters(msgq,&MN); - - if (!Loaded) - UnloadMailData(msgq); //do not keep data for mail in memory - } - - if (mwui!=NULL) - mwui->UpdateMailsMessagesAccess=TRUE; - - //Now we are going to check if extracting data from mail headers are needed. - //If popups will be displayed or mailbrowser window - if ((((mwui!=NULL) && !(mwui->RunFirstTime)) && - ( - ((nnflags & YAMN_ACC_MSGP) && !(MN.Real.BrowserUC+MN.Virtual.BrowserUC)) || - ((nflags & YAMN_ACC_MSGP) && (MN.Real.BrowserUC+MN.Virtual.BrowserUC)) - ) - ) || //if mail window was displayed before and flag YAMN_ACC_MSGP is set - ((nnflags & YAMN_ACC_MSG) && !(MN.Real.BrowserUC+MN.Virtual.BrowserUC)) || //if needed to run mailbrowser when no unseen and no unseen mail found - ((nflags & YAMN_ACC_MSG) && (MN.Real.BrowserUC+MN.Virtual.BrowserUC)) || //if unseen mails found, we sure run mailbrowser - ((nflags & YAMN_ACC_ICO) && (MN.Real.SysTrayUC+MN.Virtual.SysTrayUC)) - ) //if needed to run systray - RunMailBrowser=TRUE; - else RunMailBrowser=FALSE; - - if ( (nflags & YAMN_ACC_POP) && - (ActualAccount->Flags & YAMN_ACC_POPN) && - (MN.Real.PopUpNC+MN.Virtual.PopUpNC)) //if some popups with mails are needed to show - RunPopUps=TRUE; - else RunPopUps=FALSE; - - if (RunMailBrowser) - ChangeExistingMailStatus(GetDlgItem(hDlg,IDC_LISTMAILS),ActualAccount,&MN); - if (RunMailBrowser || RunPopUps) - AddNewMailsToListView(hDlg==NULL ? NULL : GetDlgItem(hDlg,IDC_LISTMAILS),ActualAccount,&MN,nflags); - - if (RunMailBrowser) - { - size_t len = strlen(ActualAccount->Name)+strlen(Translate(MAILBROWSERTITLE))+10; //+10 chars for numbers - char *TitleStrA=new char[len]; - WCHAR *TitleStrW=new WCHAR[len]; - - sprintf(TitleStrA,Translate(MAILBROWSERTITLE),ActualAccount->Name,MN.Real.DisplayUC+MN.Virtual.DisplayUC,MN.Real.Display+MN.Virtual.Display); - MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,TitleStrA,-1,TitleStrW,(int)strlen(TitleStrA)+1); - SendMessageW(hDlg,WM_SETTEXT,(WPARAM)0,(LPARAM)TitleStrW); - delete[] TitleStrA; - delete[] TitleStrW; - } - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UpdateMails:Do mail actions\n"); - #endif - - DoMailActions(hDlg,ActualAccount,&MN,nflags,nnflags); - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UpdateMails:Do mail actions done\n"); - #endif - - SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails,YAMN_MSG_NEW,0,YAMN_MSG_NEW,YAMN_FLAG_REMOVE); //rempve the new flag - if (!RunMailBrowser) - SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails,YAMN_MSG_UNSEEN,YAMN_MSG_STAYUNSEEN,YAMN_MSG_UNSEEN,YAMN_FLAG_REMOVE); //remove the unseen flag when it was not displayed and it has not "stay unseen" flag set - - if (mwui!=NULL) - { - mwui->UpdateMailsMessagesAccess=FALSE; - mwui->RunFirstTime=FALSE; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UpdateMails:ActualAccountMsgsSO-write done\n"); - DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read done\n"); - #endif - WriteDoneFcn(ActualAccount->MessagesAccessSO); - ReadDoneFcn(ActualAccount->AccountAccessSO); - - if (RunMailBrowser) - UpdateWindow(GetDlgItem(hDlg,IDC_LISTMAILS)); - else if (hDlg!=NULL) - DestroyWindow(hDlg); - - return 1; -} - -int ChangeExistingMailStatus(HWND hListView,HACCOUNT ActualAccount,struct CMailNumbers *MN) -{ - int i,in; - LVITEMW item; - HYAMNMAIL mail,msgq; - - in=ListView_GetItemCount(hListView); - item.mask=LVIF_PARAM; - - for (i=0;iMails;(msgq!=NULL)&&(msgq!=mail);msgq=msgq->Next); //found the same mail in account queue - if (msgq==NULL) //if mail was not found - if (TRUE==ListView_DeleteItem(hListView,i)) - { - in--;i--; - continue; - } - } - - return TRUE; -} - -void MimeDateToLocalizedDateTime(char *datein, WCHAR *dateout, int lendateout); -int AddNewMailsToListView(HWND hListView,HACCOUNT ActualAccount,struct CMailNumbers *MN,DWORD nflags) -{ - HYAMNMAIL msgq; - POPUPDATAT NewMailPopUp = {0}; - - WCHAR *FromStr; - WCHAR SizeStr[20]; - WCHAR LocalDateStr[128]; - - LVITEMW item; - LVFINDINFO fi; - - int foundi,lfoundi; - struct CHeader UnicodeHeader; - BOOL Loaded,Extracted,FromStrNew=FALSE; - - ZeroMemory(&item,sizeof(item)); - ZeroMemory(&UnicodeHeader,sizeof(UnicodeHeader)); - - if (hListView!=NULL) - { - item.mask=LVIF_TEXT | LVIF_PARAM; - item.iItem=0; - ZeroMemory(&fi,sizeof(fi)); - fi.flags=LVFI_PARAM; //let's go search item by lParam number - lfoundi=0; - } - - NewMailPopUp.lchContact=(ActualAccount->hContact != NULL) ? ActualAccount->hContact : ActualAccount; - NewMailPopUp.lchIcon=g_LoadIconEx(2); - NewMailPopUp.colorBack=nflags & YAMN_ACC_POPC ? ActualAccount->NewMailN.PopUpB : GetSysColor(COLOR_BTNFACE); - NewMailPopUp.colorText=nflags & YAMN_ACC_POPC ? ActualAccount->NewMailN.PopUpT : GetSysColor(COLOR_WINDOWTEXT); - NewMailPopUp.iSeconds=ActualAccount->NewMailN.PopUpTime; - - NewMailPopUp.PluginWindowProc=NewMailPopUpProc; - NewMailPopUp.PluginData=(void *)0; //it's new mail popup - - for (msgq=(HYAMNMAIL)ActualAccount->Mails;msgq!=NULL;msgq=msgq->Next,lfoundi++) - { -// now we hide mail pointer to item's lParam member. We can later use it to retrieve mail datas - - Extracted=FALSE;FromStr=NULL;FromStrNew=FALSE; - - if (hListView!=NULL) - { - fi.lParam=(LPARAM)msgq; - if (-1!=(foundi=ListView_FindItem(hListView,-1,&fi))) //if mail is already in window - { - lfoundi=foundi; - continue; //do not insert any item - } - - item.iItem=lfoundi; //insert after last found item - item.lParam=(LPARAM)msgq; - } - - if (!LoadedMailData(msgq)) //check if mail is already in memory - { - Loaded=false; - if (NULL==LoadMailData(msgq)) //if we could not load mail to memory, consider this mail deleted and do not display it - continue; - } - else - Loaded=true; - - if (((hListView!=NULL) && (msgq->Flags & YAMN_MSG_DISPLAY)) || - ((nflags & YAMN_ACC_POP) && (ActualAccount->Flags & YAMN_ACC_POPN) && (msgq->Flags & YAMN_MSG_POPUP) && (msgq->Flags & YAMN_MSG_NEW))) - { - - if (!Extracted) ExtractHeader(msgq->MailData->TranslatedHeader,msgq->MailData->CP,&UnicodeHeader); - Extracted=TRUE; - - if ((UnicodeHeader.From!=NULL) && (UnicodeHeader.FromNick!=NULL)) - { - FromStr=new WCHAR[wcslen(UnicodeHeader.From)+wcslen(UnicodeHeader.FromNick)+4]; - swprintf(FromStr,L"%s <%s>",UnicodeHeader.FromNick,UnicodeHeader.From); - FromStrNew=TRUE; - } - else if (UnicodeHeader.From!=NULL) - FromStr=UnicodeHeader.From; - else if (UnicodeHeader.FromNick!=NULL) - FromStr=UnicodeHeader.FromNick; - else if (UnicodeHeader.ReturnPath!=NULL) - FromStr=UnicodeHeader.ReturnPath; - - if (NULL==FromStr) - { - FromStr=L""; - FromStrNew=FALSE; - } - } - - - if ((hListView!=NULL) && (msgq->Flags & YAMN_MSG_DISPLAY)) - { - item.iSubItem=0; - item.pszText=FromStr; - item.iItem=SendMessageW(hListView,LVM_INSERTITEMW,(WPARAM)0,(LPARAM)&item); - - item.iSubItem=1; - item.pszText=(NULL!=UnicodeHeader.Subject ? UnicodeHeader.Subject : (WCHAR*)L""); - SendMessageW(hListView,LVM_SETITEMTEXTW,(WPARAM)item.iItem,(LPARAM)&item); - - item.iSubItem=2; - swprintf(SizeStr,L"%d kB",msgq->MailData->Size/1024); - item.pszText=SizeStr; - SendMessageW(hListView,LVM_SETITEMTEXTW,(WPARAM)item.iItem,(LPARAM)&item); - - item.iSubItem=3; - item.pszText=L""; - { CMimeItem *heads; - for (heads=msgq->MailData->TranslatedHeader;heads!=NULL;heads=heads->Next) { - if (!_stricmp(heads->name,"Date")) { - MimeDateToLocalizedDateTime(heads->value,LocalDateStr,128); - item.pszText=LocalDateStr; - break; - } } } - SendMessageW(hListView,LVM_SETITEMTEXTW,(WPARAM)item.iItem,(LPARAM)&item); - } - - if ((nflags & YAMN_ACC_POP) && (ActualAccount->Flags & YAMN_ACC_POPN) && (msgq->Flags & YAMN_MSG_POPUP) && (msgq->Flags & YAMN_MSG_NEW)) - { - WideCharToMultiByte(CP_ACP,0,FromStr,-1,(char *)NewMailPopUp.lptzContactName,sizeof(NewMailPopUp.lptzContactName),NULL,NULL); - if (!WideCharToMultiByte(CP_ACP,0,UnicodeHeader.Subject,-1,(char *)NewMailPopUp.lptzText,sizeof(NewMailPopUp.lptzText),NULL,NULL)) - NewMailPopUp.lptzText[0]=0; - PYAMN_MAILSHOWPARAM MailParam = (PYAMN_MAILSHOWPARAM)malloc(sizeof(YAMN_MAILSHOWPARAM)); - if (MailParam) { - MailParam->account = ActualAccount; - MailParam->mail = msgq; - MailParam->ThreadRunningEV = 0; - NewMailPopUp.PluginData=MailParam; - PUAddPopUpT(&NewMailPopUp); - } - } - - if ((msgq->Flags & YAMN_MSG_UNSEEN) && (ActualAccount->NewMailN.Flags & YAMN_ACC_KBN)) - CallService(MS_KBDNOTIFY_EVENTSOPENED,(WPARAM)1,NULL); - - if (FromStrNew) - delete[] FromStr; - - if (Extracted) - { - DeleteHeaderContent(&UnicodeHeader); - ZeroMemory(&UnicodeHeader,sizeof(UnicodeHeader)); - } - - if (!Loaded) - { - SaveMailData(msgq); - UnloadMailData(msgq); //do not keep data for mail in memory - } - } - - return TRUE; -} - -void DoMailActions(HWND hDlg,HACCOUNT ActualAccount,struct CMailNumbers *MN,DWORD nflags,DWORD nnflags) -{ - char *NotIconText = Translate("- new mail message(s)"); - NOTIFYICONDATA nid; - - ZeroMemory(&nid,sizeof(nid)); - - if (MN->Real.EventNC+MN->Virtual.EventNC) - NotifyEventHooks(hNewMailHook,0,0); - - if ((nflags & YAMN_ACC_KBN) && (MN->Real.PopUpRun+MN->Virtual.PopUpRun)) - { - CallService(MS_KBDNOTIFY_STARTBLINK,(WPARAM)MN->Real.PopUpNC+MN->Virtual.PopUpNC,NULL); - } - - if ((nflags & YAMN_ACC_CONT) && (MN->Real.PopUpRun+MN->Virtual.PopUpRun)) - { - char sMsg[250]; - _snprintf(sMsg,249,Translate("%s : %d new mail message(s), %d total"),ActualAccount->Name,MN->Real.PopUpNC+MN->Virtual.PopUpNC,MN->Real.PopUpTC+MN->Virtual.PopUpTC); - if (!(nflags & YAMN_ACC_CONTNOEVENT)) { - CLISTEVENT cEvent; - cEvent.cbSize = sizeof(CLISTEVENT); - cEvent.hContact = ActualAccount->hContact; - cEvent.hIcon = g_LoadIconEx(2); - cEvent.hDbEvent = (HANDLE)ActualAccount->hContact; - cEvent.lParam = (LPARAM) ActualAccount->hContact; - cEvent.pszService = MS_YAMN_CLISTDBLCLICK; - cEvent.pszTooltip = sMsg; - cEvent.flags = 0; - CallServiceSync(MS_CLIST_ADDEVENT, 0,(LPARAM)&cEvent); - } - DBWriteContactSettingString(ActualAccount->hContact, "CList", "StatusMsg", sMsg); - - if (nflags & YAMN_ACC_CONTNICK) - { - DBWriteContactSettingString(ActualAccount->hContact, YAMN_DBMODULE, "Nick",sMsg); - } - } - - if ((nflags & YAMN_ACC_POP) && - !(ActualAccount->Flags & YAMN_ACC_POPN) && - (MN->Real.PopUpRun+MN->Virtual.PopUpRun)) - { - POPUPDATAT NewMailPopUp ={0}; - - NewMailPopUp.lchContact=(ActualAccount->hContact != NULL) ? ActualAccount->hContact : ActualAccount; - NewMailPopUp.lchIcon=g_LoadIconEx(2); - NewMailPopUp.colorBack=nflags & YAMN_ACC_POPC ? ActualAccount->NewMailN.PopUpB : GetSysColor(COLOR_BTNFACE); - NewMailPopUp.colorText=nflags & YAMN_ACC_POPC ? ActualAccount->NewMailN.PopUpT : GetSysColor(COLOR_WINDOWTEXT); - NewMailPopUp.iSeconds=ActualAccount->NewMailN.PopUpTime; - - NewMailPopUp.PluginWindowProc=NewMailPopUpProc; - NewMailPopUp.PluginData=(void *)0; //multiple popups - - lstrcpyn(NewMailPopUp.lptzContactName, _A2T(ActualAccount->Name),SIZEOF(NewMailPopUp.lptzContactName)); - wsprintf(NewMailPopUp.lptzText,TranslateT("%d new mail message(s), %d total"),MN->Real.PopUpNC+MN->Virtual.PopUpNC,MN->Real.PopUpTC+MN->Virtual.PopUpTC); - PUAddPopUpT(&NewMailPopUp); - } - - //destroy tray icon if no new mail - if ((MN->Real.SysTrayUC+MN->Virtual.SysTrayUC==0) && (hDlg!=NULL)) - { - nid.hWnd=hDlg; - nid.uID=0; - Shell_NotifyIcon(NIM_DELETE,&nid); - } - - //and remove the event - if ((nflags & YAMN_ACC_CONT) && (!(nflags & YAMN_ACC_CONTNOEVENT)) && (MN->Real.UnSeen + MN->Virtual.UnSeen==0)) { - CallService(MS_CLIST_REMOVEEVENT,(WPARAM)ActualAccount->hContact,(LPARAM)ActualAccount->hContact); - } - - if ((MN->Real.BrowserUC+MN->Virtual.BrowserUC==0) && (hDlg!=NULL)) - { - if (!IsWindowVisible(hDlg) && !(nflags & YAMN_ACC_MSG)) - PostMessage(hDlg,WM_DESTROY,(WPARAM)0,(LPARAM)0); //destroy window if no new mail and window is not visible - if (nnflags & YAMN_ACC_MSG) //if no new mail and msg should be executed - { - SetForegroundWindow(hDlg); - ShowWindow(hDlg,SW_SHOWNORMAL); - } - } - else - if (hDlg!=NULL) //else insert icon and set window if new mails - { - SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_SCROLL,(WPARAM)0,(LPARAM)0x7ffffff); - - if ((nflags & YAMN_ACC_ICO) && (MN->Real.SysTrayUC+MN->Virtual.SysTrayUC)) - { - char* src; - TCHAR *dest; - int i; - - for (src=ActualAccount->Name,dest=nid.szTip,i=0;(*src!=(TCHAR)0) && (i+1Real.AppNC+MN->Virtual.AppNC!=0) - { - if (nflags & YAMN_ACC_APP) - { - PROCESS_INFORMATION pi; - STARTUPINFOW si; - ZeroMemory(&si,sizeof(si)); - si.cb=sizeof(si); - - if (ActualAccount->NewMailN.App!=NULL) - { - WCHAR *Command; - if (ActualAccount->NewMailN.AppParam!=NULL) - Command=new WCHAR[wcslen(ActualAccount->NewMailN.App)+wcslen(ActualAccount->NewMailN.AppParam)+6]; - else - Command=new WCHAR[wcslen(ActualAccount->NewMailN.App)+6]; - - if (Command!=NULL) - { - lstrcpyW(Command,L"\""); - lstrcatW(Command,ActualAccount->NewMailN.App); - lstrcatW(Command,L"\" "); - if (ActualAccount->NewMailN.AppParam!=NULL) - lstrcatW(Command,ActualAccount->NewMailN.AppParam); - CreateProcessW(NULL,Command,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); - delete[] Command; - } - } - } - } - - if (MN->Real.SoundNC+MN->Virtual.SoundNC!=0) - if (nflags & YAMN_ACC_SND) - CallService(MS_SKIN_PLAYSOUND,0,(LPARAM)YAMN_NEWMAILSOUND); - - if ((nnflags & YAMN_ACC_POP) && (MN->Real.PopUpRun+MN->Virtual.PopUpRun==0)) - { - POPUPDATAT NoNewMailPopUp; - - NoNewMailPopUp.lchContact=(ActualAccount->hContact != NULL) ? ActualAccount->hContact : ActualAccount; - NoNewMailPopUp.lchIcon=g_LoadIconEx(1); - NoNewMailPopUp.colorBack=ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC ? ActualAccount->NoNewMailN.PopUpB : GetSysColor(COLOR_BTNFACE); - NoNewMailPopUp.colorText=ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC ? ActualAccount->NoNewMailN.PopUpT : GetSysColor(COLOR_WINDOWTEXT); - NoNewMailPopUp.iSeconds=ActualAccount->NoNewMailN.PopUpTime; - - NoNewMailPopUp.PluginWindowProc=NoNewMailPopUpProc; - NoNewMailPopUp.PluginData=(void *)0; //it's not new mail popup - - lstrcpyn(NoNewMailPopUp.lptzContactName,_A2T(ActualAccount->Name),SIZEOF(NoNewMailPopUp.lptzContactName)); - if (MN->Real.PopUpSL2NC+MN->Virtual.PopUpSL2NC) - wsprintf(NoNewMailPopUp.lptzText,TranslateT("No new mail message, %d spam(s)"),MN->Real.PopUpSL2NC+MN->Virtual.PopUpSL2NC); - else - lstrcpyn(NoNewMailPopUp.lptzText,TranslateT("No new mail message"),SIZEOF(NoNewMailPopUp.lptzText)); - PUAddPopUpT(&NoNewMailPopUp); - } - - if ((nflags & YAMN_ACC_CONT) && (MN->Real.PopUpRun+MN->Virtual.PopUpRun==0)) - { - if (ActualAccount->hContact != NULL) - { - if (MN->Real.PopUpTC+MN->Virtual.PopUpTC) - { - char tmp[255]; - sprintf(tmp,Translate("%d new mail message(s), %d total"),MN->Real.PopUpNC+MN->Virtual.PopUpNC,MN->Real.PopUpTC+MN->Virtual.PopUpTC); - DBWriteContactSettingString(ActualAccount->hContact, "CList", "StatusMsg", tmp); - } - else - DBWriteContactSettingString(ActualAccount->hContact, "CList", "StatusMsg", Translate("No new mail message")); - - if (nflags & YAMN_ACC_CONTNICK) - { - DBWriteContactSettingString(ActualAccount->hContact, YAMN_DBMODULE, "Nick", ActualAccount->Name); - } - } - } - return; -} - -DWORD WINAPI ShowEmailThread(LPVOID Param); -LRESULT CALLBACK NewMailPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) -{ - INT_PTR PluginParam=0; - switch(msg) - { - case WM_COMMAND: - //if clicked and it's new mail popup window - if ((HIWORD(wParam)==STN_CLICKED) && (-1!=(PluginParam=CallService(MS_POPUP_GETPLUGINDATA,(WPARAM)hWnd,(LPARAM)&PluginParam)))) - { - HANDLE hContact = 0; - HACCOUNT Account; - if (PluginParam){ - PYAMN_MAILSHOWPARAM MailParam = new YAMN_MAILSHOWPARAM; - memcpy(MailParam,(PINT_PTR)PluginParam,sizeof(YAMN_MAILSHOWPARAM)); - hContact = MailParam->account->hContact; - Account = MailParam->account; - if (NULL!=(MailParam->ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) { - HANDLE NewThread; - if (NULL!=(NewThread=CreateThread(NULL,0,ShowEmailThread,(LPVOID)MailParam,0,NULL))) - { - CloseHandle(NewThread); - } - CloseHandle(MailParam->ThreadRunningEV); - } - //delete MailParam; - } else { - DBVARIANT dbv; - - hContact=(HANDLE)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); - - if (!DBGetContactSetting((HANDLE) hContact,YAMN_DBMODULE,"Id",&dbv)) - { - Account=(HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)dbv.pszVal); - DBFreeVariant(&dbv); - } - else - Account = (HACCOUNT) hContact; //???? - - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0==WaitToReadFcn(Account->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter\n"); - #endif - switch(msg) - { - case WM_COMMAND: - { - YAMN_MAILBROWSERPARAM Param={(HANDLE)0,Account, - (Account->NewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG, - (Account->NoNewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG}; - - RunMailBrowserSvc((WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); - } - break; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(Account->AccountAccessSO); - } - #ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter failed\n"); - #endif - } - if ((Account->NewMailN.Flags & YAMN_ACC_CONT) && !(Account->NewMailN.Flags & YAMN_ACC_CONTNOEVENT)) { - CallService(MS_CLIST_REMOVEEVENT,(WPARAM)hContact,(LPARAM)hContact); - } - } - // fall through - case WM_CONTEXTMENU: - SendMessageW(hWnd,UM_DESTROYPOPUP,0,0); - break; - case UM_FREEPLUGINDATA:{ - PYAMN_MAILSHOWPARAM mpd = (PYAMN_MAILSHOWPARAM)PUGetPluginData(hWnd); - HANDLE hContact = 0; - if ((mpd) && (INT_PTR)mpd!=-1)free(mpd); - return FALSE; - } - case UM_INITPOPUP: - //This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups. - WindowList_Add(YAMNVar.MessageWnds,hWnd,NULL); - break; - case UM_DESTROYPOPUP: - WindowList_Remove(YAMNVar.MessageWnds,hWnd); - break; - case WM_YAMN_STOPACCOUNT: - { - HACCOUNT ActualAccount; - HANDLE hContact; - DBVARIANT dbv; - - hContact=(HANDLE)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); - - if (!DBGetContactSetting((HANDLE) hContact,YAMN_DBMODULE,"Id",&dbv)) - { - ActualAccount=(HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)dbv.pszVal); - DBFreeVariant(&dbv); - } - else - ActualAccount = (HACCOUNT) hContact; - - if ((HACCOUNT)wParam!=ActualAccount) - break; - DestroyWindow(hWnd); - return 0; - } - case WM_NOTIFY: - default: - break; - } - return DefWindowProc(hWnd,msg,wParam,lParam); -} - -LRESULT CALLBACK NoNewMailPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) -{ - switch(msg) - { - case WM_COMMAND: - if ((HIWORD(wParam)==STN_CLICKED) && (msg==WM_COMMAND)) - { - HACCOUNT ActualAccount; - HANDLE hContact; - DBVARIANT dbv; - - hContact=(HANDLE)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); - - if (!DBGetContactSetting((HANDLE) hContact,YAMN_DBMODULE,"Id",&dbv)) - { - ActualAccount=(HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)dbv.pszVal); - DBFreeVariant(&dbv); - } - else - ActualAccount = (HACCOUNT) hContact; - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0==WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter\n"); - #endif - switch(msg) - { - case WM_COMMAND: - { - YAMN_MAILBROWSERPARAM Param={(HANDLE)0,ActualAccount,ActualAccount->NewMailN.Flags,ActualAccount->NoNewMailN.Flags,0}; - - 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; - - RunMailBrowserSvc((WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); - } - break; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - } - #ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter failed\n"); - #endif - SendMessageW(hWnd,UM_DESTROYPOPUP,0,0); - } - break; - - case WM_CONTEXTMENU: - SendMessageW(hWnd,UM_DESTROYPOPUP,0,0); - break; - - case UM_FREEPLUGINDATA: - //Here we'd free our own data, if we had it. - return FALSE; - case UM_INITPOPUP: - //This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups. - WindowList_Add(YAMNVar.MessageWnds,hWnd,NULL); - break; - case UM_DESTROYPOPUP: - WindowList_Remove(YAMNVar.MessageWnds,hWnd); - break; - case WM_YAMN_STOPACCOUNT: - { - HACCOUNT ActualAccount; - HANDLE hContact; - DBVARIANT dbv; - - hContact=(HANDLE)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); - - if (!DBGetContactSetting((HANDLE) hContact,YAMN_DBMODULE,"Id",&dbv)) - { - ActualAccount=(HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)dbv.pszVal); - DBFreeVariant(&dbv); - } - else - ActualAccount = (HACCOUNT) hContact; - - if ((HACCOUNT)wParam!=ActualAccount) - break; - - DestroyWindow(hWnd); - return 0; - } - case WM_NOTIFY: -/* switch(((LPNMHDR)lParam)->code) - { - case NM_CLICK: - { - } - } - break; -*/ default: - break; - } - return DefWindowProc(hWnd,msg,wParam,lParam); -} - -#ifdef __GNUC__ -//number of 100 ns periods between FILETIME 0 (1601/01/01 00:00:00.0000000) and TIMESTAMP 0 (1970/01/01 00:00:00) -#define NUM100NANOSEC 116444736000000000ULL -//The biggest time Get[Date|Time]Format can handle (Fri, 31 Dec 30827 23:59:59.9999999) -#define MAXFILETIME 0x7FFF35F4F06C7FFFULL -#else -#define NUM100NANOSEC 116444736000000000 -#define MAXFILETIME 0x7FFF35F4F06C7FFF -#endif - -ULONGLONG MimeDateToFileTime(char *datein) -{ - char *day=0, *month=0, *year=0, *time=0, *shift=0; - SYSTEMTIME st; - ULONGLONG res=0; - int wShiftSeconds = CallService(MS_DB_TIME_TIMESTAMPTOLOCAL,0,0); - GetLocalTime(&st); - //datein = "Xxx, 1 Jan 2060 5:29:1 +0530 XXX"; - //datein = "Xxx, 1 Jan 2060 05:29:10 "; - //datein = " ManySpaces 1.5 Jan 2060 05::"; - //datein = "Xxx, 35 February 20 :29:10 "; - //datein = "01.12.2007 (22:38:17)"; // - if (datein){ - char tmp [64]; - while ( datein[0]==' ') datein++; // eat leading spaces - strncpy(tmp,datein,63); tmp [63]=0; - if (atoi(tmp)) { // Parseable integer on DayOfWeek field? Buggy mime date. - day = tmp; - } else { - int i = 0; - while (tmp[i]==' ')i++; if (day = strchr(&tmp[i],' ')){day[0]=0; day++;} - } - if (day) {while ( day[0]==' ') day++;if (month= strchr(day, ' ')){month[0]=0; month++;}} - if (month) {while (month[0]==' ')month++;if (year = strchr(month,' ')) { year[0]=0; year++;}} - if (year) {while ( year[0]==' ') year++;if (time = strchr(year, ' ')) { time[0]=0; time++;}} - if (time) {while ( time[0]==' ') time++;if (shift= strchr(time, ' ')){shift[0]=0; shift++;shift[5]=0;}} - - if (year){ - st.wYear = atoi(year); - if (strlen(year)<4) if (st.wYear<70)st.wYear += 2000; else st.wYear += 1900; - }; - if (month) for (int i=0;i<12;i++) if (strncmp(month,s_MonthNames[i],3)==0) {st.wMonth = i + 1; break;} - if (day) st.wDay = atoi(day); - if (time) { - char *h, *m, *s; - h = time; - if (m = strchr(h,':')) { - m[0]=0; m++; - if (s = strchr(m,':')){s[0] = 0; s++;} - } else s=0; - st.wHour = atoi(h); - st.wMinute = m?atoi(m):0; - st.wSecond = s?atoi(s):0; - } else {st.wHour=st.wMinute=st.wSecond=0;} - - if (shift){ - if (strlen(shift)<4) { - //has only hour - wShiftSeconds = (atoi(shift))*3600; - } else { - char *smin = shift + strlen(shift)-2; - int ismin = atoi(smin); - smin[0] = 0; - int ishour = atoi(shift); - wShiftSeconds = (ishour*60+(ishour<0?-1:1)*ismin)*60; - } - } - } // if (datein) - FILETIME ft; - if (SystemTimeToFileTime(&st,&ft)) { - res = ((ULONGLONG)ft.dwHighDateTime<<32)|((ULONGLONG)ft.dwLowDateTime); - LONGLONG w100nano = Int32x32To64((DWORD)wShiftSeconds,10000000); - res -= w100nano; - }else{ - res=0; - } - return res; -} - -void FileTimeToLocalizedDateTime(LONGLONG filetime, WCHAR *dateout, int lendateout){ - int localeID = CallService(MS_LANGPACK_GETLOCALE,0,0); - //int localeID = MAKELCID(LANG_URDU, SORT_DEFAULT); - if (localeID==CALLSERVICE_NOTFOUND) localeID=LOCALE_USER_DEFAULT; - if (filetime>MAXFILETIME) filetime = MAXFILETIME; - else if (filetime<=0) { - wcsncpy(dateout,TranslateW(L"Invalid"),lendateout); - return; - } - SYSTEMTIME st; - WORD wTodayYear, wTodayMonth, wTodayDay; - FILETIME ft; - BOOL willShowDate = !(optDateTime&SHOWDATENOTODAY); - if (!willShowDate){ - GetLocalTime(&st); - wTodayYear = st.wYear; - wTodayMonth = st.wMonth; - wTodayDay = st.wDay; - } - ft.dwLowDateTime = (DWORD)filetime; - ft.dwHighDateTime = (DWORD)(filetime >> 32); - FILETIME localft; - if (!FileTimeToLocalFileTime(&ft,&localft)) { - // this should never happen - wcsncpy(dateout,L"Incorrect FileTime",lendateout); - } else { - if (!FileTimeToSystemTime(&localft,&st)) { - // this should never happen - wcsncpy(dateout,L"Incorrect LocalFileTime",lendateout); - } else { - dateout[lendateout-1]=0; - int templen = 0; - if (!willShowDate) willShowDate = (wTodayYear!=st.wYear)||(wTodayMonth!=st.wMonth)||(wTodayDay!=st.wDay); - if (willShowDate){ - templen = GetDateFormatW(localeID,(optDateTime&SHOWDATELONG)?DATE_LONGDATE:DATE_SHORTDATE,&st,NULL,dateout,lendateout-2); - dateout[templen-1] = ' '; - } - if (templen<(lendateout-1)) { - GetTimeFormatW(localeID,(optDateTime&SHOWDATENOSECONDS)?TIME_NOSECONDS:0,&st,NULL,&dateout[templen],lendateout-templen-1); - } - } - } -} - -void MimeDateToLocalizedDateTime(char *datein, WCHAR *dateout, int lendateout) -{ - ULONGLONG ft = MimeDateToFileTime(datein); - FileTimeToLocalizedDateTime(ft,dateout,lendateout); -} - -int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2,LPARAM lParamSort ) { - if (lParam1 == NULL || lParam2 == NULL) - return 0; - - int nResult = 0; - char *str1; - char *str2; - HYAMNMAIL email1 = (HYAMNMAIL)lParam1; - HYAMNMAIL email2 = (HYAMNMAIL)lParam2; - struct CShortHeader Header1; - struct CShortHeader Header2; - ZeroMemory(&Header1,sizeof(Header1)); - ZeroMemory(&Header2,sizeof(Header2)); - - try { - ExtractShortHeader(email1->MailData->TranslatedHeader,&Header1); - ExtractShortHeader(email2->MailData->TranslatedHeader,&Header2); - - switch((int)lParamSort) - { - case 0: //From - if (Header1.FromNick == NULL) - str1 = Header1.From; - else str1 = Header1.FromNick; - - if (Header2.FromNick == NULL) - str2 = Header2.From; - else str2 = Header2.FromNick; - - nResult = strcmp(str1, str2); - - if (bFrom) nResult = -nResult; - break; - case 1: //Subject - if (Header1.Subject == NULL) - str1 = " "; - else str1 = Header1.Subject; - - if (Header2.Subject == NULL) - str2 = " "; - else str2 = Header2.Subject; - - nResult = strcmp(str1, str2); - - if (bSub) nResult = -nResult; - break; - case 2: //Size - if (email1->MailData->Size == email2->MailData->Size) nResult = 0; - if (email1->MailData->Size > email2->MailData->Size) nResult = 1; - if (email1->MailData->Size < email2->MailData->Size) nResult = -1; - - if (bSize) nResult = -nResult; - break; - - case 3: //Date - { - ULONGLONG ts1 = 0, ts2 = 0; - ts1 = MimeDateToFileTime(Header1.Date); - ts2 = MimeDateToFileTime(Header2.Date); - if (ts1 > ts2) nResult = 1; - else if (ts1 < ts2) nResult = -1; - else nResult = 0; - } - if (bDate) nResult = -nResult; - break; - - default: - if (Header1.Subject == NULL) str1 = " "; - else str1 = Header1.Subject; - - if (Header2.Subject == NULL) str2 = " "; - else str2 = Header2.Subject; - - nResult = strcmp(str1, str2); - break; - } - //MessageBox(NULL,str1,str2,0); - } - catch( ... ) - { - } - - //free mem - DeleteShortHeaderContent(&Header1); - DeleteShortHeaderContent(&Header2); - return nResult; - -} - -HCURSOR hCurSplitNS, hCurSplitWE; -static WNDPROC OldSplitterProc; -#define DM_SPLITTERMOVED (WM_USER+15) -static LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) { - case WM_NCHITTEST: - return HTCLIENT; - case WM_SETCURSOR: - { - SetCursor(hCurSplitNS); - return TRUE; - } - case WM_LBUTTONDOWN: - SetCapture(hwnd); - return 0; - case WM_MOUSEMOVE: - if (GetCapture() == hwnd) { - RECT rc; - GetClientRect(hwnd, &rc); - SendMessage(GetParent(hwnd), DM_SPLITTERMOVED, (short) HIWORD(GetMessagePos()) + rc.bottom / 2, (LPARAM) hwnd); - } - return 0; - case WM_LBUTTONUP: - ReleaseCapture(); - return 0; - } - return CallWindowProc(OldSplitterProc, hwnd, msg, wParam, lParam); -} - - -void ConvertCodedStringToUnicode(char *stream,WCHAR **storeto,DWORD cp,int mode); -int ConvertStringToUnicode(char *stream,unsigned int cp,WCHAR **out); -INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - switch(msg) - { - case WM_INITDIALOG: - { -// HIMAGELIST hIcons; - PYAMN_MAILSHOWPARAM MailParam = (PYAMN_MAILSHOWPARAM)lParam; - WCHAR *iHeaderW=NULL; - WCHAR *iValueW=NULL; - int StrLen; - HWND hListView = GetDlgItem(hDlg,IDC_LISTHEADERS); - OldSplitterProc = (WNDPROC) SetWindowLongPtr(GetDlgItem(hDlg, IDC_SPLITTER), GWLP_WNDPROC, (LONG_PTR) SplitterSubclassProc); - SetWindowLongPtr(hDlg,DWLP_USER,(LONG_PTR)MailParam); - SendMessageW(hDlg,WM_SETICON,(WPARAM)ICON_BIG,(LPARAM)g_LoadIconEx(2, true)); - SendMessageW(hDlg,WM_SETICON,(WPARAM)ICON_SMALL,(LPARAM)g_LoadIconEx(2)); - - ListView_SetUnicodeFormat(hListView,TRUE); - ListView_SetExtendedListViewStyle(hListView,LVS_EX_FULLROWSELECT); - - StrLen=MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,Translate("Header"),-1,NULL,0); - iHeaderW=new WCHAR[StrLen+1]; - MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,Translate("Header"),-1,iHeaderW,StrLen); - - StrLen=MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,Translate("Value"),-1,NULL,0); - iValueW=new WCHAR[StrLen+1]; - MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,Translate("Value"),-1,iValueW,StrLen); - - LVCOLUMNW lvc0={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,130,iHeaderW,0,0}; - LVCOLUMNW lvc1={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,400,iValueW,0,0}; - SendMessageW(hListView,LVM_INSERTCOLUMNW,(WPARAM)0,(LPARAM)&lvc0); - SendMessageW(hListView,LVM_INSERTCOLUMNW,(WPARAM)1,(LPARAM)&lvc1); - if (NULL!=iHeaderW) - delete[] iHeaderW; - if (NULL!=iValueW) - delete[] iValueW; - - //WindowList_Add(YAMNVar.MessageWnds,hDlg,NULL); - //WindowList_Add(YAMNVar.NewMailAccountWnd,hDlg,ActualAccount); - SendMessage(hDlg,WM_YAMN_CHANGECONTENT,0,(LPARAM)MailParam); - MoveWindow(hDlg,HeadPosX,HeadPosY,HeadSizeX,HeadSizeY,0); - ShowWindow(hDlg,SW_SHOWNORMAL); - break; - } - case WM_YAMN_CHANGECONTENT: - { - PYAMN_MAILSHOWPARAM MailParam = (PYAMN_MAILSHOWPARAM) - (lParam?lParam:GetWindowLongPtr(hDlg,DWLP_USER)); - HWND hListView = GetDlgItem(hDlg,IDC_LISTHEADERS); - HWND hEdit = GetDlgItem(hDlg,IDC_EDITBODY); - //do not redraw - SendMessage(hListView, WM_SETREDRAW, 0, 0); - ListView_DeleteAllItems(hListView); - struct CMimeItem *Header; - LVITEMW item; - item.mask=LVIF_TEXT | LVIF_PARAM; - WCHAR *From=0,*Subj=0; - char *contentType=0, *transEncoding=0, *body=0; //should not be delete[]-ed - for (Header=MailParam->mail->MailData->TranslatedHeader;Header!=NULL;Header=Header->Next) - { - WCHAR *str1 = 0; - WCHAR *str2 = 0; - if (!body) if (!_stricmp(Header->name,"Body")) {body = Header->value; continue;} - if (!contentType) if (!_stricmp(Header->name,"Content-Type")) contentType = Header->value; - if (!transEncoding) if (!_stricmp(Header->name,"Content-Transfer-Encoding")) transEncoding = Header->value; - //ConvertCodedStringToUnicode(Header->name,&str1,MailParam->mail->MailData->CP,1); - { - int streamsize = MultiByteToWideChar(20127,0,Header->name,-1,NULL,0); - str1 = new WCHAR[streamsize+1]; - MultiByteToWideChar(20127,0,Header->name,-1,str1,streamsize);//US-ASCII - } - ConvertCodedStringToUnicode(Header->value,&str2,MailParam->mail->MailData->CP,1); - if (!str2) { str2 = (WCHAR *)malloc(2); str2[0] = 0; }// the header value may be NULL - if (!From) if (!_stricmp(Header->name,"From")) { - From =new WCHAR[wcslen(str2)+1]; - wcscpy(From,str2); - } - if (!Subj) if (!_stricmp(Header->name,"Subject")) { - Subj =new WCHAR[wcslen(str2)+1]; - wcscpy(Subj,str2); - } - //if (!hasBody) if (!strcmp(Header->name,"Body")) hasBody = true; - int count = 0; WCHAR **split=0; - if (str2){ - int ofs = 0; - while (str2[ofs]) { - if ((str2[ofs]==0x266A)||(str2[ofs]==0x25D9)||(str2[ofs]==0x25CB)|| - (str2[ofs]==0x09)||(str2[ofs]==0x0A)||(str2[ofs]==0x0D))count++; - ofs++; - } - split=new WCHAR*[count+1]; - count=0; ofs=0; - split[0]=str2; - while (str2[ofs]) { - if ((str2[ofs]==0x266A)||(str2[ofs]==0x25D9)||(str2[ofs]==0x25CB)|| - (str2[ofs]==0x09)||(str2[ofs]==0x0A)||(str2[ofs]==0x0D)) { - if (str2[ofs-1]) { - count++; - } - split[count]=(WCHAR *)(str2+ofs+1); - str2[ofs]=0; - } - ofs++; - }; - } - if (!_stricmp(Header->name,"From")||!_stricmp(Header->name,"To")||!_stricmp(Header->name,"Date")||!_stricmp(Header->name,"Subject")) - item.iItem = 0; - else - item.iItem = 999; - for (int i=0;i<=count;i++) { - item.iSubItem=0; - if (i==0) - item.pszText=str1; - else { - item.iItem++; - item.pszText=0; - } - item.iItem=SendMessageW(hListView,LVM_INSERTITEMW,(WPARAM)0,(LPARAM)&item); - item.iSubItem=1; - item.pszText=str2?split[i]:0; - SendMessageW(hListView,LVM_SETITEMTEXTW,(WPARAM)item.iItem,(LPARAM)&item); - } - if (split)delete[] split; - - if (str1) free(str1); - if (str2) free(str2); - } - if (body){ - WCHAR *bodyDecoded = 0; - char *localBody=0; - if (contentType) { - if (!_strnicmp(contentType,"text",4)) { - if (transEncoding){ - if (!_stricmp(transEncoding,"base64")) { - int size = (int)strlen(body)*3/4+5; - localBody = new char[size+1]; - DecodeBase64(body,localBody,size); - } else if (!_stricmp(transEncoding,"quoted-printable")) { - int size = (int)strlen(body)+2; - localBody = new char[size+1]; - DecodeQuotedPrintable(body,localBody,size,FALSE); - } - } - } else if (!_strnicmp(contentType,"multipart/",10)) { - char *bondary=NULL; - if (NULL!=(bondary=ExtractFromContentType(contentType,"boundary="))) - { - bodyDecoded = ParseMultipartBody(body,bondary); - delete[] bondary; - } - } - } - if (!bodyDecoded)ConvertStringToUnicode(localBody?localBody:body,MailParam->mail->MailData->CP,&bodyDecoded); - SendMessageW(hEdit,WM_SETTEXT,(WPARAM)0,(LPARAM)bodyDecoded); - delete[] bodyDecoded; - if (localBody) delete[] localBody; - SetFocus(hEdit); - } - if (!(MailParam->mail->Flags & YAMN_MSG_BODYRECEIVED)) { - MailParam->mail->Flags |= YAMN_MSG_BODYREQUESTED; - CallService(MS_YAMN_ACCOUNTCHECK,(WPARAM)MailParam->account,0); - } else { - if (MailParam->mail->Flags & YAMN_MSG_UNSEEN){ - MailParam->mail->Flags&=~YAMN_MSG_UNSEEN; //mark the message as seen - HWND hMailBrowser; - if (hMailBrowser=WindowList_Find(YAMNVar.NewMailAccountWnd,MailParam->account)) { - struct CChangeContent Params={MailParam->account->NewMailN.Flags|YAMN_ACC_MSGP,MailParam->account->NoNewMailN.Flags|YAMN_ACC_MSGP}; - SendMessageW(hMailBrowser,WM_YAMN_CHANGECONTENT,(WPARAM)MailParam->account,(LPARAM)&Params); - } else { - UpdateMails(NULL,MailParam->account,MailParam->account->NewMailN.Flags,MailParam->account->NoNewMailN.Flags); - } - } - } - ShowWindow(GetDlgItem(hDlg, IDC_SPLITTER),(MailParam->mail->Flags & YAMN_MSG_BODYRECEIVED)?SW_SHOW:SW_HIDE); - ShowWindow(hEdit,(MailParam->mail->Flags & YAMN_MSG_BODYRECEIVED)?SW_SHOW:SW_HIDE); - WCHAR *title=0; - title = new WCHAR[(From?wcslen(From):0)+(Subj?wcslen(Subj):0)+4]; - if (From&&Subj) wsprintfW(title,L"%s (%s)",Subj,From); - else if (From)wsprintfW(title,L"%s",From); - else if (Subj)wsprintfW(title,L"%s",Subj); - else wsprintfW(title,L"none"); - if (Subj) delete[] Subj; - if (From) delete[] From; - SendMessageW(hDlg,WM_SETTEXT,(WPARAM)0,(LPARAM)title); - delete[] title; - // turn on redrawing - SendMessage(hListView, WM_SETREDRAW, 1, 0); - SendMessage(hDlg, WM_SIZE, 0, HeadSizeY<<16|HeadSizeX); - } break; - case WM_YAMN_STOPACCOUNT: - { - PYAMN_MAILSHOWPARAM MailParam = (PYAMN_MAILSHOWPARAM) - (lParam?lParam:GetWindowLongPtr(hDlg,DWLP_USER)); - - if (NULL==MailParam) - break; - if ((HACCOUNT)wParam!=MailParam->account) - break; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ShowMessage:STOPACCOUNT:sending destroy msg\n"); - #endif - DestroyWindow(hDlg); - } - return 1; - case WM_CTLCOLORSTATIC: - //here should be check if this is our edittext control. - //but we have only one static control (for now); - SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); - SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT)); - return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);; - case WM_DESTROY: - { - RECT coord; - if (GetWindowRect(hDlg,&coord)) - { - HeadPosX=coord.left; - HeadSizeX=coord.right-coord.left; - HeadPosY=coord.top; - HeadSizeY=coord.bottom-coord.top; - } - - PostQuitMessage(1); - } - break; - case WM_SYSCOMMAND: - { - switch(wParam) - { - case SC_CLOSE: - DestroyWindow(hDlg); - break; - } - } - break; - case WM_MOVE: - HeadPosX=LOWORD(lParam); //((LPRECT)lParam)->right-((LPRECT)lParam)->left; - HeadPosY=HIWORD(lParam); //((LPRECT)lParam)->bottom-((LPRECT)lParam)->top; - return 0; - case DM_SPLITTERMOVED: - { - if ((HWND) lParam == GetDlgItem(hDlg, IDC_SPLITTER)) { - POINT pt; - pt.x = 0; - pt.y = wParam; - ScreenToClient(hDlg, &pt); - HeadSplitPos = (pt.y*1000)/HeadSizeY;//+rc.bottom-rc.top; - if (HeadSplitPos>=1000) HeadSplitPos = 999; - else if (HeadSplitPos<=0) HeadSplitPos = 1; - else SendMessage(hDlg, WM_SIZE, 0, HeadSizeY<<16|HeadSizeX); - } - return 0; - } - case WM_SIZE: - if (wParam==SIZE_RESTORED) - { - HWND hList = GetDlgItem(hDlg,IDC_LISTHEADERS); - HWND hEdit = GetDlgItem(hDlg,IDC_EDITBODY); - BOOL changeX = LOWORD(lParam)!=HeadSizeX; - BOOL isBodyShown = ((PYAMN_MAILSHOWPARAM)(GetWindowLongPtr(hDlg,DWLP_USER)))->mail->Flags & YAMN_MSG_BODYRECEIVED; - HeadSizeX=LOWORD(lParam); //((LPRECT)lParam)->right-((LPRECT)lParam)->left; - HeadSizeY=HIWORD(lParam); //((LPRECT)lParam)->bottom-((LPRECT)lParam)->top; - int localSplitPos = (HeadSplitPos*HeadSizeY)/1000; - int localSizeX; - RECT coord; - MoveWindow(GetDlgItem(hDlg,IDC_SPLITTER),5,localSplitPos,HeadSizeX-10,2,TRUE); - MoveWindow(hEdit,5,localSplitPos+6,HeadSizeX-10,HeadSizeY-localSplitPos-11,TRUE); //where to put text window while resizing - MoveWindow(hList, 5 ,5 ,HeadSizeX-10 ,(isBodyShown?localSplitPos:HeadSizeY)-10,TRUE); //where to put headers list window while resizing - //if (changeX){ - if (GetClientRect(hList,&coord)) { - localSizeX=coord.right-coord.left; - } else localSizeX=HeadSizeX; - LONG iNameWidth = ListView_GetColumnWidth(hList,0); - ListView_SetColumnWidth(hList,1,(localSizeX<=iNameWidth)?0:(localSizeX-iNameWidth)); - //} - } -// break; - return 0; - case WM_CONTEXTMENU: - { - if ( GetWindowLongPtr(( HWND )wParam, GWLP_ID ) == IDC_LISTHEADERS) { - //MessageBox(0,"LISTHEADERS","Debug",0); - HWND hList = GetDlgItem( hDlg, IDC_LISTHEADERS ); - POINT pt = { (signed short)LOWORD( lParam ), (signed short)HIWORD( lParam ) }; - HTREEITEM hItem = 0; - if (pt.x==-1) pt.x = 0; - if (pt.y==-1) pt.y = 0; - if (int numRows = ListView_GetItemCount(hList)) { - HMENU hMenu = CreatePopupMenu(); - AppendMenu(hMenu, MF_STRING, (UINT_PTR)1, TranslateT("Copy Selected")); - AppendMenu(hMenu, MF_STRING, (UINT_PTR)2, TranslateT("Copy All")); - AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); - AppendMenu(hMenu, MF_STRING, (UINT_PTR)0, TranslateT("Cancel")); - int nReturnCmd = TrackPopupMenu( hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hDlg, NULL ); - DestroyMenu( hMenu ); - if (nReturnCmd>0){ - int courRow=0; - size_t sizeNeeded = 0; - TCHAR headname[64]={0}, headvalue[256]={0}; - for (courRow=0; courRow < numRows; courRow++) { - if ((nReturnCmd==1) && (ListView_GetItemState(hList, courRow, LVIS_SELECTED)==0)) continue; - ListView_GetItemText(hList, courRow, 0, headname, SIZEOF(headname)); - ListView_GetItemText(hList, courRow, 1, headvalue, SIZEOF(headvalue)); - size_t headnamelen = _tcslen(headname); - if (headnamelen) sizeNeeded += 1 + headnamelen; - sizeNeeded += 3 + _tcslen(headvalue); - } - if (sizeNeeded && OpenClipboard(hDlg)) { - EmptyClipboard(); - HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE,(sizeNeeded+1)*sizeof(TCHAR)); - TCHAR *buff = ( TCHAR* )GlobalLock(hData); - int courPos = 0; - for (courRow=0;courRowUsingThreads,MyParam.account); - #endif - SCIncFcn(MyParam.account->UsingThreads); - SetEvent(MyParam.ThreadRunningEV); - if (MyParam.mail->MsgWindow){ - //if (!BringWindowToTop(MyParam.mail->MsgWindow)) { - if (!SetForegroundWindow(MyParam.mail->MsgWindow)) { - SendMessage(MyParam.mail->MsgWindow,WM_DESTROY,0,0); - MyParam.mail->MsgWindow = 0; - goto CREADTEVIEWMESSAGEWINDOW; - }else{ - if (IsIconic(MyParam.mail->MsgWindow)) { - OpenIcon(MyParam.mail->MsgWindow); - } - } - } else { -CREADTEVIEWMESSAGEWINDOW: - MyParam.mail->MsgWindow = CreateDialogParamW(YAMNVar.hInst,MAKEINTRESOURCEW(IDD_DLGSHOWMESSAGE),NULL,DlgProcYAMNShowMessage,(LPARAM)&MyParam); - WindowList_Add(YAMNVar.MessageWnds,MyParam.mail->MsgWindow,NULL); - MSG msg; - while(GetMessage(&msg,NULL,0,0)) { - if (!IsDialogMessage(MyParam.mail->MsgWindow, &msg)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } } - WindowList_Remove(YAMNVar.MessageWnds,MyParam.mail->MsgWindow); - MyParam.mail->MsgWindow = NULL; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"ShowMessage:Decrementing \"using threads\" %x (account %x)\n",MyParam.account->UsingThreads,MyParam.account); - #endif - SCDecFcn(MyParam.account->UsingThreads); - delete Param; - return 1; -} - -INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - switch(msg) - { - case WM_INITDIALOG: - { - HACCOUNT ActualAccount; - struct MailBrowserWinParam *MyParam=(struct MailBrowserWinParam *)lParam; - struct CMailWinUserInfo *mwui; - - ListView_SetUnicodeFormat(GetDlgItem(hDlg,IDC_LISTMAILS),TRUE); - ListView_SetExtendedListViewStyle(GetDlgItem(hDlg,IDC_LISTMAILS),LVS_EX_FULLROWSELECT); - - ActualAccount=MyParam->account; - mwui=new struct CMailWinUserInfo; - mwui->Account=ActualAccount; - mwui->TrayIconState=0; - mwui->UpdateMailsMessagesAccess=FALSE; - mwui->Seen=FALSE; - mwui->RunFirstTime=TRUE; - - SetWindowLongPtr(hDlg,DWLP_USER,(LONG_PTR)mwui); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:INIT:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:INIT:ActualAccountSO-read enter failed\n"); - #endif - DestroyWindow(hDlg); - return FALSE; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:INIT:ActualAccountSO-read enter\n"); - #endif - - SendMessageW(GetDlgItem(hDlg,IDC_BTNAPP),WM_SETTEXT,(WPARAM)0,(LPARAM)TranslateW(L"Run application")); - SendMessageW(GetDlgItem(hDlg,IDC_BTNDEL),WM_SETTEXT,(WPARAM)0,(LPARAM)TranslateW(L"Delete selected")); - SendMessageW(GetDlgItem(hDlg,IDC_BTNCHECKALL),WM_SETTEXT,(WPARAM)0,(LPARAM)TranslateW(L"Select All")); - SendMessageW(GetDlgItem(hDlg,IDC_BTNOK),WM_SETTEXT,(WPARAM)0,(LPARAM)TranslateW(L"OK")); - - LVCOLUMNW lvc0={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,FromWidth,TranslateW(L"From"),0,0}; - LVCOLUMNW lvc1={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,SubjectWidth,TranslateW(L"Subject"),0,0}; - LVCOLUMNW lvc2={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,SizeWidth,TranslateW(L"Size"),0,0}; - LVCOLUMNW lvc3={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,SizeDate,TranslateW(L"Date"),0,0}; - SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_INSERTCOLUMNW,(WPARAM)0,(LPARAM)&lvc0); - SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_INSERTCOLUMNW,(WPARAM)1,(LPARAM)&lvc1); - SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_INSERTCOLUMNW,(WPARAM)2,(LPARAM)&lvc2); - SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_INSERTCOLUMNW,(WPARAM)3,(LPARAM)&lvc3); - - if ((ActualAccount->NewMailN.App!=NULL) && (wcslen(ActualAccount->NewMailN.App))) - EnableWindow(GetDlgItem(hDlg,IDC_BTNAPP),(WPARAM)TRUE); - else - EnableWindow(GetDlgItem(hDlg,IDC_BTNAPP),(WPARAM)FALSE); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:INIT:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - - WindowList_Add(YAMNVar.MessageWnds,hDlg,NULL); - WindowList_Add(YAMNVar.NewMailAccountWnd,hDlg,ActualAccount); - - { - TCHAR accstatus[512]; - GetStatusFcn(ActualAccount,accstatus); - SetDlgItemText(hDlg,IDC_STSTATUS,accstatus); - } - SetTimer(hDlg,TIMER_FLASHING,500,NULL); - - if (ActualAccount->hContact != NULL) - { - CallService(MS_CLIST_REMOVEEVENT,(WPARAM)ActualAccount->hContact,(LPARAM)"yamn new mail message"); - } - - OldListViewSubclassProc = (WNDPROC) SetWindowLongPtr(GetDlgItem(hDlg, IDC_LISTMAILS), GWLP_WNDPROC, (LONG_PTR) ListViewSubclassProc); - - break; - } - case WM_DESTROY: - { - HACCOUNT ActualAccount; - RECT coord; - LVCOLUMNW ColInfo; - NOTIFYICONDATA nid; - HYAMNMAIL Parser; - struct CMailWinUserInfo *mwui; - - mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER); - if (NULL==(ActualAccount=GetWindowAccount(hDlg))) - break; - ColInfo.mask=LVCF_WIDTH; - if (ListView_GetColumn(GetDlgItem(hDlg,IDC_LISTMAILS),0,&ColInfo)) - FromWidth=ColInfo.cx; - if (ListView_GetColumn(GetDlgItem(hDlg,IDC_LISTMAILS),1,&ColInfo)) - SubjectWidth=ColInfo.cx; - if (ListView_GetColumn(GetDlgItem(hDlg,IDC_LISTMAILS),2,&ColInfo)) - SizeWidth=ColInfo.cx; - if (ListView_GetColumn(GetDlgItem(hDlg,IDC_LISTMAILS),3,&ColInfo)) - SizeDate=ColInfo.cx; - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DESTROY:save window position\n"); - #endif - if (!YAMNVar.Shutdown && GetWindowRect(hDlg,&coord)) //the YAMNVar.Shutdown testing is because MMessagesAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DESTROY:ActualAccountMsgsSO-write wait failed\n"); - #endif - break; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DESTROY:ActualAccountMsgsSO-write enter\n"); - #endif - //delete mails from queue, which are deleted from server (spam level 3 mails e.g.) - for (Parser=(HYAMNMAIL)ActualAccount->Mails;Parser!=NULL;Parser=Parser->Next) - { - if ((Parser->Flags & YAMN_MSG_DELETED) && YAMN_MSG_SPAML(Parser->Flags,YAMN_MSG_SPAML3) && mwui->Seen) //if spaml3 was already deleted and user knows about it - { - DeleteMessageFromQueueFcn((HYAMNMAIL *)&ActualAccount->Mails,Parser,1); - CallService(MS_YAMN_DELETEACCOUNTMAIL,(WPARAM)ActualAccount->Plugin,(LPARAM)Parser); - } - } - - //mark mails as read (remove "new" and "unseen" flags) - if (mwui->Seen) - SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails,YAMN_MSG_DISPLAY,0,YAMN_MSG_NEW | YAMN_MSG_UNSEEN,0); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DESTROY:ActualAccountMsgsSO-write done\n"); - #endif - WriteDoneFcn(ActualAccount->MessagesAccessSO); - - ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); - - delete mwui; - SetWindowLongPtr(hDlg,DWLP_USER,(LONG_PTR)NULL); - - nid.cbSize=sizeof(NOTIFYICONDATA); - nid.hWnd=hDlg; - nid.uID=0; - Shell_NotifyIcon(NIM_DELETE,&nid); - PostQuitMessage(0); - } - break; - case WM_SHOWWINDOW: - { - struct CMailWinUserInfo *mwui; - - if (NULL==(mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER))) - return 0; - mwui->Seen=TRUE; - } - case WM_YAMN_CHANGESTATUS: - { - HACCOUNT ActualAccount; - if (NULL==(ActualAccount=GetWindowAccount(hDlg))) - break; - - if ((HACCOUNT)wParam!=ActualAccount) - break; - - TCHAR accstatus[512]; - GetStatusFcn(ActualAccount,accstatus); - SetDlgItemText(hDlg,IDC_STSTATUS,accstatus); - } - return 1; - case WM_YAMN_CHANGECONTENT: - { - struct CUpdateMails UpdateParams; - BOOL ThisThreadWindow=(GetCurrentThreadId()==GetWindowThreadProcessId(hDlg,NULL)); - - if (NULL==(UpdateParams.Copied=CreateEvent(NULL,FALSE,FALSE,NULL))) - { - DestroyWindow(hDlg); - return 0; - } - UpdateParams.Flags=(struct CChangeContent *)lParam; - UpdateParams.Waiting=!ThisThreadWindow; - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:CHANGECONTENT:posting UPDATEMAILS\n"); - #endif - if (ThisThreadWindow) - { - if (!UpdateMails(hDlg,(HACCOUNT)wParam,UpdateParams.Flags->nflags,UpdateParams.Flags->nnflags)) - DestroyWindow(hDlg); - } - else if (PostMessage(hDlg,WM_YAMN_UPDATEMAILS,wParam,(LPARAM)&UpdateParams)) //this ensures UpdateMails will execute the thread who created the browser window - { - if (!ThisThreadWindow) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:CHANGECONTENT:waiting for event\n"); - #endif - WaitForSingleObject(UpdateParams.Copied,INFINITE); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:CHANGECONTENT:event signaled\n"); - #endif - } - } - - CloseHandle(UpdateParams.Copied); - } - return 1; - case WM_YAMN_UPDATEMAILS: - { - HACCOUNT ActualAccount; - - struct CUpdateMails *um=(struct CUpdateMails *)lParam; - DWORD nflags,nnflags; - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:UPDATEMAILS\n"); - #endif - - if (NULL==(ActualAccount=GetWindowAccount(hDlg))) - return 0; - if ((HACCOUNT)wParam!=ActualAccount) - return 0; - - nflags=um->Flags->nflags; - nnflags=um->Flags->nnflags; - - if (um->Waiting) - SetEvent(um->Copied); - - if (!UpdateMails(hDlg,ActualAccount,nflags,nnflags)) - DestroyWindow(hDlg); - } - return 1; - case WM_YAMN_STOPACCOUNT: - { - HACCOUNT ActualAccount; - - if (NULL==(ActualAccount=GetWindowAccount(hDlg))) - break; - if ((HACCOUNT)wParam!=ActualAccount) - break; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:STOPACCOUNT:sending destroy msg\n"); - #endif - PostQuitMessage(0); - } - return 1; - case WM_YAMN_NOTIFYICON: - { - HACCOUNT ActualAccount; - if (NULL==(ActualAccount=GetWindowAccount(hDlg))) - break; - - switch(lParam) - { - case WM_LBUTTONDBLCLK: - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DBLCLICKICON:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DBLCLICKICON:ActualAccountSO-read wait failed\n"); - #endif - return 0; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DBLCLICKICON:ActualAccountSO-read enter\n"); - #endif - if (ActualAccount->AbilityFlags & YAMN_ACC_BROWSE) - { - ShowWindow(hDlg,SW_SHOWNORMAL); - SetForegroundWindow(hDlg); - } - else - DestroyWindow(hDlg); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DBLCLICKICON:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - break; - } - break; - } - case WM_YAMN_SHOWSELECTED: - { - int iSelect; - iSelect=SendMessage(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_GETNEXTITEM,-1,MAKELPARAM((UINT)LVNI_FOCUSED,0)); // return item selected - - if (iSelect!=-1) - { - LV_ITEMW item; - HYAMNMAIL ActualMail; - - item.iItem=iSelect; - item.iSubItem=0; - item.mask=LVIF_PARAM | LVIF_STATE; - item.stateMask=0xFFFFFFFF; - ListView_GetItem(GetDlgItem(hDlg,IDC_LISTMAILS),&item); - ActualMail=(HYAMNMAIL)item.lParam; - if (NULL!=ActualMail) - { - //ShowEmailThread - PYAMN_MAILSHOWPARAM MailParam = new YAMN_MAILSHOWPARAM; - MailParam->account = GetWindowAccount(hDlg); - MailParam->mail = ActualMail; - if (NULL!=(MailParam->ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) { - HANDLE NewThread; - if (NULL!=(NewThread=CreateThread(NULL,0,ShowEmailThread,MailParam,0,NULL))) - { - //WaitForSingleObject(MailParam->ThreadRunningEV,INFINITE); - CloseHandle(NewThread); - } - CloseHandle(MailParam->ThreadRunningEV); - } - //delete MailParam; - } - } - } break; - case WM_SYSCOMMAND: - { - HACCOUNT ActualAccount; - - if (NULL==(ActualAccount=GetWindowAccount(hDlg))) - break; - switch(wParam) - { - case SC_CLOSE: - DestroyWindow(hDlg); - break; - } - } - break; - - case WM_COMMAND: - { - HACCOUNT ActualAccount; - int Items; - - if (NULL==(ActualAccount=GetWindowAccount(hDlg))) - break; - - switch(LOWORD(wParam)) - { - case IDC_BTNCHECKALL: - ListView_SetItemState(GetDlgItem(hDlg,IDC_LISTMAILS), -1, 0, LVIS_SELECTED); // deselect all items - ListView_SetItemState(GetDlgItem(hDlg,IDC_LISTMAILS),-1, LVIS_SELECTED ,LVIS_SELECTED); - Items = ListView_GetItemCount(GetDlgItem(hDlg,IDC_LISTMAILS)); - ListView_RedrawItems(GetDlgItem(hDlg,IDC_LISTMAILS), 0, Items); - UpdateWindow(GetDlgItem(hDlg,IDC_LISTMAILS)); - SetFocus(GetDlgItem(hDlg,IDC_LISTMAILS)); - break; - - case IDC_BTNOK: - DestroyWindow(hDlg); - break; - - case IDC_BTNAPP: - { - PROCESS_INFORMATION pi; - STARTUPINFOW si; - - ZeroMemory(&si,sizeof(si)); - si.cb=sizeof(si); - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0==WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read enter\n"); - #endif - if (ActualAccount->NewMailN.App!=NULL) - { - WCHAR *Command; - if (ActualAccount->NewMailN.AppParam!=NULL) - Command=new WCHAR[wcslen(ActualAccount->NewMailN.App)+wcslen(ActualAccount->NewMailN.AppParam)+6]; - else - Command=new WCHAR[wcslen(ActualAccount->NewMailN.App)+6]; - - if (Command!=NULL) - { - lstrcpyW(Command,L"\""); - lstrcatW(Command,ActualAccount->NewMailN.App); - lstrcatW(Command,L"\" "); - if (ActualAccount->NewMailN.AppParam!=NULL) - lstrcatW(Command,ActualAccount->NewMailN.AppParam); - CreateProcessW(NULL,Command,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); - delete[] Command; - } - } - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - } - #ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read enter failed\n"); - #endif - if (!(GetKeyState(VK_SHIFT) & 0x8000) && !(GetKeyState(VK_CONTROL) & 0x8000)) - DestroyWindow(hDlg); - - } - break; - case IDC_BTNDEL: - { - LVITEMW item; - HYAMNMAIL FirstMail=NULL,ActualMail; - HANDLE ThreadRunningEV; - DWORD tid,Total=0; - - // we use event to signal, that running thread has all needed stack parameters copied - if (NULL==(ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) - break; - int Items=ListView_GetItemCount(GetDlgItem(hDlg,IDC_LISTMAILS)); - - item.stateMask=0xFFFFFFFF; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write wait\n"); - #endif - if (WAIT_OBJECT_0==WaitToWriteFcn(ActualAccount->MessagesAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write enter\n"); - #endif - for (int i=0;iFlags|=YAMN_MSG_USERDELETE; //set to mail we are going to delete it - Total++; - } - } - - // Enable write-access to mails - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write done\n"); - #endif - WriteDoneFcn(ActualAccount->MessagesAccessSO); - - if (Total) - { - TCHAR DeleteMsg[1024]; - - wsprintf(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,NULL}; - - // Find if there's mail marked to delete, which was deleted before - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write wait\n"); - #endif - if (WAIT_OBJECT_0==WaitToWriteFcn(ActualAccount->MessagesAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write enter\n"); - #endif - for (ActualMail=(HYAMNMAIL)ActualAccount->Mails;ActualMail!=NULL;ActualMail=ActualMail->Next) - { - if ((ActualMail->Flags & YAMN_MSG_DELETED) && ((ActualMail->Flags & YAMN_MSG_USERDELETE))) //if selected mail was already deleted - { - DeleteMessageFromQueueFcn((HYAMNMAIL *)&ActualAccount->Mails,ActualMail,1); - CallService(MS_YAMN_DELETEACCOUNTMAIL,(WPARAM)ActualAccount->Plugin,(LPARAM)ActualMail); //delete it from memory - 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; - - if (NULL!=(NewThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ActualAccount->Plugin->Fcn->DeleteMailsFcnPtr,(LPVOID)&ParamToDeleteMails,0,&tid))) - { - WaitForSingleObject(ThreadRunningEV,INFINITE); - CloseHandle(NewThread); - } - // Enable write-access to mails - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write done\n"); - #endif - WriteDoneFcn(ActualAccount->MessagesAccessSO); - } - } - else - //else mark messages that they are not to be deleted - SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails,YAMN_MSG_DISPLAY | YAMN_MSG_USERDELETE,0,YAMN_MSG_USERDELETE,0); - } - } - CloseHandle(ThreadRunningEV); - if (DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_CLOSEDELETE, 0)) - DestroyWindow(hDlg); - - } - break; - } - } - break; - case WM_SIZE: - if (wParam==SIZE_RESTORED) - { - LONG x=LOWORD(lParam); //((LPRECT)lParam)->right-((LPRECT)lParam)->left; - LONG y=HIWORD(lParam); //((LPRECT)lParam)->bottom-((LPRECT)lParam)->top; - MoveWindow(GetDlgItem(hDlg,IDC_BTNDEL), 5 ,y-5-25,(x-20)/3,25,TRUE); //where to put DELETE button while resizing - MoveWindow(GetDlgItem(hDlg,IDC_BTNCHECKALL),10+ (x-20)/3,y-5-25,(x-20)/6,25,TRUE); //where to put CHECK ALL button while resizing - MoveWindow(GetDlgItem(hDlg,IDC_BTNAPP), 15+ (x-20)/3 + (x-20)/6,y-5-25,(x-20)/3,25,TRUE); //where to put RUN APP button while resizing - MoveWindow(GetDlgItem(hDlg,IDC_BTNOK), 20+2*(x-20)/3 + (x-20)/6 ,y-5-25,(x-20)/6,25,TRUE); //where to put OK button while resizing - MoveWindow(GetDlgItem(hDlg,IDC_LISTMAILS), 5 ,5 ,x-10 ,y-55,TRUE); //where to put list mail window while resizing - MoveWindow(GetDlgItem(hDlg,IDC_STSTATUS), 5 ,y-5-45 ,x-10 ,15,TRUE); //where to put account status text while resizing - } -// break; - return 0; - case WM_GETMINMAXINFO: - ((LPMINMAXINFO)lParam)->ptMinTrackSize.x=MAILBROWSER_MINXSIZE; - ((LPMINMAXINFO)lParam)->ptMinTrackSize.y=MAILBROWSER_MINYSIZE; - return 0; - case WM_TIMER: - { - NOTIFYICONDATA nid; - struct CMailWinUserInfo *mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER); - - ZeroMemory(&nid,sizeof(nid)); - nid.cbSize=sizeof(NOTIFYICONDATA); - nid.hWnd=hDlg; - nid.uID=0; - nid.uFlags=NIF_ICON; - if (mwui->TrayIconState==0) - nid.hIcon=g_LoadIconEx(0); - else - nid.hIcon=g_LoadIconEx(2); - Shell_NotifyIcon(NIM_MODIFY,&nid); - mwui->TrayIconState=!mwui->TrayIconState; -// UpdateWindow(hDlg); - } - break; - case WM_NOTIFY: - switch(((LPNMHDR)lParam)->idFrom) - { - - case IDC_LISTMAILS: - { - - switch(((LPNMHDR)lParam)->code) - { - case NM_DBLCLK: - SendMessage(hDlg,WM_YAMN_SHOWSELECTED,0,0); - break; - case LVN_COLUMNCLICK: - HACCOUNT ActualAccount; - if (NULL!=(ActualAccount=GetWindowAccount(hDlg))) { - NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lParam; - if (WAIT_OBJECT_0==WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:COLUMNCLICK:ActualAccountSO-read enter\n"); - #endif - switch((int)pNMListView->iSubItem) - { - case 0: - bFrom = !bFrom; - break; - case 1: - bSub = !bSub; - break; - case 2: - bSize = !bSize; - break; - case 3: - bDate = !bDate; - break; - default: - break; - } - ListView_SortItems(pNMListView->hdr.hwndFrom,ListViewCompareProc,pNMListView->iSubItem); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - } } - break; - - case NM_CUSTOMDRAW: - { - HACCOUNT ActualAccount; - LPNMLVCUSTOMDRAW cd=(LPNMLVCUSTOMDRAW)lParam; - LONG_PTR PaintCode; - - if (NULL==(ActualAccount=GetWindowAccount(hDlg))) - break; - - switch(cd->nmcd.dwDrawStage) - { - case CDDS_PREPAINT: - PaintCode=CDRF_NOTIFYITEMDRAW; - break; - case CDDS_ITEMPREPAINT: - PaintCode=CDRF_NOTIFYSUBITEMDRAW; - break; - case CDDS_ITEMPREPAINT | CDDS_SUBITEM: - { -// COLORREF crText, crBkgnd; -// crText= RGB(128,128,255); - HYAMNMAIL ActualMail; - BOOL umma; - - { - struct CMailWinUserInfo *mwui; - mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER); - umma= mwui->UpdateMailsMessagesAccess; - } - ActualMail=(HYAMNMAIL)cd->nmcd.lItemlParam; - if (!ActualMail) - ActualMail=(HYAMNMAIL)readItemLParam(cd->nmcd.hdr.hwndFrom,cd->nmcd.dwItemSpec); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DRAWITEM:ActualAccountMsgsSO-read wait\n"); - #endif - if (!umma) - if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->MessagesAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DRAWITEM:ActualAccountMsgsSO-read wait failed\n"); - #endif - return 0; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DRAWITEM:ActualAccountMsgsSO-read enter\n"); - #endif - switch(ActualMail->Flags & YAMN_MSG_SPAMMASK) - { - case YAMN_MSG_SPAML1: - case YAMN_MSG_SPAML2: - cd->clrText=RGB(150,150,150); - break; - case YAMN_MSG_SPAML3: - cd->clrText=RGB(200,200,200); - cd->clrTextBk=RGB(160,160,160); - break; - case 0: - if (cd->nmcd.dwItemSpec & 1) - cd->clrTextBk=RGB(230,230,230); - break; - default: - break; - } - if (ActualMail->Flags & YAMN_MSG_UNSEEN) - cd->clrTextBk=RGB(220,235,250); - PaintCode=CDRF_DODEFAULT; - - if (!umma) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:DRAWITEM:ActualAccountMsgsSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->MessagesAccessSO); - } - - break; - } - } - SetWindowLongPtr(hDlg,DWLP_MSGRESULT,PaintCode); - return 1; - } - } - } - } - break; - case WM_CONTEXTMENU: - { - if ( GetWindowLongPtr(( HWND )wParam, GWLP_ID ) == IDC_LISTMAILS) { - //MessageBox(0,"LISTHEADERS","Debug",0); - HWND hList = GetDlgItem( hDlg, IDC_LISTMAILS ); - POINT pt = { (signed short)LOWORD( lParam ), (signed short)HIWORD( lParam ) }; - HTREEITEM hItem = 0; - if (pt.x==-1) pt.x = 0; - if (pt.y==-1) pt.y = 0; - if (int numRows = ListView_GetItemCount(hList)) { - HMENU hMenu = CreatePopupMenu(); - AppendMenu(hMenu, MF_STRING, (UINT_PTR)1, TranslateT("Copy Selected")); - AppendMenu(hMenu, MF_STRING, (UINT_PTR)2, TranslateT("Copy All")); - AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); - AppendMenu(hMenu, MF_STRING, (UINT_PTR)0, TranslateT("Cancel")); - int nReturnCmd = TrackPopupMenu( hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hDlg, NULL ); - DestroyMenu( hMenu ); - if (nReturnCmd>0){ - int courRow=0; - size_t sizeNeeded = 0; - TCHAR from[128]={0}, subject[256]={0}, size[16]={0}, date[64]={0}; - for (courRow=0;courRowmessage == WM_KEYDOWN - && lpmsg->wParam == VK_RETURN) - return DLGC_WANTALLKEYS; - } - break; - } - case WM_KEYDOWN: - { - - BOOL isCtrl = GetKeyState(VK_CONTROL) & 0x8000; - BOOL isShift = GetKeyState(VK_SHIFT) & 0x8000; - BOOL isAlt = GetKeyState(VK_MENU) & 0x8000; - - switch (wParam) - { - case 'A': // ctrl-a - if (!isAlt && !isShift && isCtrl) SendMessage(hwndParent,WM_COMMAND,IDC_BTNCHECKALL,0); - break; - case VK_RETURN: - case VK_SPACE: - if (!isAlt && !isShift && !isCtrl) SendMessage(hwndParent,WM_YAMN_SHOWSELECTED,0,0); - break; - case VK_DELETE: - SendMessage(hwndParent,WM_COMMAND,IDC_BTNDEL,0); - break; - } - - break; - - } - } - return CallWindowProc(OldListViewSubclassProc, hDlg, msg, wParam, lParam); -} - -DWORD WINAPI MailBrowser(LPVOID Param) -{ - MSG msg; - - HWND hMailBrowser; - BOOL WndFound=FALSE; - HACCOUNT ActualAccount; - struct MailBrowserWinParam MyParam; - - MyParam=*(struct MailBrowserWinParam *)Param; - ActualAccount=MyParam.account; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:Incrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); - #endif - SCIncFcn(ActualAccount->UsingThreads); - -// we will not use params in stack anymore - SetEvent(MyParam.ThreadRunningEV); - - __try - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:ActualAccountSO-read wait failed\n"); - #endif - return 0; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:ActualAccountSO-read enter\n"); - #endif - if (!(ActualAccount->AbilityFlags & YAMN_ACC_BROWSE)) - { - MyParam.nflags=MyParam.nflags & ~YAMN_ACC_MSG; - MyParam.nnflags=MyParam.nnflags & ~YAMN_ACC_MSG; - } - if (!(ActualAccount->AbilityFlags & YAMN_ACC_POPUP)) - MyParam.nflags=MyParam.nflags & ~YAMN_ACC_POP; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - - if (NULL!=(hMailBrowser=WindowList_Find(YAMNVar.NewMailAccountWnd,ActualAccount))) - WndFound=TRUE; - if ((hMailBrowser==NULL) && ((MyParam.nflags & YAMN_ACC_MSG) || (MyParam.nflags & YAMN_ACC_ICO) || (MyParam.nnflags & YAMN_ACC_MSG))) - { - hMailBrowser=CreateDialogParamW(YAMNVar.hInst,MAKEINTRESOURCEW(IDD_DLGVIEWMESSAGES),NULL,DlgProcYAMNMailBrowser,(LPARAM)&MyParam); - SendMessageW(hMailBrowser,WM_SETICON,(WPARAM)ICON_BIG,(LPARAM)g_LoadIconEx(2,true)); - SendMessageW(hMailBrowser,WM_SETICON,(WPARAM)ICON_SMALL,(LPARAM)g_LoadIconEx(2)); - MoveWindow(hMailBrowser,PosX,PosY,SizeX,SizeY,TRUE); - } - - if (hMailBrowser!=NULL) - { - struct CChangeContent Params={MyParam.nflags,MyParam.nnflags}; //if this thread created window, just post message to update mails - - SendMessageW(hMailBrowser,WM_YAMN_CHANGECONTENT,(WPARAM)ActualAccount,(LPARAM)&Params); //we ensure this will do the thread who created the browser window - } - else - UpdateMails(NULL,ActualAccount,MyParam.nflags,MyParam.nnflags); //update mails without displaying or refreshing any window - - if ((hMailBrowser!=NULL) && !WndFound) //we process message loop only for thread that created window - { - while(GetMessage(&msg,NULL,0,0)) - { - if (!IsDialogMessage(hMailBrowser, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - } - - if ((!WndFound) && (ActualAccount->Plugin->Fcn!=NULL) && (ActualAccount->Plugin->Fcn->WriteAccountsFcnPtr!=NULL) && ActualAccount->AbleToWork) - ActualAccount->Plugin->Fcn->WriteAccountsFcnPtr(); - } - __finally - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"MailBrowser:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); - #endif - SCDecFcn(ActualAccount->UsingThreads); - } - return 1; -} - -INT_PTR RunMailBrowserSvc(WPARAM wParam,LPARAM lParam) -{ - DWORD tid; - //an event for successfull copy parameters to which point a pointer in stack for new thread - HANDLE ThreadRunningEV; - PYAMN_MAILBROWSERPARAM Param=(PYAMN_MAILBROWSERPARAM)wParam; - - if ((DWORD)lParam!=YAMN_MAILBROWSERVERSION) - return 0; - - if (NULL!=(ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) - { - HANDLE NewThread; - - Param->ThreadRunningEV=ThreadRunningEV; - if (NULL!=(NewThread=CreateThread(NULL,0,MailBrowser,Param,0,&tid))) - { - WaitForSingleObject(ThreadRunningEV,INFINITE); - CloseHandle(NewThread); - } - CloseHandle(ThreadRunningEV); - return 1; - } - return 0; -} diff --git a/protocols/YAMN/debug.cpp b/protocols/YAMN/debug.cpp deleted file mode 100644 index 9b9793a965..0000000000 --- a/protocols/YAMN/debug.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * YAMN plugin main file - * Miranda homepage: http://miranda-icq.sourceforge.net/ - * - * Debug functions used in DEBUG release (you need to global #define DEBUG to get debug version) - * - * (c) majvan 2002-2004 - */ - -#include "yamn.h" -#include "debug.h" -#ifdef YAMN_DEBUG -#include "version.h" - -#if defined (WIN9X) - #define YAMN_VER "YAMN " YAMN_VERSION_C " (Win9x)" -#elif defined(WIN2IN1) - #define YAMN_VER "YAMN " YAMN_VERSION_C " (2in1)" -#else - #define YAMN_VER "YAMN " YAMN_VERSION_C " (WinNT)" -#endif - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -TCHAR DebugUserDirectory[MAX_PATH] = _T("."); -LPCRITICAL_SECTION FileAccessCS; - -#ifdef DEBUG_SYNCHRO -TCHAR DebugSynchroFileName2[]=_T("%s\\yamn-debug.synchro.log"); -HANDLE SynchroFile; -#endif - -#ifdef DEBUG_COMM -TCHAR DebugCommFileName2[]=_T("%s\\yamn-debug.comm.log"); -HANDLE CommFile; -#endif - -#ifdef DEBUG_DECODE -TCHAR DebugDecodeFileName2[]=_T("%s\\yamn-debug.decode.log"); -HANDLE DecodeFile; -#endif - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -void InitDebug() -{ -#if defined (DEBUG_SYNCHRO) || defined (DEBUG_COMM) || defined (DEBUG_DECODE) - TCHAR DebugFileName[MAX_PATH]; -#endif - if (FileAccessCS==NULL) - { - FileAccessCS=new CRITICAL_SECTION; - InitializeCriticalSection(FileAccessCS); - } - -#ifdef DEBUG_SYNCHRO - _stprintf(DebugFileName,DebugSynchroFileName2,DebugUserDirectory); - - SynchroFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); - DebugLog(SynchroFile,"Synchro debug file created by %s\n",YAMN_VER); -#endif - -#ifdef DEBUG_COMM - _stprintf(DebugFileName,DebugCommFileName2,DebugUserDirectory); - - CommFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); - DebugLog(CommFile,"Communication debug file created by %s\n",YAMN_VER); -#endif - -#ifdef DEBUG_DECODE - _stprintf(DebugFileName,DebugDecodeFileName2,DebugUserDirectory); - - DecodeFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); - DebugLog(DecodeFile,"Decoding kernel debug file created by %s\n",YAMN_VER); -#endif -} - -void UnInitDebug() -{ -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"File is being closed normally."); - CloseHandle(SynchroFile); -#endif -#ifdef DEBUG_COMM - DebugLog(CommFile,"File is being closed normally."); - CloseHandle(CommFile); -#endif -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"File is being closed normally."); - CloseHandle(DecodeFile); -#endif -} - - -void DebugLog(HANDLE File,const char *fmt,...) -{ - char *str; - char tids[32]; - va_list vararg; - int strsize; - DWORD Written; - - va_start(vararg,fmt); - str=(char *)malloc(strsize=65536); - mir_snprintf(tids, SIZEOF(tids), "[%x]",GetCurrentThreadId()); - while(_vsnprintf(str,strsize,fmt,vararg)==-1) - str=(char *)realloc(str,strsize+=65536); - va_end(vararg); - EnterCriticalSection(FileAccessCS); - WriteFile(File,tids,(DWORD)strlen(tids),&Written,NULL); - WriteFile(File,str,(DWORD)strlen(str),&Written,NULL); - LeaveCriticalSection(FileAccessCS); - free(str); -} - -void DebugLogW(HANDLE File,const WCHAR *fmt,...) -{ - WCHAR *str; - char tids[32]; - va_list vararg; - int strsize; - DWORD Written; - - va_start(vararg,fmt); - str=(WCHAR *)malloc((strsize=65536)*sizeof(WCHAR)); - mir_snprintf(tids, SIZEOF(tids), "[%x]",GetCurrentThreadId()); - while(_vsnwprintf(str,strsize,fmt,vararg)==-1) - str=(WCHAR *)realloc(str,(strsize+=65536)*sizeof(WCHAR)); - va_end(vararg); - EnterCriticalSection(FileAccessCS); - WriteFile(File,tids,(DWORD)strlen(tids),&Written,NULL); - WriteFile(File,str,(DWORD)wcslen(str)*sizeof(WCHAR),&Written,NULL); - LeaveCriticalSection(FileAccessCS); - free(str); -} - -#endif //ifdef DEBUG \ No newline at end of file diff --git a/protocols/YAMN/debug.h b/protocols/YAMN/debug.h deleted file mode 100644 index 3bde9ddc81..0000000000 --- a/protocols/YAMN/debug.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef __DEBUG_H -#define __DEBUG_H - -// #define YAMN_DEBUG - -//#define YAMN_VER_BETA -//#define YAMN_VER_BETA_CRASHONLY - -#ifdef YAMN_DEBUG - -//#pragma comment(lib, "th32.lib") - -#if !defined(_WIN32_WINNT) -#define _WIN32_WINNT 0x0501 // WinXP only -#endif -#define VC_EXTRALEAN -#include -#include -#include -#include - -//#define DEBUG_SYNCHRO //debug synchro to a file -//#define DEBUG_COMM //debug communiation to a file -//#define DEBUG_DECODE //debug header decoding to a file -//#define DEBUG_DECODECODEPAGE //add info about codepage used in conversion -//#define DEBUG_DECODEBASE64 //add info about base64 result -//#define DEBUG_DECODEQUOTED //add info about quoted printable result -//#define DEBUG_FILEREAD //debug file reading to message boxes -//#define DEBUG_FILEREADMESSAGES //debug file reading messages to message boxes - -void DebugLog(HANDLE,const char *fmt,...); -void DebugLogW(HANDLE File,const WCHAR *fmt,...); - -#ifdef DEBUG_SYNCHRO -// Used for synchronization debug -extern HANDLE SynchroFile; -#endif - -#ifdef DEBUG_COMM -// Used for communication debug -extern HANDLE CommFile; -#endif - -#ifdef DEBUG_DECODE -// Used for decoding debug -extern HANDLE DecodeFile; -#endif - -#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) -DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo,char *DebugString); - -DWORD ReadStringFromMemoryW(char **Parser,TCHAR *End,char **StoreTo,TCHAR *DebugString); - -#else -DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo); - -DWORD ReadStringFromMemoryW(WCHAR **Parser,WCHAR *End,WCHAR **StoreTo); - -#endif - -//#ifdef DEBUG_ACCOUNTS -//int GetAccounts(); -//void WriteAccounts(); -//#endif - -#endif //YAMN_DEBUG -#endif //_DEBUG_H diff --git a/protocols/YAMN/docs/ChangeLog.txt b/protocols/YAMN/docs/ChangeLog.txt new file mode 100644 index 0000000000..6a85810ab2 --- /dev/null +++ b/protocols/YAMN/docs/ChangeLog.txt @@ -0,0 +1,243 @@ +0.1.2.5 +======= +! fix many memory leaks patch by Merlin +* x64 support by Merlin +* Resource patch by mataes (for translations) + +0.1.2.4 +======= +* Only show popup tab if popup plugin is present +! Wrong time displayed in mailbrower (fix by y_b) + +0.1.2.3 +======= +* New design for the options pages (Thanks Eyecue) + +0.1.2.2 +======= +* using, with updater, the correct file id in file listing (yamn 2in1) ++ added folders plugin support ++ Support for miranda 0.8 + +0.1.2.1 +======= +! Don't close MailBrowser when e-mails are updated if it is manually open ++ Discard the new Event when message is shown or is deleted from the server ++ Option to disable the CList events per account ++ Contact status change also happens when e-mail are being deleted + +0.1.2.0 +======= +! patch by TioDuke for icolib and status and status icons handling. Thanks! +! code cleaning (properly destroy services and hooks) ++ Contact status changes accordingly the action (Ready, Working, Error) + +0.1.1.0 +======= ++ Show message is open in new thread ++ Click on individual new e-mail popups shows the message window + +0.1.0.2 +============ ++ Pressing "Space" key will show the selected message +! Delete message is done by DELETE key, not by '.' +! removed some repeated code +! "Ok" and "Select All" buttons in mail browser are translatable + +0.1.0.1 +============ ++ Message body shown in separate edit box. ++ Support for Content-transfer-encoding: Quoted-Printable and base64 ++ Recursive Content-type: multipart/ support ++ Option to auto retrieve body + +0.0.1.11 +============ ++ Option to use yamn as a protocol. +* Patch by Tioduke (code cleaning) +! Fixed the crash parsing invalid "Date" header (SPAMs or silly e-mail client) (y_b) +! ShowMessage dialog follows Content-type header to chose the codepage (y_b) ++ Only supported codepages are shown in the options (y_b) ++ Enhance codepages support (y_b) + +0.0.1.10 +============ +! Icons are based on single bitmap image (y_b) +* Show full feaders on double click in mailbrowser (y_b) +* Dates are shown localized and sorted correctly (y_b) +* To show long/short date and seconds (y_b) +! Solved a rare/random crash on unstable connection (y_b) +! Enabled tabstop on new tabcontrol and reordered tabstop in option pages (y_b) +* Enable TAB selection in mailbrowser dialog (patch by -pv-) ++ introducing 2in1 build - can be used both in win9x and NT/XP +* Options redesign. + +0.0.1.9 +============ +* Patch by Perf (visual patch) + +0.0.1.8 +============ ++ add ctr-A to select all mails ++ del key delete selected mail ++ add a select all button + +0.0.1.7 +============ +* Change options dialog (use tabsrmm uxtheme) +! Invert back and text color for no new mail popup in option page. +* New default icon reworked by Faith Healer. + +0.0.1.6 +============ +* Try to update all icons when changing in icolib. +! Allow scrolling in list of email account. (Patch by Jazzy) +! Memory leak in stls fix (y_b) + +0.0.1.5 +============ +! Bug fix with help.dll problem. (Patch by Jazzy) + (http://developer.berlios.de/bugs/?func=detailbug&bug_id=6692&group_id=3292) +! Remove merge in agressiveoptimize.h + +0.0.1.4 +============ +! Option page bug (patch by y_b) +* Allow to edit the application text + +0.0.1.3 +============ +! Bug fix with new icolib + +0.0.1.2 +============ +! Bug fix with updater and stable version ++ Using new m_icolib.h ++ New context menu entry to launch application ++ Patch by y_b +{ + + Start TLS support + + Better icolib support + + SSL Logging +} + +0.0.1.1 +============ +! Bug fix on left click popup. + +0.0.1.0 +============ +Time for release. + +0.0.0.18 +============ +! Visual bug in option page +! Recompilation for win 9x users. + +0.0.0.17 +============ +* Redesign option page to have only one entry in plugins options +! Bug fix when there is no date set in the header (spam mails) (Thx Egres) + +0.0.0.16 +============ +* Right click on error popup close the popup. +! Missing break; in nonewmail popup in switch. ++ Add option to rename contact according to new mail. +! Patch by pescuma on delete accounts + +0.0.0.15 +============ +! Fixed dismiss event by right click on new mail popup crash +* Change string for the status choose button +! use CallServiceSync() instead of CallService() for adding clistevent (now icon blinks) + +0.0.0.14 +============ +! Tooltip on the clist event will now show correct text +! Remove the messagebox on double clik on mail +* Change options dialog add dialog for status choose. + +0.0.0.13 +============ ++ Use of event count for the keyboard flashing + +0.0.0.12 +============ +- Remove message body retrieving due to bug. + +0.0.0.11 +============ ++ Add a function to retrieve the whole mail source. ++ Show the mail source when double clicking on it in mail browser. ++ Add a version resource. + +0.0.0.10 +============ ++ Now able to pass hContact handle to popup so can show avatar if set. +* Change folder structure in svn SDK\import replace by include + +0.0.0.9 +============ ++ Sorting asc and desc of the mail browser listview ++ Use the format yyyy-mm-dd hh:mm:ss for date comparaison in sorting ++ Doubleclick on list view to show the mail body but it seems to be empty :( + +0.0.0.8 +============ ++ Add date field in mail browser +* Modify the tooltip text for the clist event (add account name) +* Rename Contact member of CAccount by hContact since it is an HANDLE ++ Updater support for BETA +* Using the right headers (no more the one in SDK) + +0.0.0.7 +============ ++ Added changelog txt file. ++ Check presence of icolib to choose the right icon to show in clist ++ Status message will show all message pending in mail box (until they get retrieve by your email client) + +0.0.0.6 +============ +* Options page redesign. ++ Right click on popup close the clist event too. ++ Update status message if no new mail. ++ Right click on popup^with no new mail close the popup. +* No more delete of contact (avoid group affectation bug). + +0.0.0.5 +============ ++ Add contact context menu entry to check for new mail. ++ Catch double click event on contact to shown the mail browser. + +0.0.0.4 +============ ++ Add per account option to be show as contact or not. ++ Gestion de la suppression d'un compte ++ Use of the status message for showing number of emails. ++ Refresh yamn contact on the click on apply in options dialog. +* Better condition for the ^contact loop (ouuppsss) + +0.0.0.3 +============ ++ Now account are shown as a contact. ++ Source code modification and use of yamn.h ++ Wait the event moduleloaded before loading the icons (support icolib). + +0.0.0.2 +============ ++ Use of patch by Q (From file listing) (Memory cleaning, empty mail browser even if there are mails, yamn freeze sometime) ++ Use of thread access function. ++ Possibility to change toptoolbar icons via icolib. ++ Icon in main menu entry (Asked by a7) ++ New Icons set by Manudevil. ++ Change version number to be compatible with updater plugin + +0.01 +============ + ++ icolib support. ++ keyboard flash support (just 10 sec) (thx TioDuke) needs Keyboard Notify Ext. 1.5.4.4 ++ list of email can be sorted. +* left click on popup shows email list. +* better toptoolbar support. \ No newline at end of file diff --git a/protocols/YAMN/docs/yamn-translation.txt b/protocols/YAMN/docs/yamn-translation.txt new file mode 100644 index 0000000000..7acbad549f --- /dev/null +++ b/protocols/YAMN/docs/yamn-translation.txt @@ -0,0 +1,184 @@ +; Common strings that belong to many files +;[Cancel] +;[Check mail] +;[Default] +;[New Mail] +;[No new mail message] +;[Offline] +;[YAMN] + +; ../../protocols/YAMN/browser/badconnect.cpp +;[ - connection error] +;[Unknown error] + +; ../../protocols/YAMN/browser/mailbrowser.cpp +;[%d new mail message(s), %d total] +;[%s : %d new mail message(s), %d total] +;[- new mail message(s)] +;[Copy All] +;[Copy Selected] +;[Delete confirmation] +;[Do you really want to delete %d selected mails?] +;[Header] +;[No new mail message, %d spam(s)] +;[Value] + +; ../../protocols/YAMN/mails/mime.cpp +;[Part] + +; ../../protocols/YAMN/main.cpp +;[Connect Fail] +;[Launch Application] +;[Neutral] +;[TopToolBar Down] +;[TopToolBar UP] + +; ../../protocols/YAMN/proto/netlib.cpp +;[%s connection] + +; ../../protocols/YAMN/proto/pop3/pop3comm.cpp +;[Account is about to be stopped.] +;[Bad user or password.] +;[Cannot allocate memory for received data.] +;[Cannot connect to POP3 server.] +;[Cannot connect to server with NetLib.] +;[Cannot login to POP3 server.] +;[Cannot read SSL data.] +;[Cannot receive data.] +;[Cannot send data.] +;[Cannot write SSL data.] +;[Connecting to server] +;[DNS lookup error.] +;[Deleting requested mails] +;[Deleting spam] +;[Disconnected] +;[Entering POP3 account] +;[Error %d-%d-%d-%d:] +;[Error connecting socket with SSL.] +;[Error connecting to server with socket.] +;[Error reading account file. Account file corrupted.] +;[Error while copying data to disk occured. File in use?] +;[Error while creating SSL structure.] +;[Error while creating base socket.] +;[Error while executing POP3 command.] +;[Found new version of account book, not compatible with this version of YAMN.] +;[Mail notifier and browser for Miranda IM. Included POP3 protocol.] +;[Memory allocation error while data reading] +;[Memory allocation error.] +;[OpenSSL not loaded.] +;[POP3 plugin- write file error] +;[POP3 protocol (internal)] +;[Reading body %s] +;[Reading file error. File already in use?] +;[Reading new mail messages (%d%% done)] +;[Searching for new mail message] +;[Server does not support APOP authorization.] +;[Server rejected connection with SSL.] +;[Windows socket 2.0 init failed.] +;[YAMN (internal POP3) read error] + +; ../../protocols/YAMN/proto/pop3/pop3opt.cpp +;[Account Test] +;[Account Test (failed)] +;[Accounts] +;[All Files] +;[Cannot allocate memory space for new account] +;[Connection failed message] +;[Delete account confirmation] +;[Do you really want to delete this account?] +;[Executables] +;[General] +;[Input error] +;[Memory error] +;[Network] +;[New Account] +;[No account selected] +;[Please select application to run] +;[Please wait while no account is in use.] +;[Plugins] +;[PopUps] +;[Select executable used for notification] +;[This is not a valid number value] +;[Time left to next check [s]: %d] +;[You have N new mail messages] + +; ../../protocols/YAMN/resources/YAMN.rc +;[..s Popup duration] +;[APOP] +;[Account] +;[Auto retrieve body] +;[Away] +;[Background colour] +;[Check from menu] +;[Check interval [min]:] +;[Check this account] +;[Check while ...] +;[Choose modes] +;[Codepage:] +;[Connection failure notifications] +;[Contact:] +;[Copyright:] +;[DND] +;[Date/Time Representation] +;[Description:] +;[Disable Events] +;[Disable STLS] +;[Don't show seconds] +;[Don't show today's date] +;[Enable Close on Delete Button] +;[Enable YAMN Main Menu] +;[Errors] +;[Execute Application] +;[Free for chat] +;[Installed plugins] +;[Invisible] +;[Keyboard Flash] +;[List4] +;[List5] +;[Mail Notifications] +;[MailBrowser Options] +;[Message] +;[Message notification if failed] +;[Multi popup] +;[N/A] +;[Name:] +;[No new mail notifications] +;[Notifications] +;[OK] +;[Occupied] +;[On the phone] +;[Online] +;[Only check when ...] +;[Options] +;[Out to lunch] +;[Password:] +;[Persistant message] +;[Popup] +;[Popup if no mail] +;[Popup notification if failed] +;[Port:] +;[Preview] +;[Replace nick name] +;[Reset counter] +;[SSL] +;[Server:] +;[Show YAMN as a Protocol (Require Restart)] +;[Show long localised date] +;[Single popup] +;[Sound] +;[Sound notification if failed] +;[Startup check] +;[Status:] +;[Text colour] +;[TopToolBar button \"Check mail\"] +;[Tray Icon] +;[Tray icon notification if failed] +;[Use contact notification for this account] +;[Use custom colour] +;[User Name:] +;[Version:] +;[WWW:] +;[YAMN General Options] + +; ../../protocols/YAMN/services.cpp +;[Nick] diff --git a/protocols/YAMN/filter/Base/AggressiveOptimize.h b/protocols/YAMN/filter/Base/AggressiveOptimize.h deleted file mode 100644 index 1bf0e19c2c..0000000000 --- a/protocols/YAMN/filter/Base/AggressiveOptimize.h +++ /dev/null @@ -1,168 +0,0 @@ - -////////////////////////////// -// Version 1.40 -// October 22nd, 2002 - .NET (VC7, _MSC_VER=1300) support! -// Version 1.30 -// Nov 24th, 2000 -// Version 1.20 -// Jun 9th, 2000 -// Version 1.10 -// Jan 23rd, 2000 -// Version 1.00 -// May 20th, 1999 -// Todd C. Wilson, Fresh Ground Software -// (todd@nopcode.com) -// This header file will kick in settings for Visual C++ 5 and 6 that will (usually) -// result in smaller exe's. -// The "trick" is to tell the compiler to not pad out the function calls; this is done -// by not using the /O1 or /O2 option - if you do, you implicitly use /Gy, which pads -// out each and every function call. In one single 500k dll, I managed to cut out 120k -// by this alone! -// The other two "tricks" are telling the Linker to merge all data-type segments together -// in the exe file. The relocation, read-only (constants) data, and code section (.text) -// sections can almost always be merged. Each section merged can save 4k in exe space, -// since each section is padded out to 4k chunks. This is very noticeable with smaller -// exes, since you could have only 700 bytes of data, 300 bytes of code, 94 bytes of -// strings - padded out, this could be 12k of runtime, for 1094 bytes of stuff! For larger -// programs, this is less overall, but can save at least 4k. -// Note that if you're using MFC static or some other 3rd party libs, you may get poor -// results with merging the readonly (.rdata) section - the exe may grow larger. -// To use this feature, define _MERGE_DATA_ in your project or before this header is used. -// With Visual C++ 5, the program uses a file alignment of 512 bytes, which results -// in a small exe. Under VC6, the program instead uses 4k, which is the same as the -// section size. The reason (from what I understand) is that 4k is the chunk size of -// the virtual memory manager, and that WinAlign (an end-user tuning tool for Win98) -// will re-align the programs on this boundary. The problem with this is that all of -// Microsoft's system exes and dlls are *NOT* tuned like this, and using 4k causes serious -// exe bloat. This is very noticeable for smaller programs. -// The "trick" for this is to use the undocumented FILEALIGN linker parm to change the -// padding from 4k to 1/2k, which results in a much smaller exe - anywhere from 20%-75% -// depending on the size. Note that this is the same as using /OPT:NOWIN98, which *is* -// a previously documented switch, but was left out of the docs for some reason in VC6 and -// all of the current MSDN's - see KB:Q235956 for more information. -// Microsoft does say that using the 4k alignment will "speed up process loading", -// but I've been unable to notice a difference, even on my P180, with a very large (4meg) exe. -// Please note, however, that this will probably not change the size of the COMPRESSED -// file (either in a .zip file or in an install archive), since this 4k is all zeroes and -// gets compressed away. -// Also, the /ALIGN:4096 switch will "magically" do the same thing, even though this is the -// default setting for this switch. Apparently this sets the same values as the above two -// switches do. We do not use this in this header, since it smacks of a bug and not a feature. -// Thanks to Michael Geary for some additional tips! -// -// Notes about using this header in .NET -// First off, VC7 does not allow a lot of the linker command options in pragma's. There is no -// honest or good reason why Microsoft decided to make this change, it just doesn't. -// So that is why there are a lot of <1300 #if's in the header. -// If you want to take full advantage of the VC7 linker options, you will need to do it on a -// PER PROJECT BASIS; you can no longer use a global header file like this to make it better. -// Items I strongly suggest putting in all your VC7 project linker options command line settings: -// /ignore:4078 /RELEASE -// Compiler options: -// /GL (Whole Program Optimization) -// If you're making an .EXE and not a .DLL, consider adding in: -// /GA (Optimize for Windows Application) -// Some items to consider using in your VC7 projects (not VC6): -// Link-time Code Generation - whole code optimization. Put this in your exe/dll project link settings. -// /LTCG:NOSTATUS -// The classic no-padding and no-bloat compiler C/C++ switch: -// /opt:nowin98 -// -// (C++ command line options: /GL /opt:nowin98 and /GA for .exe files) -// (Link command line options: /ignore:4078 /RELEASE /LTCG:NOSTATUS) -// -// Now, notes on using these options in VC7 vs VC6. -// VC6 consistently, for me, produces smaller code from C++ the exact same sources, -// with or without this header. On average, VC6 produces 5% smaller binaries compared -// to VC7 compiling the exact same project, *without* this header. With this header, VC6 -// will make a 13k file, while VC7 will make a 64k one. VC7 is just bloaty, pure and -// simple - all that managed/unmanaged C++ runtimes, and the CLR stuff must be getting -// in the way of code generation. However, template support is better, so there. -// Both VC6 and VC7 show the same end kind of end result savings - larger binary output -// will shave about 2% off, where as smaller projects (support DLL's, cpl's, -// activex controls, ATL libs, etc) get the best result, since the padding is usually -// more than the actual usable code. But again, VC7 does not compile down as small as VC6. -// -// The argument can be made that doing this is a waste of time, since the "zero bytes" -// will be compressed out in a zip file or install archive. Not really - it doesn't matter -// if the data is a string of zeroes or ones or 85858585 - it will still take room (20 bytes -// in a zip file, 29 bytes if only *4* of them 4k bytes are not the same) and time to -// compress that data and decompress it. Also, 20k of zeros is NOT 20k on disk - it's the -// size of the cluster slop- for Fat32 systems, 20k can be 32k, NTFS could make it 24k if you're -// just 1 byte over (round up). Most end users do not have the dual P4 Xeon systems with -// two gigs of RDram and a Raid 0+1 of Western Digital 120meg Special Editions that all -// worthy developers have (all six of us), so they will need any space and LOADING TIME -// savings they will need; taking an extra 32k or more out of your end user's 64megs of -// ram on Windows 98 is Not a Good Thing. -// -// Now, as a ADDED BONUS at NO EXTRA COST TO YOU! Under VC6, using the /merge:.text=.data -// pragma will cause the output file to be un-disassembleable! (is that a word?) At least, -// with the normal tools - WinDisam, DumpBin, and the like will not work. Try it - use the -// header, compile release, and then use DUMPBIN /DISASM filename.exe - no code! -// Thanks to Gëzim Pani for discovering this gem - for a full writeup on -// this issue and the ramifactions of it, visit www.nopcode.com for the Aggressive Optimize -// article. - -#ifndef _AGGRESSIVEOPTIMIZE_H_ -#define _AGGRESSIVEOPTIMIZE_H_ - -#pragma warning(disable:4711) - -#ifdef NDEBUG -// /Og (global optimizations), /Os (favor small code), /Oy (no frame pointers) -#pragma optimize("gsy",on) - -#if (_MSC_VER<1300) - #pragma comment(linker,"/RELEASE") -#endif - -/* -// Note that merging the .rdata section will result in LARGER exe's if you using -// MFC (esp. static link). If this is desirable, define _MERGE_RDATA_ in your project. -#ifdef _MERGE_RDATA_ -#pragma comment(linker,"/merge:.rdata=.data") -#endif // _MERGE_RDATA_ - -#pragma comment(linker,"/merge:.text=.data") -#if (_MSC_VER<1300) - // In VC7, this causes problems with the relocation and data tables, so best to not merge them - #pragma comment(linker,"/merge:.reloc=.data") -#endif -*/ - -// Merging sections with different attributes causes a linker warning, so -// turn off the warning. From Michael Geary. Undocumented, as usual! -#if (_MSC_VER<1300) - // In VC7, you will need to put this in your project settings - #pragma comment(linker,"/ignore:4078") -#endif - -// With Visual C++ 5, you already get the 512-byte alignment, so you will only need -// it for VC6, and maybe later. -#if _MSC_VER >= 1000 - -// Option #1: use /filealign -// Totally undocumented! And if you set it lower than 512 bytes, the program crashes. -// Either leave at 0x200 or 0x1000 -//#pragma comment(linker,"/FILEALIGN:0x200") - -// Option #2: use /opt:nowin98 -// See KB:Q235956 or the READMEVC.htm in your VC directory for info on this one. -// This is our currently preferred option, since it is fully documented and unlikely -// to break in service packs and updates. -#if (_MSC_VER<1300) - // In VC7, you will need to put this in your project settings - #pragma comment(linker,"/opt:nowin98") -#else - -// Option #3: use /align:4096 -// A side effect of using the default align value is that it turns on the above switch. -// Does nothing under Vc7 that /opt:nowin98 doesn't already give you -// #pragma comment(linker,"/ALIGN:512") -#endif - -#endif // _MSC_VER >= 1000 - -#endif // NDEBUG - -#endif // _AGGRESSIVEOPTIMIZE_H_ diff --git a/protocols/YAMN/filter/Base/Base.dsp b/protocols/YAMN/filter/Base/Base.dsp deleted file mode 100644 index 7231712a74..0000000000 --- a/protocols/YAMN/filter/Base/Base.dsp +++ /dev/null @@ -1,108 +0,0 @@ -# Microsoft Developer Studio Project File - Name="Base" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** NICHT BEARBEITEN ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=Base - Win32 Release -!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE -!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl -!MESSAGE -!MESSAGE NMAKE /f "Base.mak". -!MESSAGE -!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben -!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: -!MESSAGE -!MESSAGE NMAKE /f "Base.mak" CFG="Base - Win32 Release" -!MESSAGE -!MESSAGE Für die Konfiguration stehen zur Auswahl: -!MESSAGE -!MESSAGE "Base - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library") -!MESSAGE "Base - Win32 Debug" (basierend auf "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "Base - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Ignore_Export_Lib 1 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /G4 /Zp4 /MD /W3 /GX /O1 /Ob0 /I "../../../../include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /G4 /Zp4 /MD /W3 /GX /Zi /O1 /Ob0 /I "../../../../include" /I "../../../../include/msapi" /I "../../../../include_API" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD BASE RSC /l 0x417 /d "NDEBUG" -# ADD RSC /l 0x417 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib /nologo /dll /machine:I386 /out:"../../../../bin/release/plugins/YAMN-filter/Base.dll" /filealign:512 -# ADD LINK32 kernel32.lib user32.lib /nologo /dll /pdb:"../../../../bin/Release/plugins/YAMN/base.pdb" /debug /machine:I386 /out:"../../../../bin/Release/plugins/YAMN/base.dll" /filealign:512 - -!ELSEIF "$(CFG)" == "Base - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /G4 /Zp4 /MDd /W3 /Gm /Gi /GX /ZI /Od /I "../../../../include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /GZ /c -# ADD CPP /nologo /G4 /Zp4 /MDd /W3 /Gm /Gi /GX /ZI /Od /I "../../../../include" /I "../../../../include/msapi" /I "../../../../include_API" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /GZ /c -# ADD BASE RSC /l 0x417 /d "_DEBUG" -# ADD RSC /l 0x417 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib /nologo /dll /debug /machine:I386 /out:"../../../../bin/Debug/plugins/YAMN-filter/Base.dll" -# ADD LINK32 kernel32.lib user32.lib /nologo /dll /pdb:"../../../../bin/Debug/plugins/YAMN/base.pdb" /debug /machine:I386 /out:"../../../../bin/Debug/plugins/YAMN/base.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "Base - Win32 Release" -# Name "Base - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\debug.cpp -# End Source File -# Begin Source File - -SOURCE=.\maindll.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/protocols/YAMN/filter/Base/Base.mak b/protocols/YAMN/filter/Base/Base.mak deleted file mode 100644 index 75ec59db8a..0000000000 --- a/protocols/YAMN/filter/Base/Base.mak +++ /dev/null @@ -1,229 +0,0 @@ -# Microsoft Developer Studio Generated NMAKE File, Based on Base.dsp -!IF "$(CFG)" == "" -CFG=Base - Win32 Release -!MESSAGE No configuration specified. Defaulting to Base - Win32 Release. -!ENDIF - -!IF "$(CFG)" != "Base - Win32 Release" && "$(CFG)" != "Base - Win32 Debug" -!MESSAGE Invalid configuration "$(CFG)" specified. -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "Base.mak" CFG="Base - Win32 Release" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "Base - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "Base - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE -!ERROR An invalid configuration is specified. -!ENDIF - -!IF "$(OS)" == "Windows_NT" -NULL= -!ELSE -NULL=nul -!ENDIF - -!IF "$(CFG)" == "Base - Win32 Release" - -OUTDIR=.\Release -INTDIR=.\Release - -ALL : "..\..\..\..\bin\release\plugins\YAMN-filter\base.dll" - - -CLEAN : - -@erase "$(INTDIR)\debug.obj" - -@erase "$(INTDIR)\maindll.obj" - -@erase "$(INTDIR)\vc60.idb" - -@erase "$(OUTDIR)\base.exp" - -@erase "..\..\..\..\bin\release\plugins\YAMN-filter\base.dll" - -"$(OUTDIR)" : - if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" - -CPP=cl.exe -CPP_PROJ=/nologo /G4 /Zp4 /MD /W3 /GX /O1 /Ob0 /I "../../../../include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\Base.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c - -.c{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cpp{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cxx{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.c{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cpp{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cxx{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -MTL=midl.exe -MTL_PROJ= -RSC=rc.exe -BSC32=bscmake.exe -BSC32_FLAGS=/nologo /o"$(OUTDIR)\Base.bsc" -BSC32_SBRS= \ - -LINK32=link.exe -LINK32_FLAGS=kernel32.lib user32.lib /nologo /dll /incremental:no /pdb:"$(OUTDIR)\base.pdb" /machine:I386 /out:"../../../../bin/release/plugins/YAMN-filter/base.dll" /implib:"$(OUTDIR)\base.lib" /filealign:512 -LINK32_OBJS= \ - "$(INTDIR)\debug.obj" \ - "$(INTDIR)\maindll.obj" - -"..\..\..\..\bin\release\plugins\YAMN-filter\base.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) - $(LINK32) @<< - $(LINK32_FLAGS) $(LINK32_OBJS) -<< - -!ELSEIF "$(CFG)" == "Base - Win32 Debug" - -OUTDIR=.\Debug -INTDIR=.\Debug -# Begin Custom Macros -OutDir=.\Debug -# End Custom Macros - -ALL : "..\..\..\..\bin\Debug\plugins\YAMN-filter\Base.dll" "$(OUTDIR)\Base.bsc" - - -CLEAN : - -@erase "$(INTDIR)\debug.obj" - -@erase "$(INTDIR)\debug.sbr" - -@erase "$(INTDIR)\maindll.obj" - -@erase "$(INTDIR)\maindll.sbr" - -@erase "$(INTDIR)\vc60.idb" - -@erase "$(INTDIR)\vc60.pdb" - -@erase "$(OUTDIR)\Base.bsc" - -@erase "$(OUTDIR)\Base.exp" - -@erase "$(OUTDIR)\Base.pdb" - -@erase "..\..\..\..\bin\Debug\plugins\YAMN-filter\Base.dll" - -@erase "..\..\..\..\bin\Debug\plugins\YAMN-filter\Base.ilk" - -"$(OUTDIR)" : - if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" - -CPP=cl.exe -CPP_PROJ=/nologo /G4 /Zp4 /MDd /W3 /Gm /Gi /GX /ZI /Od /I "../../../../include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\Base.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c - -.c{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cpp{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cxx{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.c{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cpp{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cxx{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -MTL=midl.exe -MTL_PROJ= -RSC=rc.exe -BSC32=bscmake.exe -BSC32_FLAGS=/nologo /o"$(OUTDIR)\Base.bsc" -BSC32_SBRS= \ - "$(INTDIR)\debug.sbr" \ - "$(INTDIR)\maindll.sbr" - -"$(OUTDIR)\Base.bsc" : "$(OUTDIR)" $(BSC32_SBRS) - $(BSC32) @<< - $(BSC32_FLAGS) $(BSC32_SBRS) -<< - -LINK32=link.exe -LINK32_FLAGS=kernel32.lib user32.lib /nologo /dll /incremental:yes /pdb:"$(OUTDIR)\Base.pdb" /debug /machine:I386 /out:"../../../../bin/Debug/plugins/YAMN-filter/Base.dll" /implib:"$(OUTDIR)\Base.lib" -LINK32_OBJS= \ - "$(INTDIR)\debug.obj" \ - "$(INTDIR)\maindll.obj" - -"..\..\..\..\bin\Debug\plugins\YAMN-filter\Base.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) - $(LINK32) @<< - $(LINK32_FLAGS) $(LINK32_OBJS) -<< - -!ENDIF - - -!IF "$(NO_EXTERNAL_DEPS)" != "1" -!IF EXISTS("Base.dep") -!INCLUDE "Base.dep" -!ELSE -!MESSAGE Warning: cannot find "Base.dep" -!ENDIF -!ENDIF - - -!IF "$(CFG)" == "Base - Win32 Release" || "$(CFG)" == "Base - Win32 Debug" -SOURCE=.\debug.cpp - -!IF "$(CFG)" == "Base - Win32 Release" - - -"$(INTDIR)\debug.obj" : $(SOURCE) "$(INTDIR)" - - -!ELSEIF "$(CFG)" == "Base - Win32 Debug" - - -"$(INTDIR)\debug.obj" "$(INTDIR)\debug.sbr" : $(SOURCE) "$(INTDIR)" - - -!ENDIF - -SOURCE=.\maindll.cpp - -!IF "$(CFG)" == "Base - Win32 Release" - - -"$(INTDIR)\maindll.obj" : $(SOURCE) "$(INTDIR)" - - -!ELSEIF "$(CFG)" == "Base - Win32 Debug" - - -"$(INTDIR)\maindll.obj" "$(INTDIR)\maindll.sbr" : $(SOURCE) "$(INTDIR)" - - -!ENDIF - - -!ENDIF - diff --git a/protocols/YAMN/filter/Base/debug.cpp b/protocols/YAMN/filter/Base/debug.cpp deleted file mode 100644 index 654ece7b57..0000000000 --- a/protocols/YAMN/filter/Base/debug.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copied from YAMN plugin - * - * (c) majvan 2002-2004 - */ -#ifdef DEBUG_FILTER - -#include -#include -#include - - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -TCHAR DebugUserDirectory[MAX_PATH]="."; -LPCRITICAL_SECTION FileAccessCS; - -void DebugLog(HANDLE File,const char *fmt,...); - -#ifdef DEBUG_FILTER -TCHAR DebugFilterFileName2[]=_T("%s\\yamn-debug.basefilter.log"); -HANDLE FilterFile=INVALID_HANDLE_VALUE; -#endif - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -void InitDebug() -{ - TCHAR DebugFileName[MAX_PATH]; - - if(FileAccessCS==NULL) - { - FileAccessCS=new CRITICAL_SECTION; - InitializeCriticalSection(FileAccessCS); - } - - _stprintf(DebugFileName,DebugFilterFileName2,DebugUserDirectory); - - FilterFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,0,NULL); - - DebugLog(FilterFile,"Base filter plugin for YAMN - debug file\n"); -} - -void UnInitDebug() -{ - DebugLog(FilterFile,"File is being closed normally."); - CloseHandle(FilterFile); -} - -void DebugLog(HANDLE File,const char *fmt,...) -{ - char *str; - char tids[32]; - va_list vararg; - int strsize; - DWORD Written; - - va_start(vararg,fmt); - str=(char *)malloc(strsize=65536); - _stprintf(tids,_T("[%x]"),GetCurrentThreadId()); - while(_vsnprintf(str,strsize,fmt,vararg)==-1) - str=(char *)realloc(str,strsize+=65536); - va_end(vararg); - EnterCriticalSection(FileAccessCS); - WriteFile(File,tids,(DWORD)strlen(tids),&Written,NULL); - WriteFile(File,str,(DWORD)strlen(str),&Written,NULL); - LeaveCriticalSection(FileAccessCS); - free(str); -} - -#endif //ifdef DEBUG \ No newline at end of file diff --git a/protocols/YAMN/filter/Base/docs/base-readme.txt b/protocols/YAMN/filter/Base/docs/base-readme.txt deleted file mode 100644 index 2e79bbbdd8..0000000000 --- a/protocols/YAMN/filter/Base/docs/base-readme.txt +++ /dev/null @@ -1,63 +0,0 @@ -======================== -= Base Filter for YAMN = -======================== - -Q: What??? -A: YAMN filter to classify incoming email. - -Q: How? -A: Finding occurency of defiend MIME header item and its value from blacklist file. - -Q: Blacklist file? -A: Yes. It is created by yourself and located in Miranda directory with name 'basefilterdeny.txt' - -Q: Created by myself? -A: Just create the file and write there your header MIME items and its values. - -Q: What do you mean "header MIME items" and "its values"? -A: Every mail has header consisting of MIME items like "Subject" or "Return-Path". - -Q: So I need to understand how the header looks like... -A: Yes, if you want to use this filter, you should. Header MIME is defined in RFC822 standard. - -Q: Ok, I've just studied it. So how to set filter (write some rules to the blacklist file)? -A: Each line is one rule: write the exact item, press , press the substring of value needed to be found, press , define spamlevel and then press . - -Q: Spamlevel? -A: Yes. - 0=do not notify - 1=notify, display with another color in mailbrowser - 2=do not notify, display with another color in mailbrowser - 3=delete, display in mailbrowser about deleted mail - 4=delete, do not display (mail's quick death, hehe) - -Q: So the rule has 3 parameters, that's it? -A: Yes. This is the example: -<------ start of file ------> -From CrazyMail 1 -X-Importance low 0 -Subject LinuxMailList 0 -Return-Path cheapsoftware@junkmails.net 2 -X-TextClassification spam 3 -<------ end of file -------> - -Q: Wait while. Ok, but it does not work. -A: Check if you have this plugin listed in Miranda/Options/Plugins/YAMN item - -Q: No, it is not listed in YAMN plugins. -A: Then check if the dll residents in Plugins/YAMN direcotry. - -Q: This directory does not exists. -A: Create it and put the dll there. Restart Miranda. - -Q: Hmmm, ok. But it is not still listed. -A: Your version of YAMN and filter does not match. - -Q: And? -A: Try to look to http://www.majvan.host.sk/Projekty/YAMN for updates. - -Q: Now, it is listed, but does not work anyway. -A: Try to download debug version from YAMN homepage, if you are not using it (the name of filter must contain the word "debug") - -Q: What does debug version do? -A: It creates debug log file in Miranda home directory where you can browse how does filter mark mails. \ No newline at end of file diff --git a/protocols/YAMN/filter/Base/maindll.cpp b/protocols/YAMN/filter/Base/maindll.cpp deleted file mode 100644 index 1cb9d92338..0000000000 --- a/protocols/YAMN/filter/Base/maindll.cpp +++ /dev/null @@ -1,238 +0,0 @@ -//--------------------------------------------------------------------------- -#include -#include -#include -#include -#include -#include -#include -#include -#include "../../m_filterplugin.h" -#if !defined(_WIN64) - #include "aggressiveoptimize.h" -#endif - -typedef INT_PTR(* MIRANDASERVICE)(WPARAM,LPARAM); - -DWORD WINAPI FilterMail(HACCOUNT Account,DWORD AccountVer,HYAMNMAIL Mail,DWORD MailVer);//Function marks mail as spam when it is spam... -DWORD WINAPI UnLoadFilter(LPVOID); - -int LoadRules(); //Load rules from file -int findsubstr(char *original,char *pattern); //finds if original contains substring - -YAMN_FILTERIMPORTFCN FilterFunctions= //we set for YAMN which is our filter function -{ - FilterMail, - UnLoadFilter, -}; - -struct cFilterTable -{ - char account[256]; - char name[256]; - char value[256]; - unsigned char sl; -} *ft=NULL; -int fts=0; - -YAMN_FILTERREGISTRATION FilterRegistration= //classical YAMN registration -{ -#ifdef DEBUG_FILTER - "Base filter plugin for YAMN (debug)", -#else - "Base filter plugin for YAMN", -#endif - "", - "© majvan", - "Classifies mails using the rules stored in file", - "om3tn@psg.sk", - "http://www.majvan.host.sk/Projekty/YAMN?fm=soft", -}; - -char *FilterPath=NULL; - -struct YAMNExportedFcn -{ - YAMN_SETFILTERPLUGINFCNIMPORTFCN SetFilterPluginFcnImportFcn; - MIRANDASERVICE RegisterFilterPlugin; -} YAMNFcn,*pYAMNFcn; //exported functions from YAMN we will use - -HYAMNFILTERPLUGIN POPFilePlugin; //handle of this plugin for YAMN -HINSTANCE hInst; //handle of this DLL for Windows - -#ifdef DEBUG_FILTER -extern void InitDebug(); -extern void UnInitDebug(); -extern void DebugLog(HANDLE File,const char *fmt,...); -extern HANDLE FilterFile; -#endif - -extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved) -{ - hInst=hinstDLL; - return true; -} - -extern "C" int __declspec(dllexport) LoadFilter(MIRANDASERVICE GetYAMNFcnPtr) -{ - FilterPath=new char[MAX_PATH]; - char *delim; - pYAMNFcn=&YAMNFcn; - - GetModuleFileName(GetModuleHandle(NULL),FilterPath,MAX_PATH); - if(NULL!=(delim=strrchr(FilterPath,'\\'))) - *delim=0; - lstrcat(FilterPath,"\\basefilterdeny.txt"); -#ifdef DEBUG_FILTER - InitDebug(); -#endif - - if (!LoadRules()) - return 0; - - pYAMNFcn->RegisterFilterPlugin=(MIRANDASERVICE)GetYAMNFcnPtr((WPARAM)MS_YAMN_REGISTERFILTERPLUGIN,(LPARAM)0); - pYAMNFcn->SetFilterPluginFcnImportFcn=(YAMN_SETFILTERPLUGINFCNIMPORTFCN)GetYAMNFcnPtr((WPARAM)YAMN_SETFILTERPLUGINFCNIMPORTID,(LPARAM)0); -//Register our filter plugin to YAMN - if(NULL==(POPFilePlugin=(HYAMNFILTERPLUGIN)pYAMNFcn->RegisterFilterPlugin((WPARAM)&FilterRegistration,(LPARAM)YAMN_FILTERREGISTRATIONVERSION))) - return 0; -//And add our imported functions for YAMN - if (!pYAMNFcn->SetFilterPluginFcnImportFcn(POPFilePlugin,0xb0000000,&FilterFunctions,YAMN_FILTERIMPORTFCNVERSION)) - return 0; - return 1; //Load luccess -} - -DWORD WINAPI UnLoadFilter(LPVOID) -{ -#ifdef DEBUG_FILTER - UnInitDebug(); -#endif - if(FilterPath!=NULL) - delete[] FilterPath; - FilterPath=NULL; - - return 0; -} - -extern "C" int __declspec(dllexport) UninstallFilter() -{ - if(FilterPath==NULL) - MessageBox(NULL,"Cannot delete blacklist file when Base Filter is not loaded. Please do it manually.","Base Filter uninstalling",MB_OK|MB_ICONWARNING); - else - DeleteFile(FilterPath); - return 0; -} - - -//And this is main filter function. -DWORD WINAPI FilterMail(HACCOUNT Account,DWORD AccountVer,HYAMNMAIL Mail,DWORD MailVer) -{ - struct CMimeItem *Browser; - - if(MailVer!=YAMN_MAILVERSION) //we test if we work with the right YAMNMAIL - return 0; - if(Mail->MailData==NULL) //MailData should be available - return 0; - -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\n"); -#endif - if (!(Mail->Flags & YAMN_MSG_VIRTUAL)) - for(Browser=Mail->MailData->TranslatedHeader;Browser!=NULL;Browser=Browser->Next) //we browse all header stored in Mail->TranslatedHeader - { -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\n",Browser->name,Browser->value); -#endif - for(int i=0;iname,ft[i].name)) - { -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\t\t\n",Browser->name); -#endif - if(findsubstr(Browser->value,ft[i].value)) //and if we find - { - if ((ft[i].sl==0) && ((Mail->Flags & YAMN_MSG_SPAMMASK)==0)) - { - Mail->Flags&=~(YAMN_MSG_POPUP | YAMN_MSG_SYSTRAY | YAMN_MSG_BROWSER | YAMN_MSG_SOUND | YAMN_MSG_APP | YAMN_MSG_NEVENT); -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\t\tSetting individual flags not to notify mail, but does not consider as spam."); -#endif - } - else if ((Mail->Flags & YAMN_MSG_SPAMMASK) < ft[i].sl) //if some filter plugin set higher level of spam, we do nothing - { - Mail->Flags=(Mail->Flags & ~YAMN_MSG_SPAMMASK)+ft[i].sl; //else we set spam level 2 (clearing spam bits and then settting them to level 2 -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\t\tMail marked to be spam #%d\n",Mail->Flags & YAMN_MSG_SPAMMASK); -#endif - } - } -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\t\t\n"); -#endif - } -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\n"); -#endif - } -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\n\n"); -#endif - return 1; -} - -int LoadRules() -{ - char *account=NULL; - char name[256]; - char value[256]; - char BadCompiler[512+5]; - unsigned char sl; - FILE *fp; - -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\n",FilterPath); -#endif - - fp=fopen(FilterPath,"rt"); - if(fp==NULL) - return 0; - - while(!feof(fp)) - { - if(fscanf(fp,"%255s",name) && !feof(fp) && (name[0]!=0)) - { - if(fscanf(fp,"%255s",value) && !feof(fp) && (value[0]!=0)) - { - if(fscanf(fp,"%d",&sl)) - { - fts++; - ft=(struct cFilterTable *)realloc((void *)ft,sizeof(cFilterTable)*fts); - lstrcpy(ft[fts-1].name,name); - lstrcpy(ft[fts-1].value,value); - ft[fts-1].sl=sl; - - sprintf(BadCompiler,"%s %s %d",name,value,sl); -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\t%s%s%d\n",name,value,sl); -#endif - } - } - } - } - - fclose(fp); -#ifdef DEBUG_FILTER - DebugLog(FilterFile,"\n"); -#endif - return 1; -} - -int findsubstr(char *original,char *pattern) -{ - int ol=lstrlen(original); - int pl=lstrlen(pattern); - - for(int i=0;(i+pl)<=ol;i++) - if (!_strnicmp(original+i,pattern,pl)) - return 1; - return 0; -} \ No newline at end of file diff --git a/protocols/YAMN/filter/Simple/AggressiveOptimize.h b/protocols/YAMN/filter/Simple/AggressiveOptimize.h deleted file mode 100644 index 1bf0e19c2c..0000000000 --- a/protocols/YAMN/filter/Simple/AggressiveOptimize.h +++ /dev/null @@ -1,168 +0,0 @@ - -////////////////////////////// -// Version 1.40 -// October 22nd, 2002 - .NET (VC7, _MSC_VER=1300) support! -// Version 1.30 -// Nov 24th, 2000 -// Version 1.20 -// Jun 9th, 2000 -// Version 1.10 -// Jan 23rd, 2000 -// Version 1.00 -// May 20th, 1999 -// Todd C. Wilson, Fresh Ground Software -// (todd@nopcode.com) -// This header file will kick in settings for Visual C++ 5 and 6 that will (usually) -// result in smaller exe's. -// The "trick" is to tell the compiler to not pad out the function calls; this is done -// by not using the /O1 or /O2 option - if you do, you implicitly use /Gy, which pads -// out each and every function call. In one single 500k dll, I managed to cut out 120k -// by this alone! -// The other two "tricks" are telling the Linker to merge all data-type segments together -// in the exe file. The relocation, read-only (constants) data, and code section (.text) -// sections can almost always be merged. Each section merged can save 4k in exe space, -// since each section is padded out to 4k chunks. This is very noticeable with smaller -// exes, since you could have only 700 bytes of data, 300 bytes of code, 94 bytes of -// strings - padded out, this could be 12k of runtime, for 1094 bytes of stuff! For larger -// programs, this is less overall, but can save at least 4k. -// Note that if you're using MFC static or some other 3rd party libs, you may get poor -// results with merging the readonly (.rdata) section - the exe may grow larger. -// To use this feature, define _MERGE_DATA_ in your project or before this header is used. -// With Visual C++ 5, the program uses a file alignment of 512 bytes, which results -// in a small exe. Under VC6, the program instead uses 4k, which is the same as the -// section size. The reason (from what I understand) is that 4k is the chunk size of -// the virtual memory manager, and that WinAlign (an end-user tuning tool for Win98) -// will re-align the programs on this boundary. The problem with this is that all of -// Microsoft's system exes and dlls are *NOT* tuned like this, and using 4k causes serious -// exe bloat. This is very noticeable for smaller programs. -// The "trick" for this is to use the undocumented FILEALIGN linker parm to change the -// padding from 4k to 1/2k, which results in a much smaller exe - anywhere from 20%-75% -// depending on the size. Note that this is the same as using /OPT:NOWIN98, which *is* -// a previously documented switch, but was left out of the docs for some reason in VC6 and -// all of the current MSDN's - see KB:Q235956 for more information. -// Microsoft does say that using the 4k alignment will "speed up process loading", -// but I've been unable to notice a difference, even on my P180, with a very large (4meg) exe. -// Please note, however, that this will probably not change the size of the COMPRESSED -// file (either in a .zip file or in an install archive), since this 4k is all zeroes and -// gets compressed away. -// Also, the /ALIGN:4096 switch will "magically" do the same thing, even though this is the -// default setting for this switch. Apparently this sets the same values as the above two -// switches do. We do not use this in this header, since it smacks of a bug and not a feature. -// Thanks to Michael Geary for some additional tips! -// -// Notes about using this header in .NET -// First off, VC7 does not allow a lot of the linker command options in pragma's. There is no -// honest or good reason why Microsoft decided to make this change, it just doesn't. -// So that is why there are a lot of <1300 #if's in the header. -// If you want to take full advantage of the VC7 linker options, you will need to do it on a -// PER PROJECT BASIS; you can no longer use a global header file like this to make it better. -// Items I strongly suggest putting in all your VC7 project linker options command line settings: -// /ignore:4078 /RELEASE -// Compiler options: -// /GL (Whole Program Optimization) -// If you're making an .EXE and not a .DLL, consider adding in: -// /GA (Optimize for Windows Application) -// Some items to consider using in your VC7 projects (not VC6): -// Link-time Code Generation - whole code optimization. Put this in your exe/dll project link settings. -// /LTCG:NOSTATUS -// The classic no-padding and no-bloat compiler C/C++ switch: -// /opt:nowin98 -// -// (C++ command line options: /GL /opt:nowin98 and /GA for .exe files) -// (Link command line options: /ignore:4078 /RELEASE /LTCG:NOSTATUS) -// -// Now, notes on using these options in VC7 vs VC6. -// VC6 consistently, for me, produces smaller code from C++ the exact same sources, -// with or without this header. On average, VC6 produces 5% smaller binaries compared -// to VC7 compiling the exact same project, *without* this header. With this header, VC6 -// will make a 13k file, while VC7 will make a 64k one. VC7 is just bloaty, pure and -// simple - all that managed/unmanaged C++ runtimes, and the CLR stuff must be getting -// in the way of code generation. However, template support is better, so there. -// Both VC6 and VC7 show the same end kind of end result savings - larger binary output -// will shave about 2% off, where as smaller projects (support DLL's, cpl's, -// activex controls, ATL libs, etc) get the best result, since the padding is usually -// more than the actual usable code. But again, VC7 does not compile down as small as VC6. -// -// The argument can be made that doing this is a waste of time, since the "zero bytes" -// will be compressed out in a zip file or install archive. Not really - it doesn't matter -// if the data is a string of zeroes or ones or 85858585 - it will still take room (20 bytes -// in a zip file, 29 bytes if only *4* of them 4k bytes are not the same) and time to -// compress that data and decompress it. Also, 20k of zeros is NOT 20k on disk - it's the -// size of the cluster slop- for Fat32 systems, 20k can be 32k, NTFS could make it 24k if you're -// just 1 byte over (round up). Most end users do not have the dual P4 Xeon systems with -// two gigs of RDram and a Raid 0+1 of Western Digital 120meg Special Editions that all -// worthy developers have (all six of us), so they will need any space and LOADING TIME -// savings they will need; taking an extra 32k or more out of your end user's 64megs of -// ram on Windows 98 is Not a Good Thing. -// -// Now, as a ADDED BONUS at NO EXTRA COST TO YOU! Under VC6, using the /merge:.text=.data -// pragma will cause the output file to be un-disassembleable! (is that a word?) At least, -// with the normal tools - WinDisam, DumpBin, and the like will not work. Try it - use the -// header, compile release, and then use DUMPBIN /DISASM filename.exe - no code! -// Thanks to Gëzim Pani for discovering this gem - for a full writeup on -// this issue and the ramifactions of it, visit www.nopcode.com for the Aggressive Optimize -// article. - -#ifndef _AGGRESSIVEOPTIMIZE_H_ -#define _AGGRESSIVEOPTIMIZE_H_ - -#pragma warning(disable:4711) - -#ifdef NDEBUG -// /Og (global optimizations), /Os (favor small code), /Oy (no frame pointers) -#pragma optimize("gsy",on) - -#if (_MSC_VER<1300) - #pragma comment(linker,"/RELEASE") -#endif - -/* -// Note that merging the .rdata section will result in LARGER exe's if you using -// MFC (esp. static link). If this is desirable, define _MERGE_RDATA_ in your project. -#ifdef _MERGE_RDATA_ -#pragma comment(linker,"/merge:.rdata=.data") -#endif // _MERGE_RDATA_ - -#pragma comment(linker,"/merge:.text=.data") -#if (_MSC_VER<1300) - // In VC7, this causes problems with the relocation and data tables, so best to not merge them - #pragma comment(linker,"/merge:.reloc=.data") -#endif -*/ - -// Merging sections with different attributes causes a linker warning, so -// turn off the warning. From Michael Geary. Undocumented, as usual! -#if (_MSC_VER<1300) - // In VC7, you will need to put this in your project settings - #pragma comment(linker,"/ignore:4078") -#endif - -// With Visual C++ 5, you already get the 512-byte alignment, so you will only need -// it for VC6, and maybe later. -#if _MSC_VER >= 1000 - -// Option #1: use /filealign -// Totally undocumented! And if you set it lower than 512 bytes, the program crashes. -// Either leave at 0x200 or 0x1000 -//#pragma comment(linker,"/FILEALIGN:0x200") - -// Option #2: use /opt:nowin98 -// See KB:Q235956 or the READMEVC.htm in your VC directory for info on this one. -// This is our currently preferred option, since it is fully documented and unlikely -// to break in service packs and updates. -#if (_MSC_VER<1300) - // In VC7, you will need to put this in your project settings - #pragma comment(linker,"/opt:nowin98") -#else - -// Option #3: use /align:4096 -// A side effect of using the default align value is that it turns on the above switch. -// Does nothing under Vc7 that /opt:nowin98 doesn't already give you -// #pragma comment(linker,"/ALIGN:512") -#endif - -#endif // _MSC_VER >= 1000 - -#endif // NDEBUG - -#endif // _AGGRESSIVEOPTIMIZE_H_ diff --git a/protocols/YAMN/filter/Simple/docs/simple-readme.txt b/protocols/YAMN/filter/Simple/docs/simple-readme.txt deleted file mode 100644 index 34c0842c87..0000000000 --- a/protocols/YAMN/filter/Simple/docs/simple-readme.txt +++ /dev/null @@ -1,51 +0,0 @@ -========================== -= Simple Filter for YAMN = -========================== - -Q: What??? -A: YAMN filter to classify incoming email. - -Q: How? -A: Regarding what the email is from and finding it in the blacklist email file. - -Q: Blacklist email file? -A: Yes. It is created by yourself and located in Miranda directory with name 'simplefilterdeny.txt' - -Q: Created by myself? -A: Just create the file and write there your blacklist mails in every line. - -Q: That's all? -A: Yes and no. You can specify spamlevel for each mail. - -Q: Spamlevel? -A: Yes. - 1=notify, display with another color in mailbrowser - 2=do not notify, display with another color in mailbrowser - 3=delete, display in mailbrowser about deleted mail - 4=delete, do not display (mail's quick death, hehe) - -Q: How to specify it? -A: After email press and write number 1-4. Note this is optional. If not defined, level 2 is default. - -Q: Ok, that's easy. -A: Yes, this is the example: -<------ start of file ------> -nigeria@spamserver.com 2 -cheapsoftware@junkmails.net 3 -learnenglish@commercial.org -<------ end of file -------> - -Q: Wait while. Ok, but it does not work. -A: Check if you have this plugin listed in Miranda/Options/Plugins/YAMN item as YAMN plugin. - -Q: No, it is not listed in YAMN plugins. -A: Then check if the dll residents in Plugins/YAMN direcotry. - -Q: This directory does not exists. -A: Create it and put the dll there. Restart Miranda. - -Q: Hmmm, ok. But it is not still listed. -A: Your version of YAMN and filter does not match. - -Q: And? -A: Try to look to http://www.majvan.host.sk/Projekty/YAMN for updates. \ No newline at end of file diff --git a/protocols/YAMN/filter/Simple/maindll.cpp b/protocols/YAMN/filter/Simple/maindll.cpp deleted file mode 100644 index 44a277d4fa..0000000000 --- a/protocols/YAMN/filter/Simple/maindll.cpp +++ /dev/null @@ -1,132 +0,0 @@ -//--------------------------------------------------------------------------- -#include -#include -#include -#include -#include -#include -#include -#include -#include "../../m_filterplugin.h" -#if !defined(_WIN64) - #include "aggressiveoptimize.h" -#endif - -typedef INT_PTR(* MIRANDASERVICE)(WPARAM,LPARAM); - -DWORD WINAPI FilterMail(HACCOUNT Account,DWORD AccountVer,HYAMNMAIL Mail,DWORD MailVer);//Function marks mail as spam when it is spam... -DWORD WINAPI UnLoadFilter(LPVOID); - -YAMN_FILTERIMPORTFCN FilterFunctions= //we set for YAMN which is our filter function -{ - FilterMail, - UnLoadFilter, //No unloading -}; - -YAMN_FILTERREGISTRATION FilterRegistration= //classical YAMN registration -{ - "Simple filter plugin for YAMN", - "", - "© porter+ majvan", - "Classifies mails using the blacklist emails stored in file", - "porterbox@hotmail.com", - "http://www.majvan.host.sk/Projekty/YAMN?fm=soft", -}; - -char *FilterPath=NULL; - -struct YAMNExportedFcn -{ - YAMN_SETFILTERPLUGINFCNIMPORTFCN SetFilterPluginFcnImportFcn; - MIRANDASERVICE RegisterFilterPlugin; -} YAMNFcn,*pYAMNFcn; //exported functions from YAMN we will use - -HYAMNFILTERPLUGIN POPFilePlugin; //handle of this plugin for YAMN -HINSTANCE hInst; //handle of this DLL for Windows - -extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved) -{ - hInst=hinstDLL; - return true; -} - -extern "C" int __declspec(dllexport) LoadFilter(MIRANDASERVICE GetYAMNFcnPtr) -{ - FilterPath=new char[MAX_PATH]; - char *delim; - pYAMNFcn=&YAMNFcn; - - GetModuleFileName(GetModuleHandle(NULL),FilterPath,MAX_PATH); - if(NULL!=(delim=strrchr(FilterPath,'\\'))) - *delim=0; - lstrcat(FilterPath,"\\simplefilterdeny.txt"); - - pYAMNFcn->RegisterFilterPlugin=(MIRANDASERVICE)GetYAMNFcnPtr((WPARAM)MS_YAMN_REGISTERFILTERPLUGIN,(LPARAM)0); - pYAMNFcn->SetFilterPluginFcnImportFcn=(YAMN_SETFILTERPLUGINFCNIMPORTFCN)GetYAMNFcnPtr((WPARAM)YAMN_SETFILTERPLUGINFCNIMPORTID,(LPARAM)0); -//Register our filter plugin to YAMN - if(NULL==(POPFilePlugin=(HYAMNFILTERPLUGIN)pYAMNFcn->RegisterFilterPlugin((WPARAM)&FilterRegistration,(LPARAM)YAMN_FILTERREGISTRATIONVERSION))) - return 0; -//And add our imported functions for YAMN - if (!pYAMNFcn->SetFilterPluginFcnImportFcn(POPFilePlugin,0xb0000000,&FilterFunctions,YAMN_FILTERIMPORTFCNVERSION)) - return 0; - return 1; //Load luccess -} - -DWORD WINAPI UnLoadFilter(LPVOID) -{ - if(FilterPath!=NULL) - delete[] FilterPath; - FilterPath=NULL; - - return 0; -} - -extern "C" int __declspec(dllexport) UninstallFilter() -{ - if(FilterPath==NULL) - MessageBox(NULL,"Cannot delete blacklist file when Simple Filter is not loaded. Please do it manually.","Simple Filter uninstalling",MB_OK|MB_ICONWARNING); - else - DeleteFile(FilterPath); - return 0; -} - - -//And this is main filter function. -DWORD WINAPI FilterMail(HACCOUNT Account,DWORD AccountVer,HYAMNMAIL Mail,DWORD MailVer) -{ - FILE *fp; - char EmailSpam[256]; - unsigned char spamLevel; - struct CMimeItem *Browser; - - if(MailVer!=YAMN_MAILVERSION) //we test if we work with the right YAMNMAIL - return 0; - if(Mail->MailData==NULL) //MailData should be available - return 0; - fp=fopen(FilterPath,"rt"); - if(fp != NULL) { - if (!(Mail->Flags & YAMN_MSG_VIRTUAL)) - for(Browser=Mail->MailData->TranslatedHeader;Browser!=NULL;Browser=Browser->Next) { //we browse all header stored in Mail->TranslatedHeader - if ((!lstrcmp(Browser->name,"Return-Path")) || (!lstrcmp(Browser->name,"From"))) { //and if we find - fseek(fp, 0L, SEEK_SET); - while(!feof(fp)) { - if(fscanf(fp, "%255s", EmailSpam) != 0) { - if (!feof(fp)) - if(fscanf(fp, "%d", &spamLevel)==0) - spamLevel=2; - if(spamLevel>4) - spamLevel=2; - if(strstr(Browser->value,EmailSpam)!=NULL) { - if ((Mail->Flags & (YAMN_MSG_SPAMMASK==0)) && (spamLevel==0)) - Mail->Flags&=~(YAMN_MSG_SOUND | YAMN_MSG_APP | YAMN_MSG_POPUP | YAMN_MSG_SYSTRAY | YAMN_MSG_BROWSER); - else if ((Mail->Flags & YAMN_MSG_SPAMMASK) < spamLevel) //if some filter plugin set higher level of spam, we do nothing - Mail->Flags=(Mail->Flags & ~YAMN_MSG_SPAMMASK)+spamLevel; //else we set spam level 2 (clearing spam bits and then settting them to level 2 - } - } - } - } - } - fclose(fp); - } - return 1; -} diff --git a/protocols/YAMN/filter/Simple/simple.dsp b/protocols/YAMN/filter/Simple/simple.dsp deleted file mode 100644 index dc6d52e6c1..0000000000 --- a/protocols/YAMN/filter/Simple/simple.dsp +++ /dev/null @@ -1,105 +0,0 @@ -# Microsoft Developer Studio Project File - Name="simple" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** NICHT BEARBEITEN ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=simple - Win32 Release -!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE -!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl -!MESSAGE -!MESSAGE NMAKE /f "simple.mak". -!MESSAGE -!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben -!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: -!MESSAGE -!MESSAGE NMAKE /f "simple.mak" CFG="simple - Win32 Release" -!MESSAGE -!MESSAGE Für die Konfiguration stehen zur Auswahl: -!MESSAGE -!MESSAGE "simple - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library") -!MESSAGE "simple - Win32 Debug" (basierend auf "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "simple - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Ignore_Export_Lib 1 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /G4 /Zp4 /MD /W3 /GX /O1 /Ob0 /I "../../../../include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD CPP /nologo /G4 /Zp4 /MD /W3 /GX /Zi /O1 /Ob0 /I "../../../../include" /I "../../../../include/msapi" /I "../../../../include_API" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c -# ADD BASE RSC /l 0x417 /d "NDEBUG" -# ADD RSC /l 0x417 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib /nologo /dll /machine:I386 /out:"../../../../bin/release/plugins/YAMN-filter/simple.dll" /filealign:512 -# ADD LINK32 kernel32.lib user32.lib /nologo /dll /pdb:"../../../../bin/Release/plugins/YAMN/simple.pdb" /debug /machine:I386 /out:"../../../../bin/Release/plugins/YAMN/simple.dll" /filealign:512 - -!ELSEIF "$(CFG)" == "simple - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Ignore_Export_Lib 1 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /G4 /Zp4 /MDd /W3 /Gm /Gi /GX /ZI /Od /I "../../../../include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /GZ /c -# ADD CPP /nologo /G4 /Zp4 /MDd /W3 /Gm /Gi /GX /ZI /Od /I "../../../../include" /I "../../../../include/msapi" /I "../../../../include_API" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /GZ /c -# ADD BASE RSC /l 0x417 /d "_DEBUG" -# ADD RSC /l 0x417 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib /nologo /dll /debug /machine:I386 /out:"../../../../bin/Debug/plugins/YAMN-filter/simple.dll" -# ADD LINK32 kernel32.lib user32.lib /nologo /dll /pdb:"../../../../bin/Debug/plugins/YAMN/simple.pdb" /debug /machine:I386 /out:"../../../../bin/Debug/plugins/YAMN/simple.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "simple - Win32 Release" -# Name "simple - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\maindll.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/protocols/YAMN/filter/Simple/simple.mak b/protocols/YAMN/filter/Simple/simple.mak deleted file mode 100644 index 085dc22e33..0000000000 --- a/protocols/YAMN/filter/Simple/simple.mak +++ /dev/null @@ -1,207 +0,0 @@ -# Microsoft Developer Studio Generated NMAKE File, Based on simple.dsp -!IF "$(CFG)" == "" -CFG=simple - Win32 Release -!MESSAGE No configuration specified. Defaulting to simple - Win32 Release. -!ENDIF - -!IF "$(CFG)" != "simple - Win32 Release" && "$(CFG)" != "simple - Win32 Debug" -!MESSAGE Invalid configuration "$(CFG)" specified. -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "simple.mak" CFG="simple - Win32 Release" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "simple - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "simple - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE -!ERROR An invalid configuration is specified. -!ENDIF - -!IF "$(OS)" == "Windows_NT" -NULL= -!ELSE -NULL=nul -!ENDIF - -!IF "$(CFG)" == "simple - Win32 Release" - -OUTDIR=.\Release -INTDIR=.\Release - -ALL : "..\..\..\..\bin\release\plugins\YAMN-filter\simple.dll" - - -CLEAN : - -@erase "$(INTDIR)\maindll.obj" - -@erase "$(INTDIR)\vc60.idb" - -@erase "$(OUTDIR)\simple.exp" - -@erase "..\..\..\..\bin\release\plugins\YAMN-filter\simple.dll" - -"$(OUTDIR)" : - if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" - -CPP=cl.exe -CPP_PROJ=/nologo /G4 /Zp4 /MD /W3 /GX /O1 /Ob0 /I "../../../../include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\simple.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c - -.c{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cpp{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cxx{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.c{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cpp{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cxx{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -MTL=midl.exe -MTL_PROJ= -RSC=rc.exe -BSC32=bscmake.exe -BSC32_FLAGS=/nologo /o"$(OUTDIR)\simple.bsc" -BSC32_SBRS= \ - -LINK32=link.exe -LINK32_FLAGS=kernel32.lib user32.lib /nologo /dll /incremental:no /pdb:"$(OUTDIR)\simple.pdb" /machine:I386 /out:"../../../../bin/release/plugins/YAMN-filter/simple.dll" /implib:"$(OUTDIR)\simple.lib" /filealign:512 -LINK32_OBJS= \ - "$(INTDIR)\maindll.obj" - -"..\..\..\..\bin\release\plugins\YAMN-filter\simple.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) - $(LINK32) @<< - $(LINK32_FLAGS) $(LINK32_OBJS) -<< - -!ELSEIF "$(CFG)" == "simple - Win32 Debug" - -OUTDIR=.\Debug -INTDIR=.\Debug -# Begin Custom Macros -OutDir=.\Debug -# End Custom Macros - -ALL : "..\..\..\..\bin\Debug\plugins\YAMN-filter\simple.dll" "$(OUTDIR)\simple.bsc" - - -CLEAN : - -@erase "$(INTDIR)\maindll.obj" - -@erase "$(INTDIR)\maindll.sbr" - -@erase "$(INTDIR)\vc60.idb" - -@erase "$(INTDIR)\vc60.pdb" - -@erase "$(OUTDIR)\simple.bsc" - -@erase "$(OUTDIR)\simple.exp" - -@erase "$(OUTDIR)\simple.pdb" - -@erase "..\..\..\..\bin\Debug\plugins\YAMN-filter\simple.dll" - -@erase "..\..\..\..\bin\Debug\plugins\YAMN-filter\simple.ilk" - -"$(OUTDIR)" : - if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" - -CPP=cl.exe -CPP_PROJ=/nologo /G4 /Zp4 /MDd /W3 /Gm /Gi /GX /ZI /Od /I "../../../../include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\simple.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c - -.c{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cpp{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cxx{$(INTDIR)}.obj:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.c{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cpp{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -.cxx{$(INTDIR)}.sbr:: - $(CPP) @<< - $(CPP_PROJ) $< -<< - -MTL=midl.exe -MTL_PROJ= -RSC=rc.exe -BSC32=bscmake.exe -BSC32_FLAGS=/nologo /o"$(OUTDIR)\simple.bsc" -BSC32_SBRS= \ - "$(INTDIR)\maindll.sbr" - -"$(OUTDIR)\simple.bsc" : "$(OUTDIR)" $(BSC32_SBRS) - $(BSC32) @<< - $(BSC32_FLAGS) $(BSC32_SBRS) -<< - -LINK32=link.exe -LINK32_FLAGS=kernel32.lib user32.lib /nologo /dll /incremental:yes /pdb:"$(OUTDIR)\simple.pdb" /debug /machine:I386 /out:"../../../../bin/Debug/plugins/YAMN-filter/simple.dll" /implib:"$(OUTDIR)\simple.lib" -LINK32_OBJS= \ - "$(INTDIR)\maindll.obj" - -"..\..\..\..\bin\Debug\plugins\YAMN-filter\simple.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) - $(LINK32) @<< - $(LINK32_FLAGS) $(LINK32_OBJS) -<< - -!ENDIF - - -!IF "$(NO_EXTERNAL_DEPS)" != "1" -!IF EXISTS("simple.dep") -!INCLUDE "simple.dep" -!ELSE -!MESSAGE Warning: cannot find "simple.dep" -!ENDIF -!ENDIF - - -!IF "$(CFG)" == "simple - Win32 Release" || "$(CFG)" == "simple - Win32 Debug" -SOURCE=.\maindll.cpp - -!IF "$(CFG)" == "simple - Win32 Release" - - -"$(INTDIR)\maindll.obj" : $(SOURCE) "$(INTDIR)" - - -!ELSEIF "$(CFG)" == "simple - Win32 Debug" - - -"$(INTDIR)\maindll.obj" "$(INTDIR)\maindll.sbr" : $(SOURCE) "$(INTDIR)" - - -!ENDIF - - -!ENDIF - diff --git a/protocols/YAMN/filter/readme.txt b/protocols/YAMN/filter/readme.txt deleted file mode 100644 index a46db0236a..0000000000 --- a/protocols/YAMN/filter/readme.txt +++ /dev/null @@ -1 +0,0 @@ -This folder contains filter plugin sources for YAMN. \ No newline at end of file diff --git a/protocols/YAMN/filterplugin.cpp b/protocols/YAMN/filterplugin.cpp deleted file mode 100644 index 8f61003293..0000000000 --- a/protocols/YAMN/filterplugin.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * YAMN plugin export functions for filtering - * - * (c) majvan 2002-2004 - */ - -#include "yamn.h" - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -PYAMN_FILTERPLUGINQUEUE FirstFilterPlugin=NULL; - -INT_PTR RegisterFilterPluginSvc(WPARAM,LPARAM); - -//Removes plugin from queue and deletes its structures -INT_PTR UnregisterFilterPlugin(HYAMNFILTERPLUGIN Plugin); - -INT_PTR UnregisterFilterPluginSvc(WPARAM wParam,LPARAM lParam); - -//Removes all filter plugins -INT_PTR UnregisterFilterPlugins(); - -INT_PTR FilterMailSvc(WPARAM,LPARAM); - -//Sets imported functions for an plugin and therefore it starts plugin to be registered and running -// Plugin- plugin, which wants to set its functions -// Importance- importance of plugin (see m_filterplugin.h) -// YAMNFilterFcn- pointer to imported functions -// YAMNfilterFcnVer- version of YAMN_FILTERIMPORTFCN, use YAMN_FILTERIMPORTFCNVERSION -// returns nonzero if success -int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin,DWORD Importance,PYAMN_FILTERIMPORTFCN YAMNFilterFcn,DWORD YAMNFilterFcnVer); - -struct CExportedFunctions FilterPluginExportedFcn[]= -{ - {YAMN_SETFILTERPLUGINFCNIMPORTID,(void *)SetFilterPluginFcnImportFcn}, -}; - -struct CExportedServices FilterPluginExportedSvc[]= -{ - {MS_YAMN_REGISTERFILTERPLUGIN,RegisterFilterPluginSvc}, - {MS_YAMN_UNREGISTERFILTERPLUGIN,UnregisterFilterPluginSvc}, -}; - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -INT_PTR RegisterFilterPluginSvc(WPARAM wParam,LPARAM lParam) -{ - PYAMN_FILTERREGISTRATION Registration=(PYAMN_FILTERREGISTRATION)wParam; - HYAMNFILTERPLUGIN Plugin; - - if (lParam!=YAMN_FILTERREGISTRATIONVERSION) - return 0; - if ((Registration->Name==NULL) || (Registration->Ver==NULL)) - return NULL; - if (NULL==(Plugin=new YAMN_FILTERPLUGIN)) - return NULL; - - Plugin->PluginInfo=Registration; - - Plugin->FilterFcn=NULL; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- new filter registered: %0x (%s) :::\n",Plugin,Registration->Name); -#endif - return (INT_PTR)Plugin; -} - -INT_PTR UnregisterFilterPlugin(HYAMNFILTERPLUGIN Plugin) -{ - PYAMN_FILTERPLUGINQUEUE Parser,Found; - - if (FirstFilterPlugin->Plugin==Plugin) - { - Found=FirstFilterPlugin; - FirstFilterPlugin=FirstFilterPlugin->Next; - } - else - { - for (Parser=FirstFilterPlugin;(Parser->Next!=NULL) && (Plugin!=Parser->Next->Plugin);Parser=Parser->Next); - if (Parser->Next!=NULL) - { - Found=Parser->Next; - Parser->Next=Parser->Next->Next; - } - else - Found=NULL; - } - if (Found!=NULL) - { - if (Plugin->FilterFcn->UnLoadFcn!=NULL) - Plugin->FilterFcn->UnLoadFcn((void *)0); - - delete Found->Plugin; - delete Found; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- filter %0x unregistered :::\n",Plugin); -#endif - } - else - return 0; - return 1; -} - -INT_PTR UnregisterFilterPluginSvc(WPARAM wParam,LPARAM lParam) -{ - HYAMNFILTERPLUGIN Plugin=(HYAMNFILTERPLUGIN)wParam; - - EnterCriticalSection(&PluginRegCS); - UnregisterFilterPlugin(Plugin); - LeaveCriticalSection(&PluginRegCS); - return 1; -} - -INT_PTR UnregisterFilterPlugins() -{ - EnterCriticalSection(&PluginRegCS); -//We remove protocols from the protocol list - while(FirstFilterPlugin!=NULL) - UnregisterFilterPlugin(FirstFilterPlugin->Plugin); - LeaveCriticalSection(&PluginRegCS); - return 1; -} - -int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin,DWORD Importance,PYAMN_FILTERIMPORTFCN YAMNFilterFcn,DWORD YAMNFilterFcnVer) -{ - PYAMN_FILTERPLUGINQUEUE Parser,Previous; - - if (YAMNFilterFcnVer!=YAMN_FILTERIMPORTFCNVERSION) - return 0; - if (YAMNFilterFcn==NULL) - return 0; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- filter %0x import succeed :::\n",Plugin); -#endif - Plugin->Importance=Importance; - Plugin->FilterFcn=YAMNFilterFcn; - - EnterCriticalSection(&PluginRegCS); -//We add protocol to the protocol list - for (Previous=NULL,Parser=FirstFilterPlugin;Parser!=NULL && Parser->Next!=NULL && Parser->Plugin->Importance<=Importance;Previous=Parser,Parser=Parser->Next); - if (Previous==NULL) //insert to the beginnig of queue - { - FirstFilterPlugin=new YAMN_FILTERPLUGINQUEUE; - FirstFilterPlugin->Plugin=Plugin; - FirstFilterPlugin->Next=Parser; - } - else - { - Previous->Next=new YAMN_FILTERPLUGINQUEUE; - Previous=Previous->Next; //leave previous, go to actual plugin - Previous->Plugin=Plugin; - Previous->Next=Parser; //and in actual plugin set, that next plugin is the one we insert in front of - } - - LeaveCriticalSection(&PluginRegCS); - return 1; -} - -INT_PTR FilterMailSvc(WPARAM wParam,LPARAM lParam) -{ - HACCOUNT Account=(HACCOUNT)wParam; - HYAMNMAIL Mail=(HYAMNMAIL)lParam; - PYAMN_FILTERPLUGINQUEUE ActualPlugin; - - EnterCriticalSection(&PluginRegCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write wait\n"); -#endif - WaitToWriteFcn(Account->MessagesAccessSO); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write enter\n"); -#endif - for (ActualPlugin=FirstFilterPlugin;ActualPlugin!=NULL;ActualPlugin=ActualPlugin->Next) - { - if (ActualPlugin->Plugin->FilterFcn->FilterMailFcnPtr!=NULL) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tFiltering Mail, running plugin %0x to filter mail\n",ActualPlugin->Plugin); -#endif - ActualPlugin->Plugin->FilterFcn->FilterMailFcnPtr(Account,YAMN_ACCOUNTVERSION,Mail,YAMN_MAILVERSION); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tFiltering Mail done\n"); -#endif - } - } - Mail->Flags|=YAMN_MSG_FILTERED; - -//Set mail flags according to spamlevel settings - if ((Mail->Flags & YAMN_MSG_SPAMMASK) > YAMN_MSG_SPAML1) - Mail->Flags=Mail->Flags & ~(YAMN_MSG_BROWSER | YAMN_MSG_POPUP | YAMN_MSG_SYSTRAY | YAMN_MSG_SOUND | YAMN_MSG_APP | YAMN_MSG_NEVENT); - if (YAMN_MSG_SPAML(Mail->Flags,YAMN_MSG_SPAML3) || YAMN_MSG_SPAML(Mail->Flags,YAMN_MSG_SPAML4)) - Mail->Flags=Mail->Flags | (YAMN_MSG_AUTODELETE | YAMN_MSG_DELETEOK); //set message to delete - if (YAMN_MSG_SPAML(Mail->Flags,YAMN_MSG_SPAML3)) - Mail->Flags=Mail->Flags & ~(YAMN_MSG_MEMDELETE); //set message not to delete it immidiatelly from memory -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write done\n"); -#endif - WriteDoneFcn(Account->MessagesAccessSO); - LeaveCriticalSection(&PluginRegCS); - return 1; -} diff --git a/protocols/YAMN/icons/iconttbup.ico b/protocols/YAMN/icons/iconttbup.ico deleted file mode 100644 index ad18c56822..0000000000 Binary files a/protocols/YAMN/icons/iconttbup.ico and /dev/null differ diff --git a/protocols/YAMN/icons/icoyamn1.ico b/protocols/YAMN/icons/icoyamn1.ico deleted file mode 100644 index d3959b4fd7..0000000000 Binary files a/protocols/YAMN/icons/icoyamn1.ico and /dev/null differ diff --git a/protocols/YAMN/icons/icoyamn2.ico b/protocols/YAMN/icons/icoyamn2.ico deleted file mode 100644 index dfada56b5f..0000000000 Binary files a/protocols/YAMN/icons/icoyamn2.ico and /dev/null differ diff --git a/protocols/YAMN/icons/proto_YAMN.rc b/protocols/YAMN/icons/proto_YAMN.rc deleted file mode 100644 index e20bd50bda..0000000000 --- a/protocols/YAMN/icons/proto_YAMN.rc +++ /dev/null @@ -1,19 +0,0 @@ -#include "resource.h" - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. - -IDI_ONLINE ICON DISCARDABLE "../resources/iconeutral.ico" -IDI_ICOYAMN1 ICON DISCARDABLE "icoyamn1.ico" -IDI_ICOYAMN2 ICON DISCARDABLE "icoyamn2.ico" -IDI_ICOTTBUP ICON DISCARDABLE "iconttbup.ico" - -IDI_OFFLINE ICON DISCARDABLE "../resources/icooffline.ico" -IDI_NA ICON DISCARDABLE "../resources/icoyamn3.ico" -IDI_OCCUPIED ICON DISCARDABLE "../resources/iconttbdown.ico" diff --git a/protocols/YAMN/icons/proto_YAMN_10.vcxproj b/protocols/YAMN/icons/proto_YAMN_10.vcxproj deleted file mode 100644 index 5cf5919162..0000000000 --- a/protocols/YAMN/icons/proto_YAMN_10.vcxproj +++ /dev/null @@ -1,142 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - Proto_YAMN - {C1CDB82C-6BBF-496E-88F4-CC57E60B0CA9} - - - - DynamicLibrary - Unicode - - - DynamicLibrary - Unicode - - - DynamicLibrary - Unicode - - - DynamicLibrary - Unicode - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(SolutionDir)$(Configuration)\Icons\ - $(SolutionDir)$(Configuration)64\Icons\ - $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ - $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ - $(SolutionDir)$(Configuration)\Icons\ - $(SolutionDir)$(Configuration)64\Icons\ - $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ - $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ - true - - - - NDEBUG;%(PreprocessorDefinitions) - ..\..\..\include\msapi - - - Windows - true - false - true - true - $(SolutionDir)\lib - - - - - NDEBUG;%(PreprocessorDefinitions) - ..\..\..\include\msapi - - - Windows - true - false - true - true - $(SolutionDir)\lib - - - - - _DEBUG;%(PreprocessorDefinitions) - ..\..\..\include\msapi - - - Windows - true - false - $(SolutionDir)\lib - - - - - _DEBUG;%(PreprocessorDefinitions) - ..\..\..\include\msapi - - - Windows - true - false - $(SolutionDir)\lib - - - - - - - - - - - - - - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - - - \ No newline at end of file diff --git a/protocols/YAMN/icons/proto_YAMN_10.vcxproj.filters b/protocols/YAMN/icons/proto_YAMN_10.vcxproj.filters deleted file mode 100644 index ae56e318a4..0000000000 --- a/protocols/YAMN/icons/proto_YAMN_10.vcxproj.filters +++ /dev/null @@ -1,37 +0,0 @@ - - - - - {4726e1d1-39cd-435a-bd59-51fdb6745f46} - ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe - - - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - - - Resource Files - - - \ No newline at end of file diff --git a/protocols/YAMN/icons/resource.h b/protocols/YAMN/icons/resource.h deleted file mode 100644 index af36adfdae..0000000000 --- a/protocols/YAMN/icons/resource.h +++ /dev/null @@ -1,2 +0,0 @@ -#include "../resources/resource.h" - diff --git a/protocols/YAMN/include/IcoLib.h b/protocols/YAMN/include/IcoLib.h deleted file mode 100644 index a911ba571d..0000000000 --- a/protocols/YAMN/include/IcoLib.h +++ /dev/null @@ -1,26 +0,0 @@ -typedef struct { - int cbSize; - char *pszSection; //section name used to group icons - char *pszDescription; //description for options dialog - char *pszName; //name to refer to icon when playing and in db - char *pszDefaultFile; //default icon file to use - int iDefaultIndex; -} SKINICONDESC; - -// -// Add a icon into options UI -// NB! pszName should be unique, e.g.: clistmw_apply, tabsrmm_history -// -// wParam = (WPARAM)0 -// lParam = (LPARAM)(SKINICONDESC*)sid; -// -#define MS_SKIN2_ADDICON "Skin2/Icons/AddIcon" -// -// Retrieve HICON with name specified in lParam -// Returned HICON SHOULDN'T be destroyed, it managed by IcoLib -// -#define MS_SKIN2_GETICON "Skin2/Icons/GetIcon" -// -// Icons change notification -// -#define ME_SKIN2_ICONSCHANGED "Skin2/IconsChanged" diff --git a/protocols/YAMN/mails/decode.cpp b/protocols/YAMN/mails/decode.cpp deleted file mode 100644 index 867ed7ff25..0000000000 --- a/protocols/YAMN/mails/decode.cpp +++ /dev/null @@ -1,558 +0,0 @@ -/* - * This code implements decoding encoded MIME header in style - * =?iso-8859-2?Q? "User using email in central Europe characters such as =E9" ?= - * - * (c) majvan 2002-2004 - */ -#include "../yamn.h" -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -struct _tcptable CodePageNamesAll[]= -{ - { "ANSI", "",TRUE,CP_ACP}, - { "WINDOWS-1", "250",0,1250}, - { "WINDOWS-1", "251",0,1251}, - { "WINDOWS-1", "252",0,1252}, - { "WINDOWS-1", "253",0,1253}, - { "WINDOWS-1", "254",0,1254}, - { "WINDOWS-1", "255",0,1255}, - { "WINDOWS-1", "256",0,1256}, - { "WINDOWS-1", "257",0,1257}, - { "WINDOWS-1", "258",0,1258}, - { "CP1", "250",0,1250}, - { "CP1", "251",0,1251}, - { "CP1", "252",0,1252}, - { "CP1", "253",0,1253}, - { "CP1", "254",0,1254}, - { "CP1", "255",0,1255}, - { "CP1", "256",0,1256}, - { "CP1", "257",0,1257}, - { "CP1", "258",0,1258}, - { "ANSI-1", "250",0,1250}, - { "ANSI-1", "251",0,1251}, - { "ANSI-1", "252",0,1252}, - { "ANSI-1", "253",0,1253}, - { "ANSI-1", "254",0,1254}, - { "ANSI-1", "255",0,1255}, - { "ANSI-1", "256",0,1256}, - { "ANSI-1", "257",0,1257}, - { "ANSI-1", "258",0,1258}, - { "KOI8", "-R",0,20866}, - { "KOI8", "",0,20866}, - { "KOI8", "-U",0,21866}, - { "KOI8", "-RU",0,21866}, - { "US-", "ASCII",0,20127}, - { "CP", "367",0,20127}, - { "ASCII", "",0,20127}, - { "ASCII", "7",0,20127}, - { "ISO-8859", "-1",0,28591}, - { "ISO-8859", "-2",0,28592}, - { "ISO-8859", "-3",0,28593}, - { "ISO-8859", "-4",0,28594}, - { "ISO-8859", "-5",0,28595}, - { "ISO-8859", "-6",0,28596}, - { "ISO-8859", "-7",0,28597}, - { "ISO-8859", "-8",0,28598}, - { "ISO-8859", "-9",0,28599}, - { "ISO-8859", "-15",0,28605}, - { "ISO_8859", "-1",0,28591}, - { "ISO_8859", "-2",0,28592}, - { "ISO_8859", "-3",0,28593}, - { "ISO_8859", "-4",0,28594}, - { "ISO_8859", "-5",0,28595}, - { "ISO_8859", "-6",0,28596}, - { "ISO_8859", "-7",0,28597}, - { "ISO_8859", "-8",0,28598}, - { "ISO_8859", "-9",0,28599}, - { "ISO_8859", "-15",0,28605}, - { "ISO-", "10646-USC2",0,1200}, - { "ISO-2022", "/2-JP",0,50220}, - { "ISO-2022", "-JP",0,50221}, - { "ISO-2022", "/JIS-JP",0,50222}, - { "ISO-2022", "-KR",0,50225}, - { "ISO-2022", "-CH(SP)",0,50227}, - { "ISO-2022", "-CH(TR)",0,50229}, - { "UTF-", "7",0,65000}, - { "UTF-", "8",0,65001}, - { "ARAB-", "TRANSPARENT",0,710}, - { "ASMO-", "TRANSPARENT",0,720}, - { "ASMO-", "449",0,709}, - { "ASMO-", "708",0,708}, - { "BIG5", "",0,950}, - { "EUC-", "CH(SP)",0,51936}, - { "EUC-", "CH(TR)",0,51950}, - { "EUC-", "JP",0,51932}, - { "EUC-", "KR",0,51949}, - { "GB-", "2312",0,20936}, - { "GB", "2312",0,20936}, - { "HZGB-", "2312",0,52936}, - { "IBM-", "037",0,37}, - { "IBM-", "290",0,290}, - { "IBM-", "437",0,437}, - { "IBM-", "500",0,500}, - { "IBM-", "775",0,775}, - { "IBM-", "850",0,850}, - { "IBM-", "852",0,852}, - { "IBM-", "855",0,855}, - { "IBM-", "857",0,857}, - { "IBM-", "860",0,860}, - { "IBM-", "861",0,861}, - { "IBM-", "862",0,862}, - { "IBM-", "863",0,863}, - { "IBM-", "864",0,864}, - { "IBM-", "865",0,865}, - { "IBM-", "866",0,866}, - { "IBM-", "869",0,869}, - { "IBM-", "870",0,870}, - { "IBM-", "875",0,875}, - { "IBM-", "1026",0,1026}, - { "IBM-", "273",0,20273}, - { "IBM-", "277",0,20277}, - { "IBM-", "278",0,20278}, - { "IBM-", "280",0,20280}, - { "IBM-", "284",0,20284}, - { "IBM-", "285",0,20285}, - { "IBM-", "290",0,20290}, - { "IBM-", "297",0,20297}, - { "IBM-", "420",0,20420}, - { "IBM-", "423",0,20423}, - { "IBM-", "871",0,20871}, - { "IBM-", "880",0,20880}, - { "IBM-", "905",0,20905}, - { "IBM-", "THAI",0,20838}, - { "ISCII-", "DEVANAGARI",0,57002}, - { "ISCII-", "BENGALI",0,57003}, - { "ISCII-", "TAMIL",0,57004}, - { "ISCII-", "TELUGU",0,57005}, - { "ISCII-", "ASSAMESE",0,57006}, - { "ISCII-", "ORIYA",0,57007}, - { "ISCII-", "KANNADA",0,57008}, - { "ISCII-", "MALAYALAM",0,57009}, - { "ISCII-", "GUJARATI",0,57010}, - { "ISCII-", "PUNJABI",0,57011}, - { "KOR-", "JOHAB",0,1361}, - { "KSC-", "5601",0,1361}, - { "MAC-", "ROMAN",0,10000}, - { "MAC-", "JP",0,10001}, - { "MAC-", "CH(SP)(BIG5)",0,10002}, - { "MAC-", "KR",0,10003}, - { "MAC-", "AR",0,10004}, - { "MAC-", "HW",0,10005}, - { "MAC-", "GR",0,10006}, - { "MAC-", "CY",0,10007}, - { "MAC-", "CH(SP)(GB2312)",0,10008}, - { "MAC-", "ROMANIA",0,10010}, - { "MAC-", "UA",0,10017}, - { "MAC-", "TH",0,10021}, - { "MAC-", "LAT2",0,10029}, - { "MAC-", "ICE",0,10079}, - { "MAC-", "TR",0,10081}, - { "MAC-", "CR",0,10082} -}; - -int CPLENALL = (sizeof(CodePageNamesAll)/sizeof(CodePageNamesAll[0])); -struct _tcptable *CodePageNamesSupp; -int CPLENSUPP = 1; - -//Gets codepage ID from string representing charset such as "iso-8859-1" -// input- the string -// size- max length of input string -int GetCharsetFromString(char *input,size_t size); - -//HexValue to DecValue ('a' to 10) -// HexValue- hexa value ('a') -// DecValue- poiner where to store dec value -// returns 0 if not success -int FromHexa(char HexValue,char *DecValue); - -//Decodes a char from Base64 -// Base64Value- input char in Base64 -// DecValue- pointer where to store the result -// returns 0 if not success -int FromBase64(char Base64Value,char *DecValue); - -//Decodes string in quoted printable -// Src- input string -// Dst- where to store output string -// DstLen- how max long should be output string -// isQ- if is "Q-encoding" modification. should be TRUE in headers -// always returns 1 -int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ); - -//Decodes string in base64 -// Src- input string -// Dst- where to store output string -// DstLen- how max long should be output string -// returns 0 if string was not properly decoded -int DecodeBase64(char *Src,char *Dst,int DstLen); - -//Converts string to unicode from string with specified codepage -// stream- input string -// cp- codepage of input string -// out- pointer to new allocated memory that contains unicode string -int ConvertStringToUnicode(char *stream,unsigned int cp,WCHAR **out); - -//Converts string from MIME header to unicode -// stream- input string -// cp- codepage of input string -// storeto- pointer to memory that contains unicode string -// mode- MIME_PLAIN or MIME_MAIL (MIME_MAIL deletes '"' from start and end of string) -void ConvertCodedStringToUnicode(char *stream,WCHAR **storeto,DWORD cp,int mode); - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -int GetCharsetFromString(char *input,size_t size) -//"ISO-8859-1" to ID from table -{ - char *pin=input; - char *pout,*parser; - - if ((size<1) || (parser=pout=new char[size+1])==NULL) - return -1; - while((*pin!=0) && (pin-input< (INT_PTR)size)) - { - if ((*pin>='a') && (*pin<='z')) - *parser++=*(pin++)-('a'-'A'); // make it capital - //else if (*pin=='\"') // this is already done in ExtractFromContentType - // *pin++; //skip the quotes if any - else - *parser++=*pin++; - } - - *parser=(char)0; - -#ifdef DEBUG_DECODECODEPAGE - DebugLog(DecodeFile,"%s",pout); -#endif - for (int i=0;i='0' && HexValue<='9') - { - *DecValue=HexValue-'0'; - return 1; - } - if (HexValue>='A' && HexValue<='F') - { - *DecValue=HexValue-'A'+10; - return 1; - } - if (HexValue>='a' && HexValue<='f') - { - *DecValue=HexValue-'a'+10; - return 1; - } - return 0; -} - -int FromBase64(char Base64Value,char *DecValue) -{ - if (Base64Value>='A' && Base64Value<='Z') - { - *DecValue=Base64Value-'A'; - return 1; - } - if (Base64Value>='a' && Base64Value<='z') - { - *DecValue=Base64Value-'a'+26; - return 1; - } - if (Base64Value>='0' && Base64Value<='9') - { - *DecValue=Base64Value-'0'+52; - return 1; - } - if (Base64Value=='+') - { - *DecValue=Base64Value-'+'+62; - return 1; - } - if (Base64Value=='/') - { - *DecValue=Base64Value-'/'+63; - return 1; - } - if (Base64Value=='=') - { - *DecValue=0; - return 1; - } - return 0; -} - -int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ) -{ -#ifdef DEBUG_DECODEQUOTED - char *DstTemp=Dst; - DebugLog(DecodeFile,"%s",Src); -#endif - for (int Counter=0;((char)*Src!=0) && DstLen && (Counter++%s",DstTemp); -#endif - return 1; -} - -int DecodeBase64(char *Src,char *Dst,int DstLen) -{ - int Result=0; - char Locator=0,MiniResult[4]; - char *End=Dst+DstLen; - - MiniResult[0]=MiniResult[1]=MiniResult[2]=MiniResult[3]=0; - -#ifdef DEBUG_DECODEBASE64 - char *DstTemp=Dst; - DebugLog(DecodeFile,"\n%s\n\n",Src); -#endif - while(*Src!=0 && DstLen && Dst!=End) - { - if ((*Src==0x0D)||(*Src==0x0A)) { - Src++; - continue; - } - if ((!(Result=FromBase64(*Src,MiniResult+Locator)) && (*Src==0)) || Locator++==3) //end_of_str || end_of_4_bytes - { - Locator=0; //next write to the first byte - *Dst++=(char)((MiniResult[0]<<2) | (MiniResult[1]>>4)); - if (Dst==End) goto end; //DstLen exceeded? - *Dst++=(char)((MiniResult[1]<<4) | (MiniResult[2]>>2)); - if (Dst==End) goto end; //someones don't like goto, but not me - *Dst++=(char)((MiniResult[2]<<6) | MiniResult[3]); - if (!Result && (*Src==0)) goto end; //end of string? - MiniResult[0]=MiniResult[1]=MiniResult[2]=MiniResult[3]=0; //zero 4byte buffer for next loop - } - if (!Result) return 0; //unrecognised character occured - Src++; - } -end: - *Dst=0; -#ifdef DEBUG_DECODEBASE64 - DebugLog(DecodeFile,"\n%s\n",DstTemp); -#endif - return 1; -} - - - -int ConvertStringToUnicode(char *stream,unsigned int cp,WCHAR **out) -{ - CPINFO CPInfo; - WCHAR *temp,*src=*out,*dest; - size_t outlen; - int streamlen,Index; - - //codepages, which require to have set 0 in dwFlags parameter when calling MultiByteToWideChar - DWORD CodePagesZeroFlags[]={50220,50221,50222,50225,50227,50229,52936,54936,57002,57003,57004,57005,57006,57007,57008,57009,57010,57011,65000,65001}; - - if ((cp!=CP_ACP) && (cp!=CP_OEMCP) && (cp!=CP_MACCP) && (cp!=CP_THREAD_ACP) && (cp!=CP_SYMBOL) && (cp!=CP_UTF7) && (cp!=CP_UTF8) && !GetCPInfo(cp,&CPInfo)) - cp=CP_ACP; -#ifdef DEBUG_DECODECODEPAGE - DebugLog(DecodeFile,"%d",cp); -#endif - - for (Index=0;Index tempstoreLength) break; - start++; - } - } - tempstore[outind] = 0; - *storeto = tempstore; -} diff --git a/protocols/YAMN/mails/m_decode.h b/protocols/YAMN/mails/m_decode.h deleted file mode 100644 index e6d2b52fae..0000000000 --- a/protocols/YAMN/mails/m_decode.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __DECODE_H -#define __DECODE_H - -#include "../debug.h" - -#define DOTLINE(s) ((((s)[-2]=='\r') || ((s)[-2]=='\n')) && ((s)[-1]=='.') && (((s)[0]=='\r') || ((s)[0]=='\n') || ((s)[0]=='\0'))) // be careful, it's different to ESR's pop3.c ;-) -#define ENDLINE(s) (((s)[0]=='\r') || ((s)[0]=='\n')) //endline -#define WS(s) (((s)[0]==' ') || ((s)[0]=='\t')) //whitespace -#define ENDLINEWS(s) ((((s)[0]=='\r') || ((s)[0]=='\n')) && (((((s)[1]=='\r') || ((s)[1]=='\n')) && (((s)[2]==' ') || ((s)[2]=='\t'))) || (((s)[1]==' ') || ((s)[1]=='\t')))) //endline+whitespace: enters(CR or LF and their combinations) followed by space or tab -#define EOS(s) ((s)[0]==0) //end of string (stream) - -#define CODES(s) ((s[0]=='=') && (s[1]=='?')) //start of coded string -#define CODEE(s) ((s[0]=='?') && (s[1]=='=')) //end of coded string -#define CODED(s) (s[0]=='?') //code delimiter - -#define MIME_PLAIN 1 -#define MIME_MAIL 2 - -struct cptable -{ - char *name; - unsigned int ID; -}; - -#endif diff --git a/protocols/YAMN/mails/mails.cpp b/protocols/YAMN/mails/mails.cpp deleted file mode 100644 index af0f3d2329..0000000000 --- a/protocols/YAMN/mails/mails.cpp +++ /dev/null @@ -1,499 +0,0 @@ -/* - * This code implements retrieving info from MIME header - * - * (c) majvan 2002-2004 - */ - -#pragma warning( disable : 4290 ) -#include "../yamn.h" - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -// SMALL INTRO -// Mails are queued in a queue (chained list). Pointer to first mail is pointed from Account structure -// member called Mails. -// Mail queue is ended with NULL- pointered mail (NULL handle) - -//Creates new mail for plugin (calling plugin's constructor, when plugin imported to YAMN) -INT_PTR CreateAccountMailSvc(WPARAM wParam,LPARAM lParam); - -//Deletes mail for plugin (calling plugin's destructor, when plugin imported to YAMN) -INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam); - -//Loads mail data from standard storage to memory -INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam); - -//Deletes mail data from memory -INT_PTR UnloadMailDataSvc(WPARAM wParam,LPARAM); - -//Saves mail data from memory to standard storage -INT_PTR SaveMailDataSvc(WPARAM wParam,LPARAM lParam); - -//Appends second MIME mail queue to the first one -//Only finds the end of first queue and its Next memember repoints to second one -void WINAPI AppendQueueFcn(HYAMNMAIL first,HYAMNMAIL second); - -//Synchronizes two accounts -//Function finds, if there were some mails deleted from mailbox and deletes (depends on RemovedOld param) them from OldQueue -//Next finds, if there are new mails. Mails that are still on mailbox are deleted (depends on RemovedNew param) from NewQueue -//After this, OldQueue is pointer to mails that are on mailbox, but not new mails -//and NewQueue contains new mails in account -//New accounts can be then appended to account mails queue, but they have set the New flag -// -//Two mails equals if they have the same ID -// -// hPlugin- handle of plugin going to delete mails -// OldQueue- queue of mails that we found on mailbox last time, after function finishes queue contains all mails except new ones -// RemovedOld- queue of mails where to store removed mails from OldQueue, if NULL deletes mails from OldQueue -// NewQueue- queue of mails that we found on mailbox (all mails), after function finishes queue contains only new mails -// RemovedNew- queue of mails where to store removed mails from NewQueue, if NULL deletes mails from NewQueue -//So function works like: -//1. delete (or move to RemovedOld queue if RemovedOld is not NULL) all mails from OldQueue not found in NewQueue -//2. delete (or move to RemovedNew queue if RemovedNew is not NULL) all mails from NewQueue found in OldQueue -void WINAPI SynchroMessagesFcn(HACCOUNT Account,HYAMNMAIL *OldQueue,HYAMNMAIL *RemovedOld,HYAMNMAIL *NewQueue,HYAMNMAIL *RemovedNew); - -//Deletes messages from mail From to the end -// Account- account who owns mails -// From- first mail in queue, which is going to delete -void WINAPI DeleteMessagesToEndFcn(HACCOUNT Account,HYAMNMAIL From); - -//Removes message from queue, does not delete from memory -// From- queue pointer -// Which- mail to delete -// mode- nonzero if you want to decrement numbers in messages that are bigger than the one in Which mail, 0 if not -void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From,HYAMNMAIL Which,int mode); - -//Finds message in queue that has the same ID number -// From- message queue -// ID- pointer to ID -// returns pointer to found message, NULL if not found -HYAMNMAIL WINAPI FindMessageByIDFcn(HYAMNMAIL From,char *ID); - -//Translate header from text to queue of CMimeItem structures -//This means that new queue will contain all info about headers -// stream- pointer to text containing header (can be ended with zero) -// len- length of stream -// head- function fills this pointer to first header item in queue -void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head); - -//Creates new mail queue, copying only these mails, that have set flag for deleting -// From- message queue, whose mail with given flag are duplicated -// returns new mail queue (or NULL when no mail with flag is in From queue) -//Function does not copy the whole mails, it copies only ID string. And ID is copied as string, so -//you can use this fcn only if you have your ID as pointer to char string ended with zero character -HYAMNMAIL WINAPI CreateNewDeleteQueueFcn(HYAMNMAIL From); - -//Sets/removes flags from specific mails -// From- pointer to first message -// FlagsSet- mail must have set these flags... -// FlagsNotSet- ...and must not have set these flags... -// FlagsToSetRemove- ...to set/remove these flags (see mode) -// mode- nonzero to set, else remove -void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From,DWORD FlagsSet,DWORD FlagsNotSet,DWORD FlagsToSetRemove,int mode); - -struct CExportedFunctions MailExportedFcn[]= -{ - {YAMN_SYNCHROMIMEMSGSID,(void *)SynchroMessagesFcn}, - {YAMN_TRANSLATEHEADERID,(void *)TranslateHeaderFcn}, - {YAMN_APPENDQUEUEID,(void *)AppendQueueFcn}, - {YAMN_DELETEMIMEQUEUEID,(void *)DeleteMessagesToEndFcn}, - {YAMN_DELETEMIMEMESSAGEID,(void *)DeleteMessageFromQueueFcn}, - {YAMN_FINDMIMEMESSAGEID,(void *)FindMessageByIDFcn}, - {YAMN_CREATENEWDELETEQUEUEID,(void *)CreateNewDeleteQueueFcn}, - {YAMN_SETREMOVEQUEUEFLAGSID,(void *)SetRemoveFlagsInQueueFcn}, -}; - -struct CExportedServices MailExportedSvc[]= -{ - {MS_YAMN_CREATEACCOUNTMAIL,CreateAccountMailSvc}, - {MS_YAMN_DELETEACCOUNTMAIL,DeleteAccountMailSvc}, - {MS_YAMN_LOADMAILDATA,LoadMailDataSvc}, - {MS_YAMN_UNLOADMAILDATA,UnloadMailDataSvc}, - {MS_YAMN_SAVEMAILDATA,SaveMailDataSvc}, -}; - - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -INT_PTR CreateAccountMailSvc(WPARAM wParam,LPARAM lParam) -{ - HACCOUNT Account=(HACCOUNT)wParam; - DWORD MailVersion=(DWORD)lParam; - HYAMNMAIL NewMail; - -//test if we are going to initialize members of suitable structure (structures of plugin and YAMN must match) - if (MailVersion!=YAMN_MAILVERSION) - return NULL; - - if (Account->Plugin!=NULL) - { - if (Account->Plugin->MailFcn->NewMailFcnPtr!=NULL) - { -//Let plugin create its own structure, which can be derived from CAccount structure - if (NULL==(NewMail=Account->Plugin->MailFcn->NewMailFcnPtr(Account,YAMN_MAILVERSION))) - return NULL; - } - else - { -//We suggest plugin uses standard CAccount structure, so we create it - if (NULL==(NewMail=new YAMNMAIL)) -//If not created successfully - return NULL; - NewMail->MailData=NULL; - } -//Init every members of structure, used by YAMN - return (INT_PTR)NewMail; - } - return NULL; -} - -INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam) -{ - HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; - HYAMNMAIL OldMail=(HYAMNMAIL)lParam; - struct CMimeItem *TH; - - if (Plugin->MailFcn!=NULL){ - if (Plugin->MailFcn->DeleteMailFcnPtr!=NULL) { - //Let plugin delete its own CMimeMsgQueue derived structure - Plugin->MailFcn->DeleteMailFcnPtr(OldMail); - return 1; - } - } - if (OldMail->MailData!=NULL) { - if (OldMail->MailData->Body!=NULL) - delete[] OldMail->MailData->Body; - if ((TH=OldMail->MailData->TranslatedHeader)!=NULL) - for (;OldMail->MailData->TranslatedHeader!=NULL;) { - TH=TH->Next; - if (OldMail->MailData->TranslatedHeader->name!=NULL) - delete[] OldMail->MailData->TranslatedHeader->name; - if (OldMail->MailData->TranslatedHeader->value!=NULL) - delete[] OldMail->MailData->TranslatedHeader->value; - delete OldMail->MailData->TranslatedHeader; - OldMail->MailData->TranslatedHeader=TH; - } - delete OldMail->MailData; - } - if (OldMail->ID!=NULL) - delete[] OldMail->ID; - - delete OldMail; //consider mail as standard HYAMNMAIL, not initialized before and use its own destructor - return 1; -} - - -void WINAPI AppendQueueFcn(HYAMNMAIL first,HYAMNMAIL second) -{ - HYAMNMAIL Finder=first; - while(Finder->Next!=NULL) Finder=Finder->Next; - Finder->Next=second; -} - -INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam) -{ - HYAMNMAIL Mail=(HYAMNMAIL)wParam; - DWORD MailVersion=(DWORD)lParam; - - if (MailVersion!=YAMN_MAILDATAVERSION) - return NULL; - -//now we have all data to memory persisting, so no loading is needed - return (INT_PTR)Mail->MailData; -} - -INT_PTR UnloadMailDataSvc(WPARAM wParam,LPARAM) -{ - HYAMNMAIL Mail=(HYAMNMAIL)wParam; - -//now we should delete structure from memory, but it will be made in future YAMN version - return 1; -} - -INT_PTR SaveMailDataSvc(WPARAM wParam,LPARAM lParam) -{ - HYAMNMAIL Mail=(HYAMNMAIL)wParam; - DWORD MailVersion=(DWORD)lParam; - - if (MailVersion!=YAMN_MAILDATAVERSION) - return (INT_PTR)-1; - -//now we have all data to memory persisting, so no saving is needed - return (INT_PTR)0; -} - -void WINAPI SynchroMessagesFcn(HACCOUNT Account,HYAMNMAIL *OldQueue,HYAMNMAIL *RemovedOld,HYAMNMAIL *NewQueue,HYAMNMAIL *RemovedNew) -//deletes messages from new queue, if they are old -//it also deletes messages from old queue, if they are not in mailbox anymore -//"YAMN_MSG_DELETED" messages in old queue remain in old queue (are never removed, although they are not in new queue) -//"YAMN_MSG_DELETED" messages in new queue remain in new queue (are never removed, although they can be in old queue) -{ - HYAMNMAIL Finder,FinderPrev; - HYAMNMAIL Parser,ParserPrev; - HYAMNMAIL RemovedOldParser =NULL; - HYAMNMAIL RemovedNewParser =NULL; - if (RemovedOld!=NULL) *RemovedOld=NULL; - if (RemovedNew!=NULL) *RemovedNew=NULL; - - for (FinderPrev=NULL,Finder=*OldQueue;Finder!=NULL;) - { - if (Finder->Flags & YAMN_MSG_DELETED) //if old queue contains deleted mail - { - FinderPrev=Finder; - Finder=Finder->Next; //get next message in old queue for testing - continue; - } - for (ParserPrev=NULL,Parser=*NewQueue;Parser!=NULL;ParserPrev=Parser,Parser=Parser->Next) - { - if (Parser->Flags & YAMN_MSG_DELETED) - continue; - - if (Parser->ID==NULL) //simply ignore the message, that has not filled its ID - continue; - - if (0==strcmp(Parser->ID,Finder->ID)) //search for equal message in new queue - break; - } - if (Parser!=NULL) //found equal message in new queue - { - if (Parser==*NewQueue) - *NewQueue=(*NewQueue)->Next; - else - ParserPrev->Next=Parser->Next; - Finder->Number=Parser->Number; //rewrite the number of current message in old queue - - if (RemovedNew==NULL) //delete from new queue - DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Parser); - else //or move to RemovedNew - { - if (RemovedNewParser==NULL) //if it is first mail removed from NewQueue - *RemovedNew=Parser; //set RemovedNew queue to point to first message in removed queue - else - RemovedNewParser->Next=Parser; //else don't forget to show to next message in RemovedNew queue - RemovedNewParser=Parser; //follow RemovedNew queue - RemovedNewParser->Next=NULL; - } - FinderPrev=Finder; - Finder=Finder->Next; //get next message in old queue for testing - } - else //a message was already deleted from mailbox - { - if (Finder==*OldQueue) //if we are at the first item in OldQueue - { - *OldQueue=(*OldQueue)->Next; //set OldQueue to next item - if (RemovedOld==NULL) //delete from old queue - DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Finder); - else //or move to RemovedOld - { - if (RemovedOldParser==NULL) //if it is first mail removed from OldQueue - *RemovedOld=Finder; //set RemovedOld queue to point to first message in removed queue - else - RemovedOldParser->Next=Finder; //else don't forget to show to next message in RemovedNew queue - RemovedOldParser=Finder; //follow RemovedOld queue - RemovedOldParser->Next=NULL; - } - Finder=*OldQueue; - } - else - { - FinderPrev->Next=Finder->Next; - if (RemovedOld==NULL) //delete from old queue - DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Finder); - else //or move to RemovedOld - { - if (RemovedOldParser==NULL) //if it is first mail removed from OldQueue - *RemovedOld=Finder; //set RemovedOld queue to point to first message in removed queue - else - RemovedOldParser->Next=Finder; //else don't forget to show to next message in RemovedNew queue - RemovedOldParser=Finder; //follow RemovedOld queue - RemovedOldParser->Next=NULL; - } - Finder=FinderPrev->Next; - } - } - } -} - -void WINAPI DeleteMessagesToEndFcn(HACCOUNT Account,HYAMNMAIL From) -{ - HYAMNMAIL Temp; - while(From!=NULL) - { - Temp=From; - From=From->Next; - DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Temp); - } -} - -void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From,HYAMNMAIL Which,int mode=0) -{ - DWORD Number=Which->Number; - HYAMNMAIL Parser; - - if (*From==Which) - { - Parser=Which->Next; - *From=Parser; - } - else - { - for (Parser=*From;Which!=Parser->Next;Parser=Parser->Next) - if (mode && (Parser->Number>Number)) Parser->Number--; - if (mode && (Parser->Number>Number)) Parser->Number--; - Parser->Next=Parser->Next->Next; - Parser=Which->Next; - } - if (mode) - for (;Parser!=NULL;Parser=Parser->Next) - if (Parser->Number>Number) Parser->Number--; -} - -void DeleteMessagesFromQueue(HYAMNMAIL *From,HYAMNMAIL Which,int mode=0) -{ - HYAMNMAIL Parser; - - for (Parser=Which;Parser!=NULL;Parser=Parser->Next) - DeleteMessageFromQueueFcn(From,Parser,mode); -} - -HYAMNMAIL WINAPI FindMessageByIDFcn(HYAMNMAIL From,char *ID) -{ - HYAMNMAIL Browser; - - for (Browser=From;Browser!=NULL;Browser=Browser->Next) - if (0==lstrcmpA(Browser->ID,ID)) - break; - return Browser; -} - -void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head) -{ - try - { - char *finder=stream; - char *prev1,*prev2,*prev3; - struct CMimeItem *Item=NULL; - - while(finder<=(stream+len)) - { - while(ENDLINEWS(finder)) finder++; - - //at the start of line - if (DOTLINE(finder+1)) //at the end of stream - break; - - prev1=finder; - - while(*finder!=':' && !EOS(finder)) finder++; - if (!EOS(finder)) - prev2=finder++; - else - break; - - while(WS(finder) && !EOS(finder)) finder++; - if (!EOS(finder)) - prev3=finder; - else - break; - - do - { - if (ENDLINEWS(finder)) finder+=2; //after endline information continues - while(!ENDLINE(finder) && !EOS(finder)) finder++; - }while(ENDLINEWS(finder)); - - if (Item!=NULL) - { - if (NULL==(Item->Next=new struct CMimeItem)) - break; - Item=Item->Next; - } - else - { - Item = new CMimeItem; - *head = Item; - } - - Item->Next=NULL; - Item->name=new char [prev2-prev1+1]; - lstrcpynA(Item->name,prev1,prev2-prev1+1); - Item->value=new char [finder-prev3+1]; - lstrcpynA(Item->value,prev3,finder-prev3+1); - - if (EOS(finder)) - break; - finder++; - if (ENDLINE(finder)) { - finder++; - if (ENDLINE(finder)) { - // end of headers. message body begins - finder++; - if (ENDLINE(finder))finder++; - prev1 = finder; - while (!DOTLINE(finder+1))finder++; - if (ENDLINE(finder))finder--; - prev2 = finder; - if (prev2>prev1){ // yes, we have body - if (NULL==(Item->Next=new struct CMimeItem)) break; // Cant create new item?! - Item=Item->Next; - Item->Next=NULL;//just in case; - Item->name=new char[5]; strncpy(Item->name,"Body",5); - Item->value=new char [prev2-prev1]; - lstrcpynA(Item->value,prev1,prev2-prev1-1); - } - break; // there is nothing else - } - } - } - } - catch(...) - { - MessageBoxA(NULL,"Translate header error","",0); - } -} - -HYAMNMAIL WINAPI CreateNewDeleteQueueFcn(HYAMNMAIL From) -{ - HYAMNMAIL FirstMail,Browser; - - for (FirstMail=NULL;From!=NULL;From=From->Next) - { - if ((From->Flags & (YAMN_MSG_USERDELETE | YAMN_MSG_AUTODELETE)) && !(From->Flags & YAMN_MSG_DELETED)) - { - if (FirstMail==NULL) - { - FirstMail=Browser=new YAMNMAIL; - if (FirstMail==NULL) - break; - } - else - { - Browser->Next=new YAMNMAIL; - Browser=Browser->Next; - } - Browser->ID=new char[strlen(From->ID)+1]; - strcpy(Browser->ID,From->ID); - Browser->Number=From->Number; - Browser->Flags=From->Flags; - } - } - return FirstMail; -} - -void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From,DWORD FlagsSet,DWORD FlagsNotSet,DWORD FlagsToSetRemove,int mode) -{ - HYAMNMAIL msgq; - - for (msgq=(HYAMNMAIL)From;msgq!=NULL;msgq=msgq->Next) - { - if ((FlagsSet==(msgq->Flags & FlagsSet)) && (0==(msgq->Flags & FlagsNotSet))) - { - if (mode) - msgq->Flags=msgq->Flags | FlagsToSetRemove; - else - msgq->Flags=msgq->Flags & ~FlagsToSetRemove; - } - } -} diff --git a/protocols/YAMN/mails/mime.cpp b/protocols/YAMN/mails/mime.cpp deleted file mode 100644 index 2a66b80e2b..0000000000 --- a/protocols/YAMN/mails/mime.cpp +++ /dev/null @@ -1,732 +0,0 @@ -/* - * This code implements retrieving info from MIME header - * - * (c) majvan 2002-2004 - */ - -#pragma warning( disable : 4290 ) -#include "../yamn.h" - -//- imported --------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -extern SWMRG *AccountBrowserSO; -extern struct WndHandles *MessageWnd; - -extern int GetCharsetFromString(char *input,size_t size); -extern void SendMsgToRecepients(struct WndHandles *FirstWin,UINT msg,WPARAM wParam,LPARAM lParam); -extern void ConvertCodedStringToUnicode(char *stream,WCHAR **storeto,DWORD cp,int mode); -extern DWORD WINAPI MailBrowser(LPVOID Param); -extern DWORD WINAPI NoNewMailProc(LPVOID Param); -extern DWORD WINAPI BadConnection(LPVOID Param); - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -//Copies one string to another -// srcstart- source string -// srcend- address to the end of source string -// dest- pointer that stores new allocated string that contains copy of source string -// mode- MIME_PLAIN or MIME_MAIL (MIME_MAIL deletes '"' characters (or '<' and '>') if they are at start and end of source string -void CopyToHeader(char *srcstart,char *srcend,char **dest,int mode); - -//Extracts email address (finds nick name and mail and then stores them to strings) -// finder- source string -// storeto- pointer that receives address of mail string -// storetonick- pointer that receives address of nickname -void ExtractAddressFromLine(char *finder,char **storeto,char **storetonick); - -//Extracts simple text from string -// finder- source string -// storeto- pointer that receives address of string -void ExtractStringFromLine(char *finder,char **storeto); - -//Extracts some item from content-type string -//Example: ContentType string: "TEXT/PLAIN; charset=US-ASCII", item:"charset=", returns: "US-ASCII" -// ContetType- content-type string -// value- string item -// returns extracted string (or NULL when not found) -char *ExtractFromContentType(char *ContentType,char *value); - -//Extracts info from header text into header members -//Note that this function as well as struct CShortHeadwer can be always changed, because there are many items to extract -//(e.g. the X-Priority and Importance and so on) -// items- translated header (see TranslateHeaderFcn) -// head- header to be filled with values extracted from items -void ExtractShortHeader(struct CMimeItem *items,struct CShortHeader *head); - -//Extracts header to mail using ExtractShortHeader fcn. -// items- translated header (see TranslateHeaderFcn) -// CP- codepage used when no default found -// head- header to be filled with values extracted from items, in unicode (wide char) -void ExtractHeader(struct CMimeItem *items,int &CP,struct CHeader *head); - -//Deletes items in CShortHeader structure -// head- structure whose items are deleted -void DeleteShortHeaderContent(struct CShortHeader *head); - -//Deletes list of YAMN_MIMENAMES structures -// Names- pointer to first item of list -void DeleteNames(PYAMN_MIMENAMES Names); - -//Deletes list of YAMN_MIMESHORTNAMES structures -// Names- pointer to first item of list -void DeleteShortNames(PYAMN_MIMESHORTNAMES Names); - -//Makes a string lowercase -// string- string to be lowercased -void inline ToLower(char *string); - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -void CopyToHeader(char *srcstart,char *srcend,char **dest,int mode) -{ - char *dst; - - if (dest==NULL) - return; - if (srcstart>=srcend) - return; - - if ((mode==MIME_MAIL) && (((*srcstart=='"') && (*(srcend-1)=='"')) || ((*srcstart=='<') && (*(srcend-1)=='>')))) - { - srcstart++; - srcend--; - } - - if (srcstart>=srcend) - return; - - if (NULL!=*dest) - delete[] *dest; - if (NULL==(*dest=new char[srcend-srcstart+1])) - return; - - dst=*dest; - - for (;srcstart' at the end of line - CopyToHeader(finder,finderend+1,storeto,MIME_MAIL); - else //at the end of line, there's '>' - { - char *finder2=finderend; - while((*finder2!='<') && (finder2>finder)) finder2--; //go to matching '<' or to the start - CopyToHeader(finder2,finderend+1,storeto,MIME_MAIL); - if (*finder2=='<') //if we found '<', the rest copy as from nick - { - finder2--; - while(WS(finder2) || ENDLINE(finder2)) finder2--; //parse whitespace - CopyToHeader(finder,finder2+1,storetonick,MIME_MAIL); //and store nickname - } - } - } - else - { - char *finderend=finder+1; - do - { - if (ENDLINEWS(finderend)) //after endline information continues - finderend+=2; - while(!ENDLINE(finderend) && (*finderend!='>') && !EOS(finderend)) finderend++; //seek to the matching < or to the end of line or to the end of string - }while(ENDLINEWS(finderend)); - CopyToHeader(finder,finderend+1,storeto,MIME_MAIL); //go to first '>' or to the end and copy - finder=finderend+1; - while(WS(finder)) finder++; //parse whitespace - if (!ENDLINE(finder) && !EOS(finder)) //if there are chars yet, it's nick - { - finderend=finder+1; - while(!ENDLINE(finderend) && !EOS(finderend)) finderend++; //seek to the end of line or to the end of string - finderend--; - while(WS(finderend)) finderend--; //find the end of line, no whitespace - CopyToHeader(finder,finderend+1,storetonick,MIME_MAIL); - } - } -} - -void ExtractStringFromLine(char *finder,char **storeto) -{ - if (finder==NULL) - { - *storeto=NULL; - return; - } - while(WS(finder)) finder++; - char *finderend=finder; - - do - { - if (ENDLINEWS(finderend)) finderend++; //after endline information continues - while(!ENDLINE(finderend) && !EOS(finderend)) finderend++; - }while(ENDLINEWS(finderend)); - finderend--; - while(WS(finderend)) finderend--; //find the end of line, no whitespace - CopyToHeader(finder,finderend+1,storeto,MIME_PLAIN); -} - -char *ExtractFromContentType(char *ContentType,char *value) -{ - char *lowered = _strdup(ContentType); - ToLower(lowered); - char *finder=strstr(lowered,value); - if (finder==NULL){ - free (lowered); - return NULL; - } - finder = finder-lowered+ContentType; - free (lowered); - - char *temp,*copier; - char *CopiedString; - - temp=finder-1; - while((temp>ContentType) && WS(temp)) temp--; //now we have to find, if the word "Charset=" is located after ';' like "; Charset=" - if (*temp!=';' && !ENDLINE(temp) && temp!=ContentType) - return NULL; - finder=finder+strlen(value); //jump over value string - - while(WS(finder)) finder++; //jump over whitespaces - temp=finder; - while(*temp!=0 && *temp!=';') temp++; //jump to the end of setting (to the next ;) - temp--; - while(WS(temp)) temp--; //remove whitespaces from the end - if (*finder=='\"') { //remove heading and tailing quotes - finder++; - if (*temp=='\"') temp--; - } - if (NULL==(CopiedString=new char[++temp-finder+1])) - return NULL; - for (copier=CopiedString;finder!=temp;*copier++=*finder++); //copy string - *copier=0; //and end it with zero character - - return CopiedString; -} - -void ExtractShortHeader(struct CMimeItem *items,struct CShortHeader *head) -{ - for (;items!=NULL;items=items->Next) - { - //at the start of line - //MessageBox(NULL,items->value,items->name,0); - if (0==_strnicmp(items->name,"From",4)) - { - if (items->value==NULL) - continue; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,""); - #endif - ExtractAddressFromLine(items->value,&head->From,&head->FromNick); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - } - else if (0==_strnicmp(items->name,"Return-Path",11)) - { - if (items->value==NULL) - continue; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,""); - #endif - ExtractAddressFromLine(items->value,&head->ReturnPath,&head->ReturnPathNick); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - } - else if (0==_strnicmp(items->name,"Subject",7)) - { - if (items->value==NULL) - continue; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,""); - #endif - ExtractStringFromLine(items->value,&head->Subject); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - } - else if (0==_strnicmp(items->name,"Body",4)) - { - if (items->value==NULL) - continue; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,""); - #endif - ExtractStringFromLine(items->value,&head->Body); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - } - else if (0==_strnicmp(items->name,"Date",4)) - { - if (items->value==NULL) - continue; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,""); - #endif - ExtractStringFromLine(items->value,&head->Date); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - } - else if (0==_strnicmp(items->name,"Content-Type",12)) - { - if (items->value==NULL) - continue; - - char *ContentType=NULL,*CharSetStr; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,""); - #endif - ExtractStringFromLine(items->value,&ContentType); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - ToLower(ContentType); - if (NULL!=(CharSetStr=ExtractFromContentType(ContentType,"charset="))) - { - head->CP=GetCharsetFromString(CharSetStr,strlen(CharSetStr)); - delete[] CharSetStr; - } - delete[] ContentType; - } - else if (0==_strnicmp(items->name,"Importance",10)) - { - if (items->value==NULL) - continue; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,""); - #endif - if (head->Priority!=-1) - { - if (0==strncmp(items->value,"low",3)) - head->Priority=5; - else if (0==strncmp(items->value,"normal",6)) - head->Priority=3; - else if (0==strncmp(items->value,"high",4)) - head->Priority=1; - } - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - } - else if (0==_strnicmp(items->name,"X-Priority",10)) - { - if (items->value==NULL) - continue; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,""); - #endif - if ((*items->value>='1') && (*items->value<='5')) - head->Priority=*items->value-'0'; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - } - - } -} - -void ExtractHeader(struct CMimeItem *items,int &CP,struct CHeader *head) -{ - struct CShortHeader ShortHeader; - - ZeroMemory(&ShortHeader,sizeof(struct CShortHeader)); - ShortHeader.Priority=ShortHeader.CP=-1; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - ExtractShortHeader(items,&ShortHeader); - - head->Priority=ShortHeader.Priority==-1 ? 3 : ShortHeader.Priority; - CP=ShortHeader.CP==-1 ? CP : ShortHeader.CP; - #ifdef DEBUG_DECODE - if (NULL!=ShortHeader.From) - DebugLog(DecodeFile,"%s%s%s%s%s%s\n"); - DebugLog(DecodeFile,"\n"); - #endif - - ConvertCodedStringToUnicode(ShortHeader.From,&head->From,CP,MIME_PLAIN); - - #ifdef DEBUG_DECODE - if (NULL!=head->From) - DebugLogW(DecodeFile,L"%s\n",head->From); - #endif - ConvertCodedStringToUnicode(ShortHeader.FromNick,&head->FromNick,CP,MIME_MAIL); - #ifdef DEBUG_DECODE - if (NULL!=head->FromNick) - DebugLogW(DecodeFile,L"%s\n",head->FromNick); - #endif - ConvertCodedStringToUnicode(ShortHeader.ReturnPath,&head->ReturnPath,CP,MIME_PLAIN); - #ifdef DEBUG_DECODE - if (NULL!=head->ReturnPath) - DebugLogW(DecodeFile,L"%s\n",head->ReturnPath); - #endif - ConvertCodedStringToUnicode(ShortHeader.ReturnPathNick,&head->ReturnPathNick,CP,MIME_MAIL); - #ifdef DEBUG_DECODE - if (NULL!=head->ReturnPathNick) - DebugLogW(DecodeFile,L"%s\n",head->ReturnPathNick); - #endif - ConvertCodedStringToUnicode(ShortHeader.Subject,&head->Subject,CP,MIME_PLAIN); - #ifdef DEBUG_DECODE - if (NULL!=head->Subject) - DebugLogW(DecodeFile,L"%s\n",head->Subject); - #endif - ConvertCodedStringToUnicode(ShortHeader.Date,&head->Date,CP,MIME_PLAIN); - #ifdef DEBUG_DECODE - if (NULL!=head->Date) - DebugLogW(DecodeFile,L"%s\n",head->Date); - #endif - - ConvertCodedStringToUnicode(ShortHeader.Body,&head->Body,CP,MIME_PLAIN); - #ifdef DEBUG_DECODE - if (NULL!=head->Body) - DebugLogW(DecodeFile,L"%s\n",head->Body); - #endif - - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - - DeleteShortHeaderContent(&ShortHeader); - -// head->From=L"Frommmm"; -// head->Subject=L"Subject"; - return; -} - -void DeleteShortHeaderContent(struct CShortHeader *head) -{ - if (head->From!=NULL) delete[] head->From; - if (head->FromNick!=NULL) delete[] head->FromNick; - if (head->ReturnPath!=NULL) delete[] head->ReturnPath; - if (head->ReturnPathNick!=NULL) delete[] head->ReturnPathNick; - if (head->Subject!=NULL) delete[] head->Subject; - if (head->Date!=NULL) delete[] head->Date; - if (head->To!=NULL) DeleteShortNames(head->To); - if (head->Cc!=NULL) DeleteShortNames(head->Cc); - if (head->Bcc!=NULL) DeleteShortNames(head->Bcc); - if (head->Body!=NULL) delete[] head->Body; -} - -void DeleteHeaderContent(struct CHeader *head) -{ - if (head->From!=NULL) delete[] head->From; - if (head->FromNick!=NULL) delete[] head->FromNick; - if (head->ReturnPath!=NULL) delete[] head->ReturnPath; - if (head->ReturnPathNick!=NULL) delete[] head->ReturnPathNick; - if (head->Subject!=NULL) delete[] head->Subject; - if (head->Date!=NULL) delete[] head->Date; - if (head->Body!=NULL) delete[] head->Body; - if (head->To!=NULL) DeleteNames(head->To); - if (head->Cc!=NULL) DeleteNames(head->Cc); - if (head->Bcc!=NULL) DeleteNames(head->Bcc); -} - -void DeleteNames(PYAMN_MIMENAMES Names) -{ - PYAMN_MIMENAMES Parser=Names,Old; - for (;Parser!=NULL;Parser=Parser->Next) - { - if (Parser->Value!=NULL) - delete[] Parser->Value; - if (Parser->ValueNick!=NULL) - delete[] Parser->ValueNick; - Old=Parser; - Parser=Parser->Next; - delete Old; - } -} - -void DeleteShortNames(PYAMN_MIMESHORTNAMES Names) -{ - PYAMN_MIMESHORTNAMES Parser=Names,Old; - for (;Parser!=NULL;Parser=Parser->Next) - { - if (Parser->Value!=NULL) - delete[] Parser->Value; - if (Parser->ValueNick!=NULL) - delete[] Parser->ValueNick; - Old=Parser; - Parser=Parser->Next; - delete Old; - } -} - - -void inline ToLower(char *string) -{ - for (;*string!=0;string++) - if (*string>='A' && *string<='Z') *string=*string-'A'+'a'; -} - -#define TE_UNKNOWN -#define TE_QUOTEDPRINTABLE 1 -#define TE_BASE64 2 -struct APartDataType -{ - char *Src;//Input - char *ContType; - int CodePage; - char *TransEnc; - BYTE TransEncType; //TE_something - char *body; - int bodyLen; - WCHAR *wBody; -}; - - -void ParseAPart(APartDataType *data) -{ - size_t len = strlen(data->Src); - try - { - char *finder=data->Src; - char *prev1,*prev2,*prev3; - - while(finder<=(data->Src+len)) - { - while(ENDLINEWS(finder)) finder++; - - //at the start of line - if (finder>data->Src){ - if (*(finder-2)=='\r' || *(finder-2)=='\n') - *(finder-2)=0; - if (*(finder-1)=='\r' || *(finder-1)=='\n') - *(finder-1)=0; - } - prev1=finder; - - while(*finder!=':' && !EOS(finder) && !ENDLINE(finder)) finder++; - if (ENDLINE(finder)||EOS(finder)) { - // no ":" in the line? here the body begins; - data->body = prev1; - break; - } - prev2=finder++; - - while(WS(finder) && !EOS(finder)) finder++; - if (!EOS(finder)) - prev3=finder; - else - break; - - do - { - if (ENDLINEWS(finder)) finder+=2; //after endline information continues - while(!ENDLINE(finder) && !EOS(finder)) finder++; - }while(ENDLINEWS(finder)); - - if (!_strnicmp(prev1,"Content-type",prev2-prev1)) { - data->ContType = prev3; - } else if (!_strnicmp(prev1,"Content-Transfer-Encoding",prev2-prev1)) { - data->TransEnc = prev3; - } - - if (EOS(finder)) - break; - finder++; - if (ENDLINE(finder)) { - finder++; - if (ENDLINE(finder)) { - // end of headers. message body begins - if (finder>data->Src){ - if (*(finder-2)=='\r' || *(finder-2)=='\n') - *(finder-2)=0; - if (*(finder-1)=='\r' || *(finder-1)=='\n') - *(finder-1)=0; - } - finder++; - if (ENDLINE(finder))finder++; - prev1 = finder; - while (!EOS(finder+1))finder++; - if (ENDLINE(finder))finder--; - prev2 = finder; - if (prev2>prev1){ // yes, we have body - data->body = prev1; - } - break; // there is nothing else - } - } - } - } - catch(...) - { - MessageBox(NULL,_T("Translate header error"),_T(""),0); - } - if (data->body) data->bodyLen = (int)strlen(data->body); -} - -//from decode.cpp -int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ); -int DecodeBase64(char *Src,char *Dst,int DstLen); -int ConvertStringToUnicode(char *stream,unsigned int cp,WCHAR **out); - -WCHAR *ParseMultipartBody(char *src, char *bond) -{ - char *srcback = _strdup(src); - size_t sizebond = strlen(bond); - int numparts = 1; - int i; - char *courbond = srcback; - WCHAR *dest; - for (;(courbond=strstr(courbond,bond));numparts++,courbond+=sizebond); - APartDataType *partData = new APartDataType[numparts]; - memset(partData, 0, sizeof(APartDataType)*numparts); - partData[0].Src = courbond = srcback; - for (i=1;(courbond=strstr(courbond,bond));i++,courbond+=sizebond){ - *(courbond-2) = 0; - partData[i].Src = courbond+sizebond; - while (ENDLINE(partData[i].Src)) partData[i].Src++; - } - size_t resultSize=0; - for (i=0;i -Delivered-To: pablo@decode.com.ar -Received: (qmail 5438 invoked by uid 618); 5 Sep 2003 19:49:16 -0000 -Mailing-List: contact foromundial-help@decode.com.ar; run by ezmlm -Precedence: bulk -X-No-Archive: yes -List-Post: -List-Help: -List-Unsubscribe: -List-Subscribe: -X-Seq: 1047 -Delivered-To: mailing list foromundial@decode.com.ar -Received: (qmail 5432 invoked by uid 618); 5 Sep 2003 19:49:15 -0000 -X-Spam-Status: No, hits=3.9 required=7.5 -Message-Id: <4.2.1.20030905163128.00a998a0@mail.labsem.cetuc.puc-rio.br> -X-Sender: sandra@mail.labsem.cetuc.puc-rio.br -X-Mailer: QUALCOMM Windows Eudora Pro Version 4.2.1 -Date: Fri, 05 Sep 2003 16:48:12 -0300 -To: foromundial@decode.com.ar -From: "Sandra M. Landi" -Mime-Version: 1.0 -Content-Type: multipart/alternative; - boundary="=====================_4293080==_.ALT" -X-Antirelay: Good relay from local net2 139.82.127.0/26 -Subject: [foromundial-1047] frases para un viernes - - -. diff --git a/protocols/YAMN/mails/test/header2.txt b/protocols/YAMN/mails/test/header2.txt deleted file mode 100644 index 3ba81a2bd0..0000000000 --- a/protocols/YAMN/mails/test/header2.txt +++ /dev/null @@ -1,97 +0,0 @@ -Return-Path: -Received: [from megami.sprintserve.net (megami.sprintserve.net [207.142.136.160]) - by mail2.ba.psg.sk with ESMTP id i4FHNUY6018585 - for ; Sat, 15 May 2004 19:23:31 +0200] -X-Envelope-To: -Received: from miranda by megami.sprintserve.net with local (Exim 4.34) - id 1BP2sS-0006W6-MS - for om3tn@psg.sk; Sat, 15 May 2004 13:23:12 -0400 -To: Undisclosed-recipients:; -Subject: UpozornØn¡ na odpovØÔ v t‚matu - YAMN problem -Reply-to: forum@miranda-im.org -From: forum@miranda-im.org: -Message-ID: -MIME-Version: 1.0 -Content-type: text/plain; charset=Windows-1250 -Content-transfer-encoding: 8bit -Date: Sat, 15 May 2004 13:23:12 -0400 -X-Priority: 3 -X-MSMail-Priority: Normal -X-Mailer: PHP -X-MimeOLE: Produced By phpBB2 -X-MailScanner-Information: Please contact the ISP for more information -X-MailScanner: Found to be clean -X-AntiAbuse: This header was added to track abuse, please include it with any abuse report -X-AntiAbuse: Primary Hostname - megami.sprintserve.net -X-AntiAbuse: Original Domain - psg.sk -X-AntiAbuse: Originator/Caller UID/GID - [32110 32110] / [47 12] -X-AntiAbuse: Sender Address Domain - megami.sprintserve.net -X-Source: -X-Source-Args: -X-Source-Dir: -. - -Subject: UpozornØn¡ na odpovØÔ v t‚matu - YAMN problem - -Return-Path: -Received: [from megami.sprintserve.net (megami.sprintserve.net [207.142.136.160]) - by mail2.ba.psg.sk with ESMTP id i4FHX2Y6020695 - for ; Sat, 15 May 2004 19:33:03 +0200] -X-Envelope-To: -Received: from miranda by megami.sprintserve.net with local (Exim 4.34) - id 1BP31h-0001cs-Ai - for om3tn@psg.sk; Sat, 15 May 2004 13:32:45 -0400 -To: Undisclosed-recipients:; -Subject: UpozornØn¡ na odpovØÔ v t‚matu - YAMN problem -Reply-to: forum@miranda-im.org -From: forum@miranda-im.org -Message-ID: <0873b36d0931479c4ebe23ba71ff4810@forums.miranda-im.org> -MIME-Version: 1.0 -Content-type: text/plain; charset=Windows-1250 -Content-transfer-encoding: 8bit -Date: Sat, 15 May 2004 13:32:45 -0400 -X-Priority: 3 -X-MSMail-Priority: Normal -X-Mailer: PHP -X-MimeOLE: Produced By phpBB2 -X-MailScanner-Information: Please contact the ISP for more information -X-MailScanner: Found to be clean -X-AntiAbuse: This header was added to track abuse, please include it with any abuse report -X-AntiAbuse: Primary Hostname - megami.sprintserve.net -X-AntiAbuse: Original Domain - psg.sk -X-AntiAbuse: Originator/Caller UID/GID - [32110 32110] / [47 12] -X-AntiAbuse: Sender Address Domain - megami.sprintserve.net -X-Source: -X-Source-Args: -X-Source-Dir: - -. - -Received: by hplm (mbox om3tn) - (with POP3 daemon cucipop (v1.31 1998/05/13) Tue May 27 18:42:20 2003) -X-From_: HMF@hotbox.ru Tue May 20 18:11:44 2003 -Return-Path: -Received: from ns1.slovanet.net (ns1.slovanet.net [195.28.64.119]) - by hplm.psg.sk (8.12.9/8.12.7) with SMTP id h4KGBfxJ003732 - for ; Tue, 20 May 2003 18:11:44 +0200 -X-Envelope-To: -Received: (qmail 6339 invoked from network); 20 May 2003 18:11:45 +0200 -Received: from unknown (HELO ??+???) (61.33.134.106) - by ns1.slovanet.net with SMTP; 20 May 2003 18:11:45 +0200 -Received: by london.com (Postfix, from userid 302) - id WTS; Tue, 20 May 2003 20:13:19 -Received: from Œù+⌥ (Œù+⌥ [61.33.134.106]) - by mill.co.uk (Postfix) with ESMTP id 613 - for ; Tue, 20 May 2003 20:13:19 -Subject: Òàìîæåííàî÷èñòêà. ÔèíëäèÌîñêâà. Îò 0,8 çà êã, âêëþ÷àâñå ! 20:13:19 -From: -To: OM3TN -Reply-To: <> -X-Mailer: AOL 7.0 for Windows UK sub 52 -X-Priority: 1 -X-MSMail-Priority: High -Mime-Version: 1.0 -Content-Type: text/html; charset="Windows-1251" -Content-Transfer-Encoding: 7bit -Date: Tue, 20 May 2003 20:13:21 -Message-Id: \ No newline at end of file diff --git a/protocols/YAMN/mails/test/readme.txt b/protocols/YAMN/mails/test/readme.txt deleted file mode 100644 index 35a30b255a..0000000000 --- a/protocols/YAMN/mails/test/readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -This is project for testing mime encoding/decoding. It -is very usefull for developers, when some problems with -non-standard headers occured. You can use it to step through -MIME decoding functions. diff --git a/protocols/YAMN/mails/test/test.cpp b/protocols/YAMN/mails/test/test.cpp deleted file mode 100644 index f8dcd14e89..0000000000 --- a/protocols/YAMN/mails/test/test.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is for testing purposes. Save in header.txt your problem header and you can - * browse through functions to get result - * - * (c) majvan 2002-2004 - */ - -#include -#include "../m_mails.h" - -extern void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head); -extern void ExtractHeader(struct CMimeItem *items,int CP,struct CHeader *head); - -void main() -{ - char Buffer[8192]; //we do not suppose longer header - FILE *fp; - YAMNMAIL *Mail; - PMAILDATA *MailData; - CMimeItem *head; - - struct CHeader ExtractedHeader; - - if(NULL==(fp=fopen("header2.txt","r"))) - return; - fread(Buffer,sizeof(Buffer),1,fp); - if(ferror(fp)) - { - fclose(fp); - return; - } - fclose(fp); - Mail = new YAMNMAIL; - MailData = new PMAILDATA; - head = new CMimeItem; - Mail->MailData = *MailData; - Mail->MailData->TranslatedHeader = head; - - TranslateHeaderFcn(Buffer,strlen(Buffer), &Mail->MailData->TranslatedHeader); - ExtractHeader(Mail->MailData->TranslatedHeader,CP_ACP,&ExtractedHeader); - return; -} \ No newline at end of file diff --git a/protocols/YAMN/mails/test/test.dsp b/protocols/YAMN/mails/test/test.dsp deleted file mode 100644 index 6d01b3669a..0000000000 --- a/protocols/YAMN/mails/test/test.dsp +++ /dev/null @@ -1,112 +0,0 @@ -# Microsoft Developer Studio Project File - Name="test" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=test - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "test.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "test.mak" CFG="test - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "test - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "test - Win32 Debug" (based on "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "test - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x405 /d "NDEBUG" -# ADD RSC /l 0x405 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 - -!ELSEIF "$(CFG)" == "test - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../../../include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c -# ADD BASE RSC /l 0x405 /d "_DEBUG" -# ADD RSC /l 0x405 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "test - Win32 Release" -# Name "test - Win32 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=..\decode.cpp -# End Source File -# Begin Source File - -SOURCE=..\mails.cpp -# End Source File -# Begin Source File - -SOURCE=..\mime.cpp -# End Source File -# Begin Source File - -SOURCE=.\test.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" -# End Group -# End Target -# End Project diff --git a/protocols/YAMN/mails/test/test.dsw b/protocols/YAMN/mails/test/test.dsw deleted file mode 100644 index e25096d17d..0000000000 --- a/protocols/YAMN/mails/test/test.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "test"=.\test.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/protocols/YAMN/main.cpp b/protocols/YAMN/main.cpp deleted file mode 100644 index e7e74ee7b4..0000000000 --- a/protocols/YAMN/main.cpp +++ /dev/null @@ -1,517 +0,0 @@ -/* - * YAMN plugin main file - * Miranda homepage: http://miranda-icq.sourceforge.net/ - * YAMN homepage: http://www.majvan.host.sk/Projekty/YAMN - * - * initializes all variables for further work - * - * (c) majvan 2002-2004 - */ - - -#include "yamn.h" -#include "main.h" -#include "resources/resource.h" -#include - -#include "m_hotkeys.h" - -//-------------------------------------------------------------------------------------------------- - -TCHAR ProfileName[MAX_PATH]; -TCHAR UserDirectory[MAX_PATH]; - -TCHAR szMirandaDir[MAX_PATH]; -TCHAR szProfileDir[MAX_PATH]; - -int YAMN_STATUS; - -BOOL UninstallPlugins; - -HANDLE hAccountFolder; - -HINSTANCE *hDllPlugins; -static int iDllPlugins = 0; - - -YAMN_VARIABLES YAMNVar; - -int hLangpack; - -PLUGININFOEX pluginInfo = { - sizeof(PLUGININFOEX), - YAMN_SHORTNAME, - YAMN_VERSION, - "Mail notifier and browser for Miranda NG. Included POP3 protocol.", - "y_b tweety (majvan)", - "francois.mean@skynet.be", - "© (2002-2004 majvan) 2005-2007 tweety y_b Miranda community", - "http://miranda-ng.org/", //"http://www.majvan.host.sk/Projekty/YAMN?fm = soft", - UNICODE_AWARE, - { 0xb047a7e5, 0x27a, 0x4cfc, { 0x8b, 0x18, 0xed, 0xa8, 0x34, 0x5d, 0x27, 0x90 } } // {B047A7E5-027A-4cfc-8B18-EDA8345D2790} -}; - -HANDLE hNewMailHook; -HANDLE NoWriterEV; -HANDLE hTTButton; - -UINT SecTimer; - -HANDLE hMenuItemMain = 0; -HANDLE hMenuItemCont = 0; -HANDLE hMenuItemContApp = 0; - -HMODULE hUxTheme = 0; -BOOL (WINAPI *MyEnableThemeDialogTexture)(HANDLE, DWORD) = 0; - -// function pointers, use typedefs for casting to shut up the compiler when using GetProcAddress() - -typedef BOOL (WINAPI *PITA)(); -typedef HANDLE (WINAPI *POTD)(HWND, LPCWSTR); -typedef UINT (WINAPI *PDTB)(HANDLE, HDC, int, int, RECT *, RECT *); -typedef UINT (WINAPI *PCTD)(HANDLE); -typedef UINT (WINAPI *PDTT)(HANDLE, HDC, int, int, LPCWSTR, int, DWORD, DWORD, RECT *); - -PITA pfnIsThemeActive = 0; -POTD pfnOpenThemeData = 0; -PDTB pfnDrawThemeBackground = 0; -PCTD pfnCloseThemeData = 0; -PDTT pfnDrawThemeText = 0; - -#define FIXED_TAB_SIZE 100 // default value for fixed width tabs - -/* - * visual styles support (XP+) - * returns 0 on failure - */ - -int InitVSApi() -{ - if ((hUxTheme = LoadLibraryA("uxtheme.dll")) == 0) - return 0; - - pfnIsThemeActive = (PITA)GetProcAddress(hUxTheme, "IsThemeActive"); - pfnOpenThemeData = (POTD)GetProcAddress(hUxTheme, "OpenThemeData"); - pfnDrawThemeBackground = (PDTB)GetProcAddress(hUxTheme, "DrawThemeBackground"); - pfnCloseThemeData = (PCTD)GetProcAddress(hUxTheme, "CloseThemeData"); - pfnDrawThemeText = (PDTT)GetProcAddress(hUxTheme, "DrawThemeText"); - - MyEnableThemeDialogTexture = (BOOL (WINAPI *)(HANDLE, DWORD))GetProcAddress(hUxTheme, "EnableThemeDialogTexture"); - if (pfnIsThemeActive != 0 && pfnOpenThemeData != 0 && pfnDrawThemeBackground != 0 && pfnCloseThemeData != 0 && pfnDrawThemeText != 0) - return 1; - - return 0; -} - -/* - * unload uxtheme.dll - */ - -int FreeVSApi() -{ - if (hUxTheme != 0) - FreeLibrary(hUxTheme); - return 0; -} - -//-------------------------------------------------------------------------------------------------- - -static void GetProfileDirectory(TCHAR *szPath, int cbPath) -//This is copied from Miranda's sources. In 0.2.1.0 it is needed, in newer vesions of Miranda use MS_DB_GETPROFILEPATH service -{ - TCHAR tszOldPath[MAX_PATH]; - CallService(MS_DB_GETPROFILEPATHT, SIZEOF(tszOldPath), (LPARAM)tszOldPath); - _tcscat(tszOldPath, _T("\\*.book")); - - TCHAR* ptszNewPath = Utils_ReplaceVarsT( _T("%miranda_userdata%")); - - SHFILEOPSTRUCT file_op = { - NULL, - FO_MOVE, - tszOldPath, - ptszNewPath, - FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_SILENT, - false, - 0, - _T("") }; - SHFileOperation(&file_op); - - _tcsncpy(szPath, ptszNewPath, cbPath); - mir_free(ptszNewPath); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - YAMNVar.hInst = hinstDLL; - return TRUE; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) -{ - return &pluginInfo; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MUUID_YAMN_FORCECHECK, MIID_LAST}; - -///////////////////////////////////////////////////////////////////////////////////////// - -#ifdef YAMN_DEBUG -static char unknownCP[1500] = {0}; -#endif -// The callback function -BOOL CALLBACK EnumSystemCodePagesProc(LPTSTR cpStr) -{ - //Convert code page string to number - UINT cp = _ttoi(cpStr); - if (!IsValidCodePage(cp)) - return TRUE; - - //Get Code Page name - CPINFOEX info; - if (GetCPInfoEx(cp, 0, &info)) { - #ifdef YAMN_DEBUG - BOOLEAN found = FALSE; - #endif - for (int i = 1;i= SIZEOF(iconList)) - return NULL; - return iconList[idx].hIcon; -} - -HICON WINAPI g_LoadIconEx( int idx, bool big ) -{ - if ( idx >= SIZEOF(iconList)) - return NULL; - return ( HICON )CallService(MS_SKIN2_GETICON, big, (LPARAM)iconList[idx].szName); -} - -void WINAPI g_ReleaseIcon( HICON hIcon ) -{ - if ( hIcon ) CallService(MS_SKIN2_RELEASEICON, (WPARAM)hIcon, 0); -} - -static void LoadPlugins() -{ - HANDLE hFind; - WIN32_FIND_DATA fd; - TCHAR szSearchPath[MAX_PATH]; - TCHAR szPluginPath[MAX_PATH]; - lstrcpy(szSearchPath, szMirandaDir); - lstrcat(szSearchPath, _T("\\Plugins\\YAMN\\*.dll")); - typedef INT_PTR (*LOADFILTERFCN)(MIRANDASERVICE GetYAMNFcn); - - hDllPlugins = NULL; - - if (INVALID_HANDLE_VALUE!=(hFind = FindFirstFile(szSearchPath, &fd))) { - do { - //rewritten from Miranda sources... Needed because Win32 API has a bug in FindFirstFile, search is done for *.dlllllll... too - TCHAR *dot = _tcsrchr(fd.cFileName, '.'); - if (dot == NULL ) - continue; - - // we have a dot - int len = (int)lstrlen(fd.cFileName); // find the length of the string - TCHAR* end = fd.cFileName+len; // get a pointer to the NULL - int safe = (end-dot)-1; // figure out how many chars after the dot are "safe", not including NULL - - if ((safe!=3) || (lstrcmpi(dot+1, _T("dll"))!=0)) //not bound, however the "dll" string should mean only 3 chars are compared - continue; - - HINSTANCE hDll; - LOADFILTERFCN LoadFilter; - - lstrcpy(szPluginPath, szMirandaDir); - lstrcat(szPluginPath, _T("\\Plugins\\YAMN\\")); - lstrcat(szPluginPath, fd.cFileName); - if ((hDll = LoadLibrary(szPluginPath)) == NULL) continue; - LoadFilter = (LOADFILTERFCN)GetProcAddress(hDll, "LoadFilter"); - if (NULL == LoadFilter) { - FreeLibrary(hDll); - hDll = NULL; - continue; - } - - if (!(*LoadFilter)(GetFcnPtrSvc)) { - FreeLibrary(hDll); - hDll = NULL; - } - - if (hDll != NULL) { - hDllPlugins = (HINSTANCE *)realloc((void *)hDllPlugins, (iDllPlugins+1)*sizeof(HINSTANCE)); - hDllPlugins[iDllPlugins++] = hDll; - } - } - while(FindNextFile(hFind, &fd)); - - FindClose(hFind); - } -} - -extern "C" int __declspec(dllexport) Load(void) -{ - int i, k; - mir_getLP(&pluginInfo); - - YAMN_STATUS = ID_STATUS_OFFLINE; - - // we get the Miranda Root Path - if (ServiceExists(MS_UTILS_PATHTOABSOLUTET)) - CallService(MS_UTILS_PATHTOABSOLUTET, (WPARAM)_T("."), (LPARAM)szMirandaDir); - else { - GetModuleFileName(GetModuleHandle(NULL), szMirandaDir, MAX_PATH); - TCHAR* str2 = _tcsrchr(szMirandaDir, '\\'); - if (str2!=NULL) *str2 = 0; - } - - // retrieve the current profile name - CallService(MS_DB_GETPROFILENAMET, (WPARAM)SIZEOF(ProfileName), (LPARAM)ProfileName); //not to pass entire array to fcn - TCHAR *fc = _tcsrchr(ProfileName, '.'); - if ( fc != NULL ) *fc = 0; - - // we get the user path where our yamn-account.book.ini is stored from mirandaboot.ini file - GetProfileDirectory(UserDirectory, SIZEOF(UserDirectory)); - - // Enumerate all the code pages available for the System Locale - EnumSystemCodePages(EnumSystemCodePagesProc, CP_INSTALLED); - CodePageNamesSupp = new _tcptable[CPLENSUPP]; - for (i = 0, k = 0; i < CPLENALL; i++) { - if (CodePageNamesAll[i].isValid){ - CodePageNamesSupp[k] = CodePageNamesAll[i]; - k++; - } } - - // Registering YAMN as protocol - PROTOCOLDESCRIPTOR pd = {0}; - pd.cbSize = PROTOCOLDESCRIPTOR_V3_SIZE; - pd.szName = YAMN_DBMODULE; - pd.type = PROTOTYPE_PROTOCOL; - CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd); - - InitializeCriticalSection(&AccountStatusCS); - InitializeCriticalSection(&FileWritingCS); - InitializeCriticalSection(&PluginRegCS); - - if (NULL == (NoWriterEV = CreateEvent(NULL, TRUE, TRUE, NULL))) - return 1; - if (NULL == (WriteToFileEV = CreateEvent(NULL, FALSE, FALSE, NULL))) - return 1; - if (NULL == (ExitEV = CreateEvent(NULL, TRUE, FALSE, NULL))) - return 1; - - PosX = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBPOSX, 0); - PosY = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBPOSY, 0); - SizeX = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBSIZEX, 800); - SizeY = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBSIZEY, 200); - - HeadPosX = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSX, 0); - HeadPosY = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSY, 0); - HeadSizeX = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEX, 690); - HeadSizeY = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEY, 300); - HeadSplitPos = DBGetContactSettingWord(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSSPLIT, 250); - - optDateTime = DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_DBTIMEOPTIONS, optDateTime); - - // Create new window queues for broadcast messages - YAMNVar.MessageWnds = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0); - YAMNVar.NewMailAccountWnd = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0); - YAMNVar.Shutdown = FALSE; - - hCurSplitNS = LoadCursor(NULL, IDC_SIZENS); - hCurSplitWE = LoadCursor(NULL, IDC_SIZEWE); - -#ifdef YAMN_DEBUG - InitDebug(); -#endif - - CreateServiceFunctions(); - - SkinAddNewSoundEx(YAMN_NEWMAILSOUND, YAMN_DBMODULE, YAMN_NEWMAILSNDDESC); - SkinAddNewSoundEx(YAMN_CONNECTFAILSOUND, YAMN_DBMODULE, YAMN_CONNECTFAILSNDDESC); - - HookEvents(); - - LoadIcons(); - LoadPlugins(); - InitVSApi(); - - HOTKEYDESC hkd = {0}; - hkd.cbSize = sizeof(hkd); - hkd.pszService = MS_YAMN_FORCECHECK; - hkd.pszSection = YAMN_DBMODULE; - hkd.pszDescription = LPGEN("Check mail"); - hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL, VK_F11); - Hotkey_Register(&hkd); - - //Create thread that will be executed every second - if (!(SecTimer = SetTimer(NULL, 0, 1000, (TIMERPROC)TimerProc))) - return 1; - - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static void UnloadPlugins() -{ - for (int i = iDllPlugins-1;i>=0;i--) { - if (FreeLibrary(hDllPlugins[i])) { - hDllPlugins[i] = NULL; //for safety - iDllPlugins --; - } - } - if (hDllPlugins){ - free((void *)hDllPlugins); - hDllPlugins = NULL; - } -} - -extern "C" int __declspec(dllexport) Unload(void) -{ -#ifdef YAMN_DEBUG - UnInitDebug(); -#endif - DestroyCursor(hCurSplitNS); - DestroyCursor(hCurSplitWE); - - CloseHandle(NoWriterEV); - CloseHandle(WriteToFileEV); - CloseHandle(ExitEV); - - FreeVSApi(); - - DeleteCriticalSection(&AccountStatusCS); - DeleteCriticalSection(&FileWritingCS); - DeleteCriticalSection(&PluginRegCS); - - UnhookEvents(); - DestroyServiceFunctions(); - - UnloadPlugins(); - - delete [] CodePageNamesSupp; - return 0; -} diff --git a/protocols/YAMN/main.h b/protocols/YAMN/main.h deleted file mode 100644 index 08d9f91fed..0000000000 --- a/protocols/YAMN/main.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef __MAIN_H -#define __MAIN_H - -#ifdef __GNUC__ - #define __try - #define __except(x) if (0) /* don't execute handler */ - #define __finally - #define _try __try - #define _except __except - #define _finally __finally -#endif - -#define YAMN_SHORTNAME "YAMN tweety" -#define YAMN_FILENAME "yamn" - - -#include "version.h" -#define YAMN_NEWMAILSNDDESC "YAMN: new mail message" -#define YAMN_CONNECTFAILSNDDESC "YAMN: connect failed" -#define YAMN_CONNECTFAILSOUND "YAMN/Sound/ConnectFail" -#define YAMN_NEWMAILSOUND "YAMN/Sound/NewMail" - -#define YAMN_DBMODULE "YAMN" -#define YAMN_DBPOSX "MailBrowserWinX" -#define YAMN_DBPOSY "MailBrowserWinY" -#define YAMN_DBSIZEX "MailBrowserWinW" -#define YAMN_DBSIZEY "MailBrowserWinH" -#define YAMN_DBMSGPOSX "MailMessageWinX" -#define YAMN_DBMSGPOSY "MailMessageWinY" -#define YAMN_DBMSGSIZEX "MailMessageWinW" -#define YAMN_DBMSGSIZEY "MailMessageWinH" -#define YAMN_DBMSGPOSSPLIT "MailMessageSplitY" -#define YAMN_TTBFCHECK "ForceCheckTTB" -#define YAMN_SHOWMAINMENU "ShowMainMenu" -#define YAMN_CLOSEDELETE "CloseOnDelete" -#define YAMN_SHOWASPROTO "ShowAsProtcol" -#define YAMN_DBTIMEOPTIONS "MailBrowserTimeOpts" - -#define YAMN_DEFAULTHK MAKEWORD(VK_F11,MOD_CONTROL) - -#define SHOWDATELONG 0x01 -#define SHOWDATENOTODAY 0x02 -#define SHOWDATENOSECONDS 0x04 - -extern unsigned char optDateTime; - -// Loading Icon and checking for icolib -void LoadIcons(); - -#endif - diff --git a/protocols/YAMN/proto/md5.c b/protocols/YAMN/proto/md5.c deleted file mode 100644 index 25546d2a65..0000000000 --- a/protocols/YAMN/proto/md5.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - */ -//#include /* for memcpy() */ -#if defined(_WIN64) - typedef unsigned __int64 size_t; -#else - typedef unsigned int size_t; - #include "../filter/simple/AggressiveOptimize.h" -#endif -void * __cdecl memcpy(void *, const void *, size_t); -void * __cdecl memset(void *, int, size_t); -#include "md5.h" - -#ifndef HIGHFIRST -#define byteReverse(buf, len) /* Nothing */ -#else -void byteReverse(unsigned char *buf, unsigned longs); - -#ifndef ASM_MD5 -/* - * Note: this code is harmless on little-endian machines. - */ -void byteReverse(unsigned char *buf, unsigned longs) -{ - uint32 t; - do { - t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | - ((unsigned) buf[1] << 8 | buf[0]); - *(uint32 *) buf = t; - buf += 4; - } while (--longs); -} -#endif -#endif - -/* - * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious - * initialization constants. - */ -void MD5Init(struct MD5Context *ctx) -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - - ctx->bits[0] = 0; - ctx->bits[1] = 0; -} - -/* - * Update context to reflect the concatenation of another buffer full - * of bytes. - */ -void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) -{ - uint32 t; - - /* Update bitcount */ - - t = ctx->bits[0]; - if ((ctx->bits[0] = t + ((uint32) len << 3)) < t) - ctx->bits[1]++; /* Carry from low to high */ - ctx->bits[1] += len >> 29; - - t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ - - /* Handle any leading odd-sized chunks */ - - if (t) { - unsigned char *p = (unsigned char *) ctx->in + t; - - t = 64 - t; - if (len < t) { - memcpy(p, buf, len); - return; - } - memcpy(p, buf, t); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); - buf += t; - len -= t; - } - /* Process data in 64-byte chunks */ - - while (len >= 64) { - memcpy(ctx->in, buf, 64); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); - buf += 64; - len -= 64; - } - - /* Handle any remaining bytes of data. */ - - memcpy(ctx->in, buf, len); -} - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -void MD5Final(unsigned char digest[16], struct MD5Context *ctx) -{ - unsigned count; - unsigned char *p; - - /* Compute number of bytes mod 64 */ - count = (ctx->bits[0] >> 3) & 0x3F; - - /* Set the first char of padding to 0x80. This is safe since there is - always at least one byte free */ - p = ctx->in + count; - *p++ = 0x80; - - /* Bytes of padding needed to make 64 bytes */ - count = 64 - 1 - count; - - /* Pad out to 56 mod 64 */ - if (count < 8) { - /* Two lots of padding: Pad the first block to 64 bytes */ - memset(p, 0, count); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); - - /* Now fill the next block with 56 bytes */ - memset(ctx->in, 0, 56); - } else { - /* Pad block to 56 bytes */ - memset(p, 0, count - 8); - } - byteReverse(ctx->in, 14); - - /* Append length in bits and transform */ - ((uint32 *) ctx->in)[14] = ctx->bits[0]; - ((uint32 *) ctx->in)[15] = ctx->bits[1]; - - MD5Transform(ctx->buf, (uint32 *) ctx->in); - byteReverse((unsigned char *) ctx->buf, 4); - memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ -} - -#ifndef ASM_MD5 - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks - * the data and converts bytes into longwords for this routine. - */ -void MD5Transform(uint32 buf[4], uint32 const in[16]) -{ - register uint32 a, b, c, d; - - a = buf[0]; - b = buf[1]; - c = buf[2]; - d = buf[3]; - - MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - buf[0] += a; - buf[1] += b; - buf[2] += c; - buf[3] += d; -} - -#endif diff --git a/protocols/YAMN/proto/md5.h b/protocols/YAMN/proto/md5.h deleted file mode 100644 index e264f686db..0000000000 --- a/protocols/YAMN/proto/md5.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MD5_H -#define MD5_H - -#ifdef __alpha -typedef unsigned int uint32; -#else -typedef unsigned long uint32; -#endif - -struct MD5Context { - uint32 buf[4]; - uint32 bits[2]; - unsigned char in[64]; -}; - -void MD5Init(struct MD5Context *context); -void MD5Update(struct MD5Context *context, unsigned char const *buf, - unsigned len); -void MD5Final(unsigned char digest[16], struct MD5Context *context); -void MD5Transform(uint32 buf[4], uint32 const in[16]); - -/* - * This is needed to make RSAREF happy on some MS-DOS compilers. - */ -typedef struct MD5Context MD5_CTX; - -#endif /* !MD5_H */ diff --git a/protocols/YAMN/proto/netclient.h b/protocols/YAMN/proto/netclient.h deleted file mode 100644 index 2414dbdef1..0000000000 --- a/protocols/YAMN/proto/netclient.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __CLIENT_H -#define __CLIENT_H - -class CNetClient -{ -public: - CNetClient(): Stopped(FALSE) {} - virtual void Connect(const char* servername,const int port)=0; - virtual void Send(const char *query)=0; - virtual char* Recv(char *buf=NULL,int buflen=65536)=0; - virtual void Disconnect()=0; - virtual BOOL Connected()=0; - virtual void SSLify()=0; - - BOOL Stopped; - int Rcv; - DWORD NetworkError; - DWORD SystemError; - BOOL ifTLSed; -}; - -#endif diff --git a/protocols/YAMN/proto/netlib.cpp b/protocols/YAMN/proto/netlib.cpp deleted file mode 100644 index b7c1864ffa..0000000000 --- a/protocols/YAMN/proto/netlib.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/* - * This code implements communication based on Miranda netlib library - * - * (c) majvan 2002-2004 - */ - -#include "..\yamn.h" -#include "m_netlib.h" -#include "netlib.h" - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -BOOL SSLLoaded=FALSE; -HANDLE hNetlibUser=NULL; - -extern PVOID TLSCtx; -extern PVOID SSLCtx; - -void __stdcall SSL_DebugLog(const char *fmt, ...) -{ - char str[ 4096 ]; - va_list vararg; - - va_start( vararg, fmt ); - int tBytes = _vsnprintf( str, sizeof(str)-1, fmt, vararg ); - if ( tBytes == 0 ) - return; - - if ( tBytes > 0 ) - str[ tBytes ] = 0; - else - str[ sizeof(str)-1 ] = 0; - - CallService(MS_NETLIB_LOG, (WPARAM)hNetlibUser, (LPARAM)str); - va_end( vararg ); -} - -HANDLE RegisterNLClient(const char *name) -{ - static NETLIBUSER nlu={0}; - char desc[128]; - - sprintf(desc, Translate("%s connection"),name); - -#ifdef DEBUG_COMM - DebugLog(CommFile,""); -#endif - nlu.cbSize = sizeof(nlu); - nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS; - nlu.szDescriptiveName=desc; - nlu.szSettingsModule=(char *)name; - hNetlibUser=(HANDLE)CallService(MS_NETLIB_REGISTERUSER,0,(LPARAM)&nlu); - -#ifdef DEBUG_COMM - if (NULL==hNetlibUser) - DebugLog(CommFile,"\n"); - else - DebugLog(CommFile,"\n"); -#endif - return hNetlibUser; -} - -//Move connection to SSL -void CNLClient::SSLify() throw(DWORD){ -#ifdef DEBUG_COMM - SSL_DebugLog("Staring SSL..."); -#endif - int socket = CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConnection, 0); - if (socket != INVALID_SOCKET) - { -#ifdef DEBUG_COMM - SSL_DebugLog("Staring netlib core SSL"); -#endif - if (CallService(MS_NETLIB_STARTSSL, (WPARAM)hConnection, 0)) - { -#ifdef DEBUG_COMM - SSL_DebugLog("Netlib core SSL started"); -#endif - isTLSed = true; - SSLLoaded = TRUE; - return; - } - } - - //ssl could not be created - throw NetworkError = (DWORD)ESSL_CREATESSL; -} - -//Connects to the server through the sock -//if not success, exception is throwed -void CNLClient::Connect(const char* servername,const int port) throw(DWORD) -{ - NETLIBOPENCONNECTION nloc; - - NetworkError=SystemError=0; - isTLSed = false; - -#ifdef DEBUG_COMM - DebugLog(CommFile,"\n"); -#endif - try - { - nloc.cbSize=sizeof(NETLIBOPENCONNECTION); - nloc.szHost=servername; - nloc.wPort=port; - nloc.flags=0; - if (NULL==(hConnection=(HANDLE)CallService(MS_NETLIB_OPENCONNECTION,(WPARAM)hNetlibUser,(LPARAM)&nloc))) - { - SystemError=WSAGetLastError(); - throw NetworkError=(DWORD)ENL_CONNECT; - } -#ifdef DEBUG_COMM - DebugLog(CommFile,"\n"); -#endif - return; - } - catch(...) - { -#ifdef DEBUG_COMM - DebugLog(CommFile,"\n"); -#endif - throw; - } -} - -//Performs a simple query -// query- command to send -int CNLClient::LocalNetlib_Send(HANDLE hConn,const char *buf,int len,int flags) { - if (isTLSed) - { -#ifdef DEBUG_COMM - SSL_DebugLog("SSL send: %s", buf); -#endif - } - - NETLIBBUFFER nlb={(char*)buf,len,flags}; - return CallService(MS_NETLIB_SEND,(WPARAM)hConn,(LPARAM)&nlb); -} - -void CNLClient::Send(const char *query) throw(DWORD) -{ - unsigned int Sent; - - if (NULL==query) - return; - if (hConnection==NULL) - return; -#ifdef DEBUG_COMM - DebugLog(CommFile,"%s",query); -#endif - try - { - if ((SOCKET_ERROR==(Sent=LocalNetlib_Send(hConnection,query,(int)strlen(query),MSG_DUMPASTEXT))) || Sent!=(unsigned int)strlen(query)) - { - SystemError=WSAGetLastError(); - throw NetworkError=(DWORD)ENL_SEND; - } -#ifdef DEBUG_COMM - DebugLog(CommFile,"\n"); -#endif - } - catch(...) - { -#ifdef DEBUG_COMM - DebugLog(CommFile,"\n"); -#endif - throw; - } -} - -//Reads data from socket -// buf- buffer where to store max. buflen of received characters -// if buf is NULL, creates buffer of buflen size -// buf is NULL by default -//You need free() returned buffer, which can be allocated in this function -//if not success, exception is throwed - -int CNLClient::LocalNetlib_Recv(HANDLE hConn,char *buf,int len,int flags) { - NETLIBBUFFER nlb={buf,len,flags}; - int iReturn = CallService(MS_NETLIB_RECV,(WPARAM)hConn,(LPARAM)&nlb); - if (isTLSed) - { -#ifdef DEBUG_COMM - SSL_DebugLog("SSL recv: %s", buf); -#endif - } - - return iReturn; -} - -char* CNLClient::Recv(char *buf,int buflen) throw(DWORD) -{ -#ifdef DEBUG_COMM - DebugLog(CommFile,""); -#endif - try - { - if (buf==NULL) - buf=(char *)malloc(sizeof(char)*(buflen+1)); - if (buf==NULL) - throw NetworkError=(DWORD)ENL_RECVALLOC; - - if (!isTLSed) - { - NETLIBSELECT nls; - memset(&nls, 0, sizeof(NETLIBSELECT)); - nls.cbSize = sizeof(NETLIBSELECT); - nls.dwTimeout = 60000; - nls.hReadConns[0] = hConnection; - switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM) &nls)) - { - case SOCKET_ERROR: - free(buf); - SystemError=WSAGetLastError(); - throw NetworkError = (DWORD) ENL_RECV; - case 0: // time out! - free(buf); - throw NetworkError = (DWORD) ENL_TIMEOUT; - } - } - - ZeroMemory(buf,buflen); - if (SOCKET_ERROR==(Rcv=LocalNetlib_Recv(hConnection,buf,buflen,MSG_DUMPASTEXT))) - { - free(buf); - SystemError=WSAGetLastError(); - throw NetworkError=(DWORD)ENL_RECV; - } - if (!Rcv) - { - free(buf); - SystemError=WSAGetLastError(); - throw NetworkError=(DWORD)ENL_RECV; - } -#ifdef DEBUG_COMM - *(buf+Rcv)=0; //end the buffer to write it to file - DebugLog(CommFile,"%s",buf); - DebugLog(CommFile,"\n"); -#endif - return(buf); - } - catch(...) - { -#ifdef DEBUG_COMM - DebugLog(CommFile,"\n"); -#endif - throw; - } -} - -//Closes netlib connection -void CNLClient::Disconnect() -{ - Netlib_CloseHandle(hConnection); - hConnection=(HANDLE)NULL; -} - -//Uninitializes netlib library -void UnregisterNLClient() -{ -#ifdef DEBUG_COMM - DebugLog(CommFile,""); -#endif - - Netlib_CloseHandle(hNetlibUser); - hNetlibUser=(HANDLE)NULL; -#ifdef DEBUG_COMM - DebugLog(CommFile,"\n"); -#endif -} diff --git a/protocols/YAMN/proto/netlib.h b/protocols/YAMN/proto/netlib.h deleted file mode 100644 index 90ad3613a5..0000000000 --- a/protocols/YAMN/proto/netlib.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef __NETLIB_H -#define __NETLIB_H - -#include "netclient.h" - -#pragma warning( disable : 4290 ) - -class CNLClient: public CNetClient -{ -public: - CNLClient(): hConnection(NULL) {} - void Connect(const char* servername,const int port) throw(DWORD); - void Send(const char *query) throw(DWORD); - char* Recv(char *buf=NULL,int buflen=65536) throw(DWORD); - void Disconnect(); - void SSLify()throw(DWORD); - - inline BOOL Connected() {return hConnection!=NULL;} - -protected: - HANDLE hConnection; - BOOL isTLSed; - int LocalNetlib_Send(HANDLE hConn,const char *buf,int len,int flags); - int LocalNetlib_Recv(HANDLE hConn,char *buf,int len,int flags); -}; - -void SSL_DebugLog(const char *fmt, ...); - -enum -{ - ENL_WINSOCKINIT=1, //error initializing socket //only wsock - ENL_GETHOSTBYNAME, //DNS error //only wsock - ENL_CREATESOCKET, //error creating socket //only wsock - ENL_CONNECT, //cannot connect to server - ENL_SEND, //cannot send data - ENL_RECV, //cannot receive data - ENL_RECVALLOC, //cannot allocate memory for received data - ENL_TIMEOUT, //timed out during recv -}; - -enum -{ - ESSL_NOTLOADED=1, //OpenSSL is not loaded - ESSL_WINSOCKINIT, //WinSock 2.0 init failed - ESSL_GETHOSTBYNAME, //DNS error - ESSL_CREATESOCKET, //error creating socket - ESSL_SOCKETCONNECT, //error connecting with socket - ESSL_CREATESSL, //error creating SSL session structure - ESSL_SETSOCKET, //error connect socket with SSL session for bidirect I/O space - ESSL_CONNECT, //cannot connect to server - ESSL_SEND, //cannot send data - ESSL_RECV, //cannot receive data - ESSL_RECVALLOC, //cannot allocate memory for received data -}; -#endif diff --git a/protocols/YAMN/proto/pop3/pop3.cpp b/protocols/YAMN/proto/pop3/pop3.cpp deleted file mode 100644 index 05e85d7156..0000000000 --- a/protocols/YAMN/proto/pop3/pop3.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/* - * This code implements basics of POP3 protocol - * - * (c) majvan 2002-2004 - */ -/* This was made from the libspopc project - * copyright c 2002 Benoit Rouits - * released under the terms of GNU LGPL - * (GNU Lesser General Public Licence). - * libspopc offers simple API for a pop3 client (MTA). - * See RFC 1725 for pop3 specifications. - * more information on http://brouits.free.fr/libspopc/ - */ -/* - * This file is not original and is changed by majvan - * for mail checker purpose. Please see original web page to - * obtain the original. I rewrote it in C++, but good ideas were, - * I think, unchanged. - * - * Note that this file was not designed to work under Unix. It's - * needed to add Unix-specific features. I was interested only in - * Windows for my project. majvan - * - */ - -#pragma warning( disable : 4290 ) - -#include "..\..\yamn.h" -#include "pop3.h" - -extern "C" { -#include "../md5.h" -} - -extern void __stdcall SSL_DebugLog( const char *fmt, ... ); - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -//Connects to the server through the netlib -//if not success, exception is throwed -//returns welcome string returned by server -//sets AckFlag -char *CPop3Client::Connect(const char* servername,const int port,BOOL UseSSL, BOOL NoTLS) -{ - char *temp = 0; - if (Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - if (NetClient!=NULL) - delete NetClient; - SSL=UseSSL; - NetClient=new CNLClient; - -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"Connect:servername: %s port:%d\n",servername,port); -#endif - POP3Error=EPOP3_CONNECT; - NetClient->Connect(servername,port); - POP3Error=0; - - if (SSL) - { - try { NetClient->SSLify(); } - catch (...) - { - NetClient->Disconnect(); - return NULL; - } - } - - temp = RecvRest(NetClient->Recv(),POP3_SEARCHACK); - extern BOOL SSLLoaded; - if (!NoTLS & !(SSL)) { - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - NetClient->Send("STLS\r\n"); - free(temp); - temp=RecvRest(NetClient->Recv(),POP3_SEARCHACK); - if (AckFlag==POP3_FOK){ // Ok, we are going to tls - try { - NetClient->SSLify(); - } catch (...) { - NetClient->Disconnect(); - return NULL; - } -// temp = RecvRest(NetClient->Recv(),POP3_SEARCHACK); - } - } -// SSL_DebugLog("Received: %s",temp); - return temp; -} - -//Receives data to the end of packet -// prev- previous data read (appends to this string next received data) -// mode- mode of packet. -// Packet can end with ack state (+OK or -ERR): set mode to POP3_SEARCHACK -// If packet ends with '.' (end of string), set mode to POP3_SEARCHDOT -// size- received data are stored to memory, but if length of data is more than allocated memory, function allocates -// new memory. New allocated memory has allocated size more bytes -// This value can be selectable: if you think it is better to reallocate by 1kB size, select size to 1024, -// default is 128. You do not need to use this parameter -char* CPop3Client::RecvRest(char* prev,int mode,int size) -{ - int SizeRead=0; - int SizeLeft=size-NetClient->Rcv; - int RcvAll=NetClient->Rcv; - char *LastString,*PrevString=prev; - - AckFlag=0; - - while(((mode==POP3_SEARCHDOT) && !SearchFromEnd(PrevString+RcvAll-1,RcvAll-3,POP3_SEARCHDOT) && !SearchFromStart(PrevString,2,POP3_SEARCHERR)) || //we are looking for dot or -err phrase - ((mode==POP3_SEARCHACK) && (!SearchFromStart(PrevString,RcvAll-3,mode) || !((RcvAll>3) && SearchFromEnd(PrevString+RcvAll-1,1,POP3_SEARCHNL))))) //we are looking for +ok or -err phrase ended with newline - { //if not found - if (NetClient->Stopped) //check if we can work with this POP3 client session - { - if (PrevString!=NULL) - free(PrevString); - throw POP3Error=(DWORD)EPOP3_STOPPED; - } - if (SizeLeft==0) //if block is full - { - SizeRead+=size; - SizeLeft=size; - LastString=NetClient->Recv(NULL,SizeLeft); - PrevString=(char *)realloc(PrevString,sizeof(char)*(SizeRead+size)); - if (PrevString==NULL) - throw POP3Error=(DWORD)EPOP3_RESTALLOC; - memcpy(PrevString+SizeRead,LastString,size); - free(LastString); - } - else - NetClient->Recv(PrevString+RcvAll,SizeLeft); //to Rcv stores received bytes - SizeLeft=SizeLeft-NetClient->Rcv; - RcvAll+=NetClient->Rcv; -// printf("[Read: %s]\n",PrevString); - } - NetClient->Rcv=RcvAll; //at the end, store the number of all bytes, no the number of last received bytes - return PrevString; -} - -// CPop3Client::SearchFromEnd -// returns 1 if substring DOTLINE or ENDLINE found from end in bs bytes -// if you need to add condition for mode, insert it into switch statement -BOOL CPop3Client::SearchFromEnd(char *end,int bs,int mode) -{ - while(bs>=0) - { - switch(mode) - { - case POP3_SEARCHDOT: - if (DOTLINE(end)) - return 1; - break; - case POP3_SEARCHNL: - if (ENDLINE(end)) - return 1; - break; - } - end--; - bs--; - } - return 0; -} - -//Finds for a occurence of some pattern in string -// returns 1 if substring OKLINE, ERRLINE or any of them found from start in bs bytes -//call only this function to retrieve ack status (+OK or -ERR), because it sets flag AckFlag -//if you need to add condition for mode, insert it into switch statement -BOOL CPop3Client::SearchFromStart(char *start,int bs,int mode) -{ - while(bs>=0) - { - switch(mode) - { - case POP3_SEARCHOK: - if (OKLINE(start)) - { - AckFlag=POP3_FOK; - return 1; - } - break; - case POP3_SEARCHERR: - if (ERRLINE(start)) - { - AckFlag=POP3_FERR; - return 1; - } - break; - case POP3_SEARCHACK: - if (ACKLINE(start)) - { - OKLINE(start) ? AckFlag=POP3_FOK : AckFlag=POP3_FERR; - return 1; - } - break; - } - start++; - bs--; - } - return 0; -} - -//Performs "USER" pop query and returns server response -//sets AckFlag -char* CPop3Client::User(char* name) -{ - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - char query[128]; - char *Result; - - sprintf(query,"USER %s\r\n",name); - NetClient->Send(query); - Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); - if (AckFlag==POP3_FERR) - throw POP3Error=(DWORD)EPOP3_BADUSER; - POP3Error=0; - return Result; -} - -//Performs "PASS" pop query and returns server response -//sets AckFlag -char* CPop3Client::Pass(char* pw) -{ - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - char query[128]; - char *Result; - - sprintf(query,"PASS %s\r\n",pw); - NetClient->Send(query); - Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); - if (AckFlag==POP3_FERR) - throw POP3Error=(DWORD)EPOP3_BADPASS; - return Result; -} - -//Performs "APOP" pop query and returns server response -//sets AckFlag -char* CPop3Client::APOP(char* name, char* pw, char* timestamp) -{ - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - char query[512]; - char *Result; - unsigned char digest[16]; - char hexdigest[40]; - - if (timestamp==NULL) - throw POP3Error=(DWORD)EPOP3_APOP; - MD5Context ctx; - MD5Init(&ctx); - MD5Update(&ctx,(const unsigned char *)timestamp,(unsigned int)strlen(timestamp)); - MD5Update(&ctx,(const unsigned char *)pw,(unsigned int)strlen(pw)); - MD5Final(digest,&ctx); - hexdigest[0]='\0'; - for (int i=0; i<16; i++) { - char tmp[4]; - sprintf(tmp, "%02x", digest[i]); - strcat(hexdigest, tmp); - } - sprintf(query,"APOP %s %s\r\n",name, hexdigest); - NetClient->Send(query); - Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); - if (AckFlag==POP3_FERR) - throw POP3Error=(DWORD)EPOP3_BADUSER; - return Result; -} - -//Performs "QUIT" pop query and returns server response -//sets AckFlag -char* CPop3Client::Quit() -{ - char query[]="QUIT\r\n"; - - NetClient->Send(query); - return RecvRest(NetClient->Recv(),POP3_SEARCHACK); -} - -//Performs "STAT" pop query and returns server response -//sets AckFlag -char* CPop3Client::Stat() -{ - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - char query[]="STAT\r\n"; - - NetClient->Send(query); - return RecvRest(NetClient->Recv(),POP3_SEARCHACK); -} - -//Performs "LIST" pop query and returns server response -//sets AckFlag -char* CPop3Client::List() -{ - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - char query[]="LIST\r\n"; - - NetClient->Send(query); - return RecvRest(NetClient->Recv(),POP3_SEARCHDOT); -} - -//Performs "TOP" pop query and returns server response -//sets AckFlag -char* CPop3Client::Top(int nr, int lines) -{ - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - char query[128]; - - sprintf(query,"TOP %d %d\r\n",nr,lines); - NetClient->Send(query); - return RecvRest(NetClient->Recv(),POP3_SEARCHDOT); -} - -//Performs "UIDL" pop query and returns server response -//sets AckFlag -char* CPop3Client::Uidl(int nr) -{ - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - char query[128]; - - if (nr) - { - sprintf(query,"UIDL %d\r\n",nr); - NetClient->Send(query); - return RecvRest(NetClient->Recv(),POP3_SEARCHACK); - } - sprintf(query,"UIDL\r\n"); - NetClient->Send(query); - return RecvRest(NetClient->Recv(),POP3_SEARCHDOT); -} - -//Performs "DELE" pop query and returns server response -//sets AckFlag -char* CPop3Client::Dele(int nr) -{ - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - char query[128]; - - sprintf(query,"DELE %d\r\n",nr); - NetClient->Send(query); - return RecvRest(NetClient->Recv(),POP3_SEARCHACK); -} -//Performs "RETR" pop query and returns server response -//sets AckFlag -char* CPop3Client::Retr(int nr) -{ - if (NetClient->Stopped) //check if we can work with this POP3 client session - throw POP3Error=(DWORD)EPOP3_STOPPED; - - char query[128]; - - sprintf(query,"RETR %d\r\n",nr); - NetClient->Send(query); - RecvRest(NetClient->Recv(),POP3_SEARCHACK); - return NetClient->Recv(); -} \ No newline at end of file diff --git a/protocols/YAMN/proto/pop3/pop3.h b/protocols/YAMN/proto/pop3/pop3.h deleted file mode 100644 index 1f7f2ea737..0000000000 --- a/protocols/YAMN/proto/pop3/pop3.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef __POP3_H -#define __POP3_H - -#include "../../debug.h" -#include "../netlib.h" //NetLib client - -#define DOTLINE(s) ((((s)[-2]=='\r') || ((s)[-2]=='\n')) && ((s)[-1]=='.') && (((s)[0]=='\r') || ((s)[0]=='\n') || ((s)[0]=='\0'))) // be careful, it's different to ESR's pop3.c ;-) -#define ENDLINE(s) (((s)[0]=='\r') || ((s)[0]=='\n')) //endline -#define OKLINE(s) (((s)[0]=='+') && (((s)[1]=='o') || ((s)[1]=='O')) && (((s)[2]=='k') || ((s)[2]=='K'))) // +OK -#define ERRLINE(s) (((s)[0]=='-') && (((s)[1]=='e') || ((s)[1]=='E')) && (((s)[2]=='r') || ((s)[2]=='R')) && (((s)[3]=='r') || ((s)[3]=='R'))) // -ERR -#define ACKLINE(s) (OKLINE(s) || ERRLINE(s)) - -#define POP3_SEARCHDOT 1 -#define POP3_SEARCHACK 2 -#define POP3_SEARCHOK 3 -#define POP3_SEARCHERR 4 -#define POP3_SEARCHNL 5 - -#define POP3_FOK 1 -#define POP3_FERR 2 - -class CPop3Client -{ -public: - CPop3Client(): NetClient(NULL), Stopped(FALSE) {} - ~CPop3Client() {if (NetClient!=NULL) delete NetClient;} - - char* Connect(const char* servername,const int port=110,BOOL UseSSL=FALSE, BOOL NoTLS=FALSE); - char* RecvRest(char* prev,int mode,int size=65536); - char* User(char* name); - char* Pass(char* pw); - char* APOP(char* name, char* pw, char* timestamp); - char* Quit(); - char* Stat(); - char* List(); - char* Top(int nr, int lines=0); - char* Uidl(int nr=0); - char* Dele(int nr); - char* Retr(int nr); - - unsigned char AckFlag; - BOOL SSL; - BOOL Stopped; - - DWORD POP3Error; - class CNetClient *NetClient; //here the network layout is defined (TCP or SSL+TCP etc.) -private: - BOOL SearchFromEnd(char *end,int bs,int mode); - BOOL SearchFromStart(char *end,int bs,int mode); -}; - -enum -{ - EPOP3_QUEUEALLOC=1, //memory allocation - EPOP3_STOPPED, //stop account - EPOP3_CONNECT, //cannot connect to server - EPOP3_RESTALLOC, //cannot allocate memory for received data - EPOP3_BADUSER, //cannot login because USER command failed - EPOP3_BADPASS, //cannot login because PASS command failed - EPOP3_APOP, //server does not send timestamp for APOP auth - EPOP3_STAT, - EPOP3_LIST, - EPOP3_UIDL, -}; - -#endif diff --git a/protocols/YAMN/proto/pop3/pop3comm.cpp b/protocols/YAMN/proto/pop3/pop3comm.cpp deleted file mode 100644 index 954f1b5860..0000000000 --- a/protocols/YAMN/proto/pop3/pop3comm.cpp +++ /dev/null @@ -1,1563 +0,0 @@ -/* - * This code implements POP3 server checking for new mail and so on. - * There's function SynchroPOP3 in this file- for checking and synchronising POP3 account - * and DeleteMailsPOP3- for deleting mails from POP3 server - * - * Note this file acts as main file for internal plugin. - * - * (c) majvan 2002-2004 - * 18/08 -*/ - - -#pragma warning( disable : 4290 ) -#include "../../yamn.h" -#include "../../main.h" -#include "pop3.h" -#include "pop3comm.h" //all we need for POP3 account (POP3 account= YAMN account + some more POP3 specified members) -#include //socket thorugh proxy functions - -#define ERRORSTR_MAXLEN 1024 //in wide-chars - -//-------------------------------------------------------------------------------------------------- - -HANDLE hNetLib = NULL; -PSCOUNTER CPOP3Account::AccountWriterSO = NULL; - -//Creates new CPOP3Account structure -HACCOUNT WINAPI CreatePOP3Account(HYAMNPROTOPLUGIN Plugin,DWORD CAccountVersion); - -//Deletes CPOP3Account structure -void WINAPI DeletePOP3Account(HACCOUNT Which); - -//Sets stop flag to account -void WINAPI StopPOP3Account(HACCOUNT Which); - -//Function registers standard functions for YAMN -int RegisterPOP3Plugin(WPARAM,LPARAM); - -//Unloads all variables created on heap (delete[]) -DWORD WINAPI UnLoadPOP3(void *); - -//Function writes POP3 accounts using YAMN exported functions -DWORD WINAPI WritePOP3Accounts(); - -//Function stores plugin's data for account to file -DWORD WINAPI WritePOP3Options(HANDLE,HACCOUNT); - -//Function reads plugin's data for account from file -DWORD WINAPI ReadPOP3Options(HACCOUNT,char **,char *); - -//Creates new mail for an account -HYAMNMAIL WINAPI CreatePOP3Mail(HACCOUNT Account,DWORD CMimeMailVersion); - -//Function does all needed work when connection failed or any error occured -//Creates structure containing error code, closes internet session, runs "bad connect" function -static void PostErrorProc(HPOP3ACCOUNT ActualAccount,void *ParamToBadConnect,DWORD POP3PluginParam,BOOL UseSSL); - -//Checks POP3 account and stores all info to account. It deletes old mails=> synchro -// WhichTemp- pointer to strucure containing needed information -DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp); - -//Deletes mails from POP3 server -// WhichTemp- structure containing needed information (queued messages to delete) -//Function deletes from memory queue in WhichTemp structure -DWORD WINAPI DeleteMailsPOP3(struct DeleteParam *WhichTemp); - -//Function makes readable message about error. It sends it back to YAMN, so YAMN then -//can show it to the message window -TCHAR* WINAPI GetErrorString(DWORD Code); - -//Function deletes string allocated in GetErrorString -void WINAPI DeleteErrorString(LPVOID String); - -//Extracts info from result of POP3's STAT command -// stream- source string -// len- length of source string -// mboxsize- adreess to integer, that receives size of mailbox -// mails- adreess to integer, that receives number of mails -void ExtractStat(char *stream,int len,int *mboxsize,int *mails); - -//Extracts mail ID on mailbox -// stream- source string -// len- length of source string -// queue- address of first message, where first ID will be stored -void ExtractUIDL(char *stream,int len,HYAMNMAIL queue); - -//Extracts mail size on mailbox -// stream- source string -// len- length of source string -// queue- address of first message, where size of message #1 will be stored -void ExtractList(char *stream,int len,HYAMNMAIL queue); - -void ExtractMail(char *stream,int len,HYAMNMAIL queue); - -YAMNExportedFcns *pYAMNFcn = NULL; -MailExportedFcns *pYAMNMailFcn = NULL; - -YAMN_PROTOIMPORTFCN POP3ProtocolFunctions = -{ - CreatePOP3Account, - DeletePOP3Account, - StopPOP3Account, - WritePOP3Options, - ReadPOP3Options, - SynchroPOP3, - SynchroPOP3, - SynchroPOP3, - DeleteMailsPOP3, - GetErrorString, - NULL, - DeleteErrorString, - WritePOP3Accounts, - NULL, - UnLoadPOP3, -}; - -YAMN_MAILIMPORTFCN POP3MailFunctions = -{ - CreatePOP3Mail, - NULL, - NULL, - NULL, -}; - -PYAMN_VARIABLES pYAMNVar = NULL; -HYAMNPROTOPLUGIN POP3Plugin = NULL; - -YAMN_PROTOREGISTRATION POP3ProtocolRegistration = -{ - "POP3 protocol (internal)", - YAMN_VERSION_C, - "© 2002-2004 majvan | 2005-2007 tweety, yb", - "Mail notifier and browser for Miranda NG. Included POP3 protocol.", - "francois.mean@skynet.be", - "http://miranda-ng.org/", -}; - -static TCHAR *FileName = NULL; - -HANDLE RegisterNLClient(const char *name); - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -CPOP3Account::CPOP3Account() -{ -//NOTE! This constructor constructs CAccount structure. If your plugin is not internal, -//you will need these constructors. All you need is in Account.cpp. Just copy to your source code -//constructor and destructor of CAccount. - UseInternetFree=CreateEvent(NULL,FALSE,TRUE,NULL); - InternetQueries=new SCOUNTER; - AbilityFlags=YAMN_ACC_BROWSE | YAMN_ACC_POPUP; - - SetAccountStatus((HACCOUNT)this,TranslateT("Disconnected")); -} - -CPOP3Account::~CPOP3Account() -{ - CloseHandle(UseInternetFree); - if (InternetQueries!=NULL) - delete InternetQueries; -} - -HACCOUNT WINAPI CreatePOP3Account(HYAMNPROTOPLUGIN Plugin,DWORD CAccountVersion) -{ -//First, we should check whether CAccountVersion matches. -//But this is internal plugin, so YAMN's CAccount structure and our CAccount structure are -//the same, so we do not need to test version. Otherwise, if CAccount version does not match -//in your plugin, you should return NULL, like this: -// if (CAccountVersion!=YAMN_ACCOUNTVERSION) return NULL; - -//Now it is needed to construct our POP3 account and return its handle - return (HACCOUNT)new struct CPOP3Account(); -} - -void WINAPI DeletePOP3Account(HACCOUNT Which) -{ - delete (HPOP3ACCOUNT)Which; -} - -void WINAPI StopPOP3Account(HACCOUNT Which) -{ - ((HPOP3ACCOUNT)Which)->Client.Stopped=TRUE; - if (((HPOP3ACCOUNT)Which)->Client.NetClient!=NULL) //we should inform also network client. Usefull only when network client implements this feature - ((HPOP3ACCOUNT)Which)->Client.NetClient->Stopped=TRUE; -} - -//This function is like main function for POP3 internal protocol -int RegisterPOP3Plugin(WPARAM,LPARAM) -{ - - //Get YAMN variables we can use - if (NULL==(pYAMNVar=(PYAMN_VARIABLES)CallService(MS_YAMN_GETVARIABLES,(WPARAM)YAMN_VARIABLESVERSION,(LPARAM)0))) - return 0; - - //We have to get pointers to YAMN exported functions: allocate structure and fill it - if (NULL==(pYAMNFcn=new struct YAMNExportedFcns)) - {UnLoadPOP3(0); return 0;} - - //Register new pop3 user in netlib - if (NULL==(hNetLib=RegisterNLClient("YAMN-POP3"))) - {UnLoadPOP3(0); return 0;} - - pYAMNFcn->SetProtocolPluginFcnImportFcn=(YAMN_SETPROTOCOLPLUGINFCNIMPORTFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SETPROTOCOLPLUGINFCNIMPORTID,(LPARAM)0); - pYAMNFcn->WaitToWriteFcn=(YAMN_WAITTOWRITEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_WAITTOWRITEID,(LPARAM)0); - pYAMNFcn->WriteDoneFcn=(YAMN_WRITEDONEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_WRITEDONEID,(LPARAM)0); - pYAMNFcn->WaitToReadFcn=(YAMN_WAITTOREADFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_WAITTOREADID,(LPARAM)0); - pYAMNFcn->ReadDoneFcn=(YAMN_READDONEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_READDONEID,(LPARAM)0); - pYAMNFcn->SCGetNumberFcn=(YAMN_SCMANAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SCGETNUMBERID,(LPARAM)0); - pYAMNFcn->SCIncFcn=(YAMN_SCMANAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SCINCID,(LPARAM)0); - pYAMNFcn->SCDecFcn=(YAMN_SCMANAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SCDECID,(LPARAM)0); - pYAMNFcn->SetStatusFcn=(YAMN_SETSTATUSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SETSTATUSID,(LPARAM)0); - pYAMNFcn->GetStatusFcn=(YAMN_GETSTATUSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_GETSTATUSID,(LPARAM)0); - - if (NULL==(pYAMNMailFcn=new struct MailExportedFcns)) - {UnLoadPOP3(0); return 0;} - - pYAMNMailFcn->SynchroMessagesFcn=(YAMN_SYNCHROMIMEMSGSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SYNCHROMIMEMSGSID,(LPARAM)0); - pYAMNMailFcn->TranslateHeaderFcn=(YAMN_TRANSLATEHEADERFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_TRANSLATEHEADERID,(LPARAM)0); - pYAMNMailFcn->AppendQueueFcn=(YAMN_APPENDQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_APPENDQUEUEID,(LPARAM)0); - pYAMNMailFcn->DeleteMessagesToEndFcn=(YAMN_DELETEMIMEQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_DELETEMIMEQUEUEID,(LPARAM)0); - pYAMNMailFcn->DeleteMessageFromQueueFcn=(YAMN_DELETEMIMEMESSAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_DELETEMIMEMESSAGEID,(LPARAM)0); - pYAMNMailFcn->FindMessageByIDFcn=(YAMN_FINDMIMEMESSAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_FINDMIMEMESSAGEID,(LPARAM)0); - pYAMNMailFcn->CreateNewDeleteQueueFcn=(YAMN_CREATENEWDELETEQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_CREATENEWDELETEQUEUEID,(LPARAM)0); - - //set static variable - if (CPOP3Account::AccountWriterSO==NULL) { - if (NULL==(CPOP3Account::AccountWriterSO=new SCOUNTER)) - {UnLoadPOP3(0); return 0;} - } - - //First, we register this plugin - //it is quite impossible this function returns zero (failure) as YAMN and internal plugin structre versions are the same - POP3ProtocolRegistration.Name = Translate("POP3 protocol (internal)"); - POP3ProtocolRegistration.Description = Translate("Mail notifier and browser for Miranda NG. Included POP3 protocol."); - if (NULL==(POP3Plugin=(HYAMNPROTOPLUGIN)CallService(MS_YAMN_REGISTERPROTOPLUGIN,(WPARAM)&POP3ProtocolRegistration,(LPARAM)YAMN_PROTOREGISTRATIONVERSION))) - return 0; - - //Next we set our imported functions for YAMN - if (!SetProtocolPluginFcnImport(POP3Plugin,&POP3ProtocolFunctions,YAMN_PROTOIMPORTFCNVERSION,&POP3MailFunctions,YAMN_MAILIMPORTFCNVERSION)) - return 0; - - //Then, we read all mails for accounts. - //You must first register account, before using this function as YAMN must use CreatePOP3Account function to add new accounts - //But if CreatePOP3Account is not implemented (equals to NULL), YAMN creates account as YAMN's standard HACCOUNT - if (FileName) CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName, 0); //shoud not happen (only for secure) - FileName = (TCHAR *)CallService(MS_YAMN_GETFILENAME,(WPARAM)_T("pop3"), 0); - - switch(CallService(MS_YAMN_READACCOUNTS,(WPARAM)POP3Plugin,(LPARAM)FileName)) { - case EACC_FILEVERSION: - MessageBox(NULL,TranslateT("Found new version of account book, not compatible with this version of YAMN."),TranslateT("YAMN (internal POP3) read error"),MB_OK); - CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); - FileName = NULL; - return 0; - case EACC_FILECOMPATIBILITY: - MessageBox(NULL,TranslateT("Error reading account file. Account file corrupted."),TranslateT("YAMN (internal POP3) read error"),MB_OK); - CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); - FileName = NULL; - return 0; - case EACC_ALLOC: - MessageBox(NULL,TranslateT("Memory allocation error while data reading"),TranslateT("YAMN (internal POP3) read error"),MB_OK); - CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); - FileName = NULL; - return 0; - case EACC_SYSTEM: - if (ERROR_FILE_NOT_FOUND!=GetLastError()) - { - TCHAR temp[1024] = {0}; - mir_sntprintf(temp, SIZEOF(temp), _T("%s\n%s"),TranslateT("Reading file error. File already in use?"),FileName); - MessageBox(NULL,temp,TranslateT("YAMN (internal POP3) read error"),MB_OK); - CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); - FileName = NULL; - return 0; - } - break; - } - //HookEvent(ME_OPT_INITIALISE,POP3OptInit); - - HACCOUNT Finder; - HANDLE hContact; - DBVARIANT dbv; - char *szProto; - - for (Finder=POP3Plugin->FirstAccount;Finder!=NULL;Finder=Finder->Next) - { - Finder->hContact = NULL; - hContact = db_find_first(); - while(hContact) - { - szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - if (szProto != NULL && strcmp(szProto, YAMN_DBMODULE)==0) - { - if (!DBGetContactSettingString(hContact,YAMN_DBMODULE,"Id",&dbv)) { - if ( strcmp( dbv.pszVal, Finder->Name) == 0) { - Finder->hContact = hContact; - DBWriteContactSettingWord(Finder->hContact, YAMN_DBMODULE, "Status", ID_STATUS_ONLINE); - DBWriteContactSettingString(Finder->hContact, "CList", "StatusMsg", Translate("No new mail message")); - if ((Finder->Flags & YAMN_ACC_ENA) && (Finder->NewMailN.Flags & YAMN_ACC_CONT)) - DBDeleteContactSetting(Finder->hContact, "CList", "Hidden"); - - if (!(Finder->Flags & YAMN_ACC_ENA) || !(Finder->NewMailN.Flags & YAMN_ACC_CONT)) - DBWriteContactSettingByte(Finder->hContact, "CList", "Hidden", 1); - } - DBFreeVariant(&dbv); - } - } - hContact = db_find_next(hContact); - } - - if (Finder->hContact == NULL && (Finder->Flags & YAMN_ACC_ENA) && (Finder->NewMailN.Flags & YAMN_ACC_CONT)) { - //No account contact found, have to create one - Finder->hContact =(HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0); - CallService(MS_PROTO_ADDTOCONTACT,(WPARAM)Finder->hContact,(LPARAM)YAMN_DBMODULE); - DBWriteContactSettingString(Finder->hContact,YAMN_DBMODULE,"Id",Finder->Name); - DBWriteContactSettingString(Finder->hContact,YAMN_DBMODULE,"Nick",Finder->Name); - DBWriteContactSettingString(Finder->hContact,"Protocol","p",YAMN_DBMODULE); - DBWriteContactSettingWord(Finder->hContact, YAMN_DBMODULE, "Status", YAMN_STATUS); - } - } - - return 0; -} - -DWORD WINAPI UnLoadPOP3(void *) -{ - //pYAMNVar is only a pointr, no need delete or free - if (hNetLib) { - Netlib_CloseHandle(hNetLib); hNetLib = NULL;} - if (CPOP3Account::AccountWriterSO) { - delete CPOP3Account::AccountWriterSO; CPOP3Account::AccountWriterSO = NULL;} - if (pYAMNMailFcn) { - delete pYAMNMailFcn; pYAMNMailFcn = NULL;} - if (pYAMNFcn) { - delete pYAMNFcn; pYAMNFcn = NULL;} - if (FileName) { - CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); FileName = NULL;} - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"UnLoadPOP3:done\n"); - #endif - return 1; -} - -DWORD WINAPI WritePOP3Accounts() -{ - DWORD ReturnValue = CallService(MS_YAMN_WRITEACCOUNTS,(WPARAM)POP3Plugin,(LPARAM)FileName); - if (ReturnValue == EACC_SYSTEM) { - TCHAR temp[1024] = {0}; - mir_sntprintf(temp, SIZEOF(temp), _T("%s\n%s"), TranslateT("Error while copying data to disk occured. File in use?"), FileName ); - MessageBox(NULL, temp, TranslateT("POP3 plugin- write file error"), MB_OK ); - } - - return ReturnValue; -} - -DWORD WINAPI WritePOP3Options(HANDLE File,HACCOUNT Which) -{ - DWORD WrittenBytes; - DWORD Ver=POP3_FILEVERSION; - - if ((!WriteFile(File,(char *)&Ver,sizeof(DWORD),&WrittenBytes,NULL)) || - (!WriteFile(File,(char *)&((HPOP3ACCOUNT)Which)->CP,sizeof(WORD),&WrittenBytes,NULL))) - return EACC_SYSTEM; - return 0; -} - -DWORD WINAPI ReadPOP3Options(HACCOUNT Which,char **Parser,char *End) -{ - DWORD Ver; -#ifdef DEBUG_FILEREAD - TCHAR Debug[256]; -#endif - Ver=*(DWORD *)(*Parser); - (*Parser)+=sizeof(DWORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; - if (Ver!=POP3_FILEVERSION) - return EACC_FILECOMPATIBILITY; - - ((HPOP3ACCOUNT)Which)->CP=*(WORD *)(*Parser); - (*Parser)+=sizeof(WORD); - if (*Parser>=End) - return EACC_FILECOMPATIBILITY; -#ifdef DEBUG_FILEREAD - _stprintf(Debug,_T("CodePage: %d, remaining %d chars"),((HPOP3ACCOUNT)Which)->CP,End-*Parser); - MessageBox(NULL,Debug,_T("debug"),MB_OK); -#endif - return 0; -} - -HYAMNMAIL WINAPI CreatePOP3Mail(HACCOUNT Account,DWORD MailDataVersion) -{ - HYAMNMAIL NewMail; -//First, we should check whether MAILDATA matches. -//But this is internal plugin, so YAMN's MAILDATA structure and our MAILDATA structure are -//the same, so we do not need to test version. Otherwise, if MAILDATA version does not match -//in your plugin, you should return NULL, like this: -// if (MailDataVersion!=YAMN_MAILDATAVERSION) return NULL; - -//Now it is needed to construct our POP3 account and return its handle - if (NULL==(NewMail=new YAMNMAIL)) - return NULL; - - if (NULL==(NewMail->MailData=new MAILDATA)) - { - delete NewMail; - return NULL; - } - NewMail->MailData->CP=((HPOP3ACCOUNT)Account)->CP; - return (HYAMNMAIL)NewMail; -} - -static void SetContactStatus(HACCOUNT account, int status){ - if ((account->hContact) && (account->NewMailN.Flags & YAMN_ACC_CONT)) { - DBWriteContactSettingWord(account->hContact, YAMN_DBMODULE, "Status", status); - } -} - -static void PostErrorProc(HPOP3ACCOUNT ActualAccount,void *ParamToBadConnection,DWORD POP3PluginParam,BOOL UseSSL) -{ - char *DataRX; - -//We create new structure, that we pass to bad connection dialog procedure. This procedure next calls YAMN imported fuction -//from POP3 protocol to determine the description of error. We can describe error from our error code structure, because later, -//when YAMN calls our function, it passes us our error code. This is pointer to structure for POP3 protocol in fact. - PPOP3_ERRORCODE ErrorCode; - -//We store status before we do Quit(), because quit can destroy our errorcode status - if (NULL!=(ErrorCode=new POP3_ERRORCODE)) - { - ErrorCode->SSL=UseSSL; - ErrorCode->AppError=ActualAccount->SystemError; - ErrorCode->POP3Error=ActualAccount->Client.POP3Error; - ErrorCode->NetError=ActualAccount->Client.NetClient->NetworkError; - ErrorCode->SystemError=ActualAccount->Client.NetClient->SystemError; - } - - if (POP3PluginParam==(DWORD)NULL) //if it was normal YAMN call (force check or so on) - { - try - { - DataRX=ActualAccount->Client.Quit(); - if (DataRX!=NULL) - free(DataRX); - } - catch(...) - { - } -//We always close connection if error occured - try - { - ActualAccount->Client.NetClient->Disconnect(); - } - catch(...) - { - } - - SetAccountStatus(ActualAccount,TranslateT("Disconnected")); - -//If we cannot allocate memory, do nothing - if (ErrorCode==NULL) - { - SetEvent(ActualAccount->UseInternetFree); - return; - } - } - else //else it was called from POP3 plugin, probably error when deleting old mail (POP3 synchro calls POP3 delete) - if (ErrorCode==NULL) - return; - - if ((ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG) || (ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO) || (ActualAccount->BadConnectN.Flags & YAMN_ACC_POP)) - { - YAMN_BADCONNECTIONPARAM cp={(HANDLE)0,ActualAccount,(UINT_PTR)ErrorCode,ParamToBadConnection}; - - CallService(MS_YAMN_BADCONNECTION,(WPARAM)&cp,(LPARAM)YAMN_BADCONNECTIONVERSION); - } - if (POP3PluginParam==(DWORD)NULL) //if it was normal YAMN call - SetEvent(ActualAccount->UseInternetFree); -} - -//Checks POP3 account and synchronizes it -DWORD WINAPI SynchroPOP3(struct CheckParam * WhichTemp) -{ - HPOP3ACCOUNT ActualAccount; - CPop3Client *MyClient; - HYAMNMAIL NewMails=NULL,MsgQueuePtr=NULL; - char* DataRX=NULL,*Temp; - int mboxsize,msgs,i; - SYSTEMTIME now; - LPVOID YAMNParam; - DWORD CheckFlags; - BOOL UsingInternet=FALSE; - struct { - char *ServerName; - DWORD ServerPort; - char *ServerLogin; - char *ServerPasswd; - DWORD Flags; - DWORD NFlags; - DWORD NNFlags; - } ActualCopied; - - //First, we should compare our version of CheckParam structure, but here it is not needed, because YAMN and internal plugin - //have the same version. But your plugin should do that in this way: - // if (((struct CheckParam *)WhichTemp)->Ver!=YAMN_CHECKVERSION) - // { - // SetEvent(((struct CheckParam *)WhichTemp)->ThreadRunningEV); //don't forget to unblock YAMN - // return (DWORD)-1; //ok, but we should return value. - // //When our plugin returns e.g. 0xFFFFFFFF (=-1, this is only our plugin value, YAMN does nothing with return value, - // //but only tests if it is nonzero. If yes, it calls GetErrorStringFcn. We know problem occured in YAMN incompatibility - // //and then we can in our GetErrorStringFcn e.g. return string "Uncompatible version of YAMN". - // } - - ActualAccount=(HPOP3ACCOUNT)WhichTemp->AccountParam; //copy address of structure from calling thread to stack of this thread - YAMNParam=WhichTemp->BrowserParam; - CheckFlags=WhichTemp->Flags; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:Incrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); - #endif - SCInc(ActualAccount->UsingThreads); - //Unblock YAMN, signal that we have copied all parameters from YAMN thread stack - if (INVALID_HANDLE_VALUE!=WhichTemp->ThreadRunningEV) - SetEvent(WhichTemp->ThreadRunningEV); - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0!=WaitToRead(ActualAccount)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountSO-read wait failed\n"); - #endif - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); - #endif - SCDec(ActualAccount->UsingThreads); - return 0; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountSO-read enter\n"); - #endif - 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. - ActualCopied.ServerName = _strdup(ActualAccount->Server->Name); - ActualCopied.ServerPort=ActualAccount->Server->Port; - ActualCopied.Flags=ActualAccount->Flags; - ActualCopied.ServerLogin=_strdup(ActualAccount->Server->Login); - ActualCopied.ServerPasswd=_strdup(ActualAccount->Server->Passwd); - ActualCopied.NFlags=ActualAccount->NewMailN.Flags; - ActualCopied.NNFlags=ActualAccount->NoNewMailN.Flags; - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountSO-read done\n"); - #endif - ReadDone(ActualAccount); - - SCInc(ActualAccount->InternetQueries); //increment counter, that there is one more thread waiting for connection - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-wait\n"); - #endif - WaitForSingleObject(ActualAccount->UseInternetFree,INFINITE); //wait until we can use connection - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-enter\n"); - #endif - SCDec(ActualAccount->InternetQueries); - - //OK, we enter the "use internet" section. But after we start communication, we can test if we did not enter the "use internet" section only for the reason, - //that previous thread release the internet section because this account has stop signal (we stop account and there are 2 threads: one communicating, - //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) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:stop signal-InternetFreeEV-done\n"); - #endif - SetEvent(ActualAccount->UseInternetFree); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:stop signal-Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); - #endif - SCDec(ActualAccount->UsingThreads); - return 0; - } - UsingInternet=TRUE; - - GetLocalTime(&now); - ActualAccount->SystemError=0; //now we can use internet for this socket. First, clear errorcode. - try - { - SetContactStatus(ActualAccount,ID_STATUS_OCCUPIED); - #ifdef DEBUG_COMM - DebugLog(CommFile,"<--------Communication-------->\n"); - #endif - // if we are already connected, we have open session (another thread left us open session), so we don't need to login - // note that connected state without logging cannot occur, because if we close session, we always close socket too (we must close socket is the right word :)) - if ((MyClient->NetClient==NULL) || !MyClient->NetClient->Connected()) - { - SetAccountStatus(ActualAccount,TranslateT("Connecting to server")); - - DataRX=MyClient->Connect(ActualCopied.ServerName,ActualCopied.ServerPort,ActualCopied.Flags & YAMN_ACC_SSL23,ActualCopied.Flags & YAMN_ACC_NOTLS); - char *timestamp=NULL; - - if (DataRX!=NULL) - { - if (ActualCopied.Flags & YAMN_ACC_APOP) - { - char *lpos=strchr(DataRX,'<'); - char *rpos=strchr(DataRX,'>'); - if (lpos && rpos && rpos>lpos) { - int sz=(int)(rpos-lpos+2); - timestamp=new char[sz]; - memcpy(timestamp, lpos, sz-1); - timestamp[sz-1]='\0'; - } - } - free(DataRX); - DataRX=NULL; - } - - SetAccountStatus(ActualAccount,TranslateT("Entering POP3 account")); - - if (ActualCopied.Flags & YAMN_ACC_APOP) - { - DataRX=MyClient->APOP(ActualCopied.ServerLogin,ActualCopied.ServerPasswd,timestamp); - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - delete[] timestamp; - } else { - DataRX=MyClient->User(ActualCopied.ServerLogin); - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - DataRX=MyClient->Pass(ActualCopied.ServerPasswd); - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - } - } - SetAccountStatus(ActualAccount,TranslateT("Searching for new mail message")); - - DataRX=MyClient->Stat(); - - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"<--------Account checking-------->\n"); - DebugLog(DecodeFile,"\n"); - #endif - ExtractStat(DataRX,MyClient->NetClient->Rcv,&mboxsize,&msgs); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%d\n",mboxsize); - DebugLog(DecodeFile,"%d\n",msgs); - DebugLog(DecodeFile,"\n"); - #endif - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - for (i=0;iNext=(HYAMNMAIL)CallService(MS_YAMN_CREATEACCOUNTMAIL,(WPARAM)ActualAccount,(LPARAM)YAMN_MAILVERSION); - MsgQueuePtr=MsgQueuePtr->Next; - } - if (MsgQueuePtr==NULL) - { - ActualAccount->SystemError=EPOP3_QUEUEALLOC; - throw (DWORD)ActualAccount->SystemError; - } - } - - if (msgs) - { - DataRX=MyClient->List(); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - ExtractList(DataRX,MyClient->NetClient->Rcv,NewMails); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - DataRX=MyClient->Uidl(); - ExtractUIDL(DataRX,MyClient->NetClient->Rcv,NewMails); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait\n"); - #endif - if (WAIT_OBJECT_0!=MsgsWaitToWrite(ActualAccount)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait failed\n"); - #endif - throw (DWORD)(ActualAccount->SystemError=EACC_STOPPED); - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write enter\n"); - #endif - ActualAccount->LastChecked=now; - for (MsgQueuePtr=(HYAMNMAIL)ActualAccount->Mails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next){ - if (MsgQueuePtr->Flags&YAMN_MSG_BODYREQUESTED){ - HYAMNMAIL NewMsgsPtr=NULL; - for (NewMsgsPtr=(HYAMNMAIL)NewMails;NewMsgsPtr!=NULL;NewMsgsPtr=NewMsgsPtr->Next){ - if (!strcmp(MsgQueuePtr->ID,NewMsgsPtr->ID)) { - TCHAR accstatus[512]; - wsprintf(accstatus,TranslateT("Reading body %s"),NewMsgsPtr->ID); - SetAccountStatus(ActualAccount,accstatus); - DataRX=MyClient->Top(MsgQueuePtr->Number,100); - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - DebugLog(DecodeFile,"
%s
\n",DataRX); - #endif - if (DataRX!=NULL) - { - Temp=DataRX; - while((TempNetClient->Rcv) && (WS(Temp) || ENDLINE(Temp))) Temp++; - - if (OKLINE(DataRX)) - for (Temp=DataRX;(TempNetClient->Rcv) && (!ENDLINE(Temp));Temp++); - while((TempNetClient->Rcv) && ENDLINE(Temp)) Temp++; - } - else - continue; - //delete all the headers of the old mail MsgQueuePtr->MailData->TranslatedHeader - struct CMimeItem *TH = MsgQueuePtr->MailData->TranslatedHeader; - if (TH) for (;MsgQueuePtr->MailData->TranslatedHeader!=NULL;) - { - TH=TH->Next; - if (MsgQueuePtr->MailData->TranslatedHeader->name!=NULL) - delete[] MsgQueuePtr->MailData->TranslatedHeader->name; - if (MsgQueuePtr->MailData->TranslatedHeader->value!=NULL) - delete[] MsgQueuePtr->MailData->TranslatedHeader->value; - delete MsgQueuePtr->MailData->TranslatedHeader; - MsgQueuePtr->MailData->TranslatedHeader=TH; - } - - TranslateHeader(Temp,MyClient->NetClient->Rcv-(Temp-DataRX),&MsgQueuePtr->MailData->TranslatedHeader); - - - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"
\n"); - #endif - MsgQueuePtr->Flags|=YAMN_MSG_BODYRECEIVED; - - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - break; - } - } - } - } - - SynchroMessages(ActualAccount,(HYAMNMAIL *)&ActualAccount->Mails,NULL,(HYAMNMAIL *)&NewMails,NULL); //we get only new mails on server! -// NewMails=NULL; - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write done\n"); - #endif - MsgsWriteDone(ActualAccount); - for (MsgQueuePtr=(HYAMNMAIL)ActualAccount->Mails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next){ - if ((MsgQueuePtr->Flags&YAMN_MSG_BODYREQUESTED) && (MsgQueuePtr->Flags&YAMN_MSG_BODYRECEIVED)) { - MsgQueuePtr->Flags&=~YAMN_MSG_BODYREQUESTED; - if (MsgQueuePtr->MsgWindow){ - SendMessage(MsgQueuePtr->MsgWindow,WM_YAMN_CHANGECONTENT,0,0); - } - } - } - - for (msgs=0,MsgQueuePtr=NewMails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next,msgs++); //get number of new mails - - try - { - TCHAR accstatus[512]; - - for (i=0,MsgQueuePtr=NewMails;MsgQueuePtr!=NULL;i++) - { - BOOL autoretr = (ActualAccount->Flags & YAMN_ACC_BODY)!=0; - DataRX=MyClient->Top(MsgQueuePtr->Number,autoretr?100:0); - wsprintf(accstatus,TranslateT("Reading new mail messages (%d%% done)"),100*i/msgs); - SetAccountStatus(ActualAccount,accstatus); - - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - DebugLog(DecodeFile,"
%s
\n",DataRX); - #endif - if (DataRX!=NULL) - { - Temp=DataRX; - while((TempNetClient->Rcv) && (WS(Temp) || ENDLINE(Temp))) Temp++; - - if (OKLINE(DataRX)) - for (Temp=DataRX;(TempNetClient->Rcv) && (!ENDLINE(Temp));Temp++); - while((TempNetClient->Rcv) && ENDLINE(Temp)) Temp++; - } - else - continue; - - TranslateHeader(Temp,MyClient->NetClient->Rcv-(Temp-DataRX),&MsgQueuePtr->MailData->TranslatedHeader); - - - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"
\n"); - #endif - MsgQueuePtr->Flags|=YAMN_MSG_NORMALNEW; - if (autoretr) MsgQueuePtr->Flags|=YAMN_MSG_BODYRECEIVED; - - //We are going to filter mail. Warning!- we must not be in read access neither write access to mails when calling this service - //This is done, because the "NewMails" queue is not synchronised. It is because it is new queue. Only this thread uses new queue yet, it is not - //connected to account mail queue. - // CallService(MS_YAMN_FILTERMAIL,(WPARAM)ActualAccount,(LPARAM)MsgQueuePtr); - FilterMailSvc((WPARAM)ActualAccount,(LPARAM)MsgQueuePtr); - - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - - //MsgQueuePtr->MailData->Body=MyClient->Retr(MsgQueuePtr->Number); - - MsgQueuePtr=MsgQueuePtr->Next; - - } - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait\n"); - #endif - if (WAIT_OBJECT_0!=MsgsWaitToWrite(ActualAccount)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait failed\n"); - #endif - throw (DWORD)ActualAccount->SystemError==EACC_STOPPED; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write enter\n"); - #endif - if (ActualAccount->Mails==NULL) - ActualAccount->Mails=NewMails; - else - { - ActualAccount->LastMail=ActualAccount->LastChecked; - AppendQueue((HYAMNMAIL)ActualAccount->Mails,NewMails); - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write done\n"); - #endif - MsgsWriteDone(ActualAccount); - - // 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,YAMNParam,(void *)POP3_DELETEFROMCHECK}; - - // Delete mails from server. Here we should not be in write access for account's mails - DeleteMailsPOP3(&ParamToDeleteMails); - } - - // if there is no waiting thread for internet connection close it - // else leave connection open - if (0==SCGetNumber(ActualAccount->InternetQueries)) - { - DataRX=MyClient->Quit(); - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - MyClient->NetClient->Disconnect(); - - SetAccountStatus(ActualAccount,TranslateT("Disconnected")); - } - - UsingInternet=FALSE; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-done\n"); - #endif - SetEvent(ActualAccount->UseInternetFree); - - ActualAccount->LastSChecked=ActualAccount->LastChecked; - ActualAccount->LastSynchronised=ActualAccount->LastChecked; - } - catch(...) - { - throw; //go to the main exception handling - } - - { - YAMN_MAILBROWSERPARAM Param={(HANDLE)0,ActualAccount,ActualCopied.NFlags,ActualCopied.NNFlags,YAMNParam}; - - 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 - CallService(MS_YAMN_MAILBROWSER,(WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); - } - SetContactStatus(ActualAccount,ActualAccount->isCounting?ID_STATUS_ONLINE:ID_STATUS_OFFLINE); - } - #ifdef DEBUG_COMM - catch(DWORD ErrorCode) - #else - catch(DWORD) - #endif - { - if (ActualAccount->Client.POP3Error==EPOP3_STOPPED) - ActualAccount->SystemError=EACC_STOPPED; - #ifdef DEBUG_COMM - DebugLog(CommFile,"ERROR: %x\n",ErrorCode); - #endif - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait\n"); - #endif - if (WAIT_OBJECT_0==MsgsWaitToWrite(ActualAccount)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write enter\n"); - #endif - ActualAccount->LastChecked=now; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write done\n"); - #endif - MsgsWriteDone(ActualAccount); - } - #ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait failed\n"); - #endif - - DeleteMIMEQueue(ActualAccount,NewMails); - - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - switch(ActualAccount->SystemError) - { - case EACC_QUEUEALLOC: - case EACC_STOPPED: - ActualAccount->Client.NetClient->Disconnect(); - break; - default: - PostErrorProc(ActualAccount,YAMNParam,(DWORD)NULL,MyClient->SSL); //it closes internet connection too - } - - if (UsingInternet) //if our thread still uses internet - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-done\n"); - #endif - SetEvent(ActualAccount->UseInternetFree); - } - SetContactStatus(ActualAccount,ID_STATUS_NA); - } - free(ActualCopied.ServerName); - free(ActualCopied.ServerLogin); - free(ActualCopied.ServerPasswd); - #ifdef DEBUG_COMM - DebugLog(CommFile,"\n"); - #endif -// WriteAccounts(); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); - #endif - SCDec(ActualAccount->UsingThreads); - return 0; -} - -DWORD WINAPI DeleteMailsPOP3(struct DeleteParam *WhichTemp) -{ - HPOP3ACCOUNT ActualAccount; - LPVOID YAMNParam; - UINT_PTR POP3PluginParam; - CPop3Client *MyClient; - HYAMNMAIL DeleteMails,NewMails=NULL,MsgQueuePtr; - char* DataRX=NULL; - int mboxsize,msgs,i; - BOOL UsingInternet=FALSE; - struct { - char *ServerName; - DWORD ServerPort; - char *ServerLogin; - char *ServerPasswd; - DWORD Flags; - DWORD NFlags; - DWORD NNFlags; - } ActualCopied; - - //First, we should compare our version of DeleteParam structure, but here it is not needed, because YAMN and internal plugin - //have the same version. But your plugin should do that in this way: - // if (((struct DeleteParam *)WhichTemp)->Ver!=YAMN_DELETEVERSION) - // { - // SetEvent(((struct DeleteParam *)WhichTemp)->ThreadRunningEV); //don't forget to unblock YAMN - // return (DWORD)-1; //ok, but we should return value. - // //When our plugin returns e.g. 0xFFFFFFFF (this is only our plugin value, YAMN does nothing with return value, - // //but only tests if it is nonzero. If yes, it calls GetErrorStringFcn), we know problem occured in YAMN incompatibility - // //and then we can in our GetErrorStringFcn e.g. return string "Uncompatible version of YAMN". - // } - - ActualAccount=(HPOP3ACCOUNT)((struct DeleteParam *)WhichTemp)->AccountParam; //copy address of structure from calling thread to stack of this thread - YAMNParam=((struct DeleteParam *)WhichTemp)->BrowserParam; - POP3PluginParam=(UINT_PTR)((struct DeleteParam *)WhichTemp)->CustomParam; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:Incrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); -#endif - SCInc(ActualAccount->UsingThreads); - if (INVALID_HANDLE_VALUE!=WhichTemp->ThreadRunningEV) - SetEvent(WhichTemp->ThreadRunningEV); - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read wait\n"); -#endif - if (WAIT_OBJECT_0!=WaitToRead(ActualAccount)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read wait failed\n"); -#endif -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); -#endif - SCDec(ActualAccount->UsingThreads); - return 0; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read enter\n"); -#endif - if (NULL==(DeleteMails=(HYAMNMAIL)CreateNewDeleteQueue((HYAMNMAIL)ActualAccount->Mails))) //if there's no mail for deleting, return - { - if (POP3_DELETEFROMCHECK!=POP3PluginParam) //We do not wait for free internet when calling from SynchroPOP3. It is because UseInternetFree is blocked - { - YAMN_MAILBROWSERPARAM Param={(HANDLE)0,ActualAccount,YAMN_ACC_MSGP,YAMN_ACC_MSGP,YAMNParam}; //Just update the window - - CallService(MS_YAMN_MAILBROWSER,(WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read done\n"); -#endif - ReadDone(ActualAccount); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); -#endif - SCDec(ActualAccount->UsingThreads); - - return NO_MAIL_FOR_DELETE; - } - 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. - ActualCopied.ServerName=_strdup(ActualAccount->Server->Name); - ActualCopied.ServerPort=ActualAccount->Server->Port; - ActualCopied.Flags=ActualAccount->Flags; - ActualCopied.ServerLogin=_strdup(ActualAccount->Server->Login); - ActualCopied.ServerPasswd=_strdup(ActualAccount->Server->Passwd); - ActualCopied.NFlags=ActualAccount->NewMailN.Flags; - ActualCopied.NNFlags=ActualAccount->NoNewMailN.Flags; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read done\n"); -#endif - ReadDone(ActualAccount); - - SCInc(ActualAccount->InternetQueries); //This is POP3-internal SCOUNTER, we set another thread wait for this account to be connected to inet - if (POP3_DELETEFROMCHECK!=POP3PluginParam) //We do not wait for free internet when calling from SynchroPOP3. It is because UseInternetFree is blocked - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:InternetFreeEV-wait\n"); -#endif - WaitForSingleObject(ActualAccount->UseInternetFree,INFINITE); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:InternetFreeEV-enter\n"); -#endif - } - SCDec(ActualAccount->InternetQueries); - UsingInternet=TRUE; - - try - { - SetContactStatus(ActualAccount,ID_STATUS_OCCUPIED); -#ifdef DEBUG_COMM - DebugLog(CommFile,"<--------Communication-------->\n"); -#endif - if ((MyClient->NetClient==NULL) || !MyClient->NetClient->Connected()) - { - SetAccountStatus(ActualAccount,TranslateT("Connecting to server")); - - DataRX=MyClient->Connect(ActualCopied.ServerName,ActualCopied.ServerPort,ActualCopied.Flags & YAMN_ACC_SSL23,ActualCopied.Flags & YAMN_ACC_NOTLS); - - char *timestamp=NULL; - if (DataRX!=NULL) { - if (ActualAccount->Flags & YAMN_ACC_APOP) { - char *lpos=strchr(DataRX,'<'); - char *rpos=strchr(DataRX,'>'); - if (lpos && rpos && rpos>lpos) { - int sz=(int)(rpos-lpos+2); - timestamp=new char[sz]; - memcpy(timestamp, lpos, sz-1); - timestamp[sz-1]='\0'; - } - } - free(DataRX); - DataRX=NULL; - } - SetAccountStatus(ActualAccount,TranslateT("Entering POP3 account")); - - if (ActualAccount->Flags & YAMN_ACC_APOP) - { - DataRX=MyClient->APOP(ActualCopied.ServerLogin,ActualCopied.ServerPasswd,timestamp); - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - delete[] timestamp; - } else { - DataRX=MyClient->User(ActualCopied.ServerLogin); - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - DataRX=MyClient->Pass(ActualCopied.ServerPasswd); - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - } - } - -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"<--------Deleting requested mails-------->\n"); -#endif - if (POP3_DELETEFROMCHECK!=POP3PluginParam) //We do not need to get mails on server as we have already it from check function - { - SetAccountStatus(ActualAccount,TranslateT("Deleting requested mails")); - - DataRX=MyClient->Stat(); - -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); -#endif - ExtractStat(DataRX,MyClient->NetClient->Rcv,&mboxsize,&msgs); -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%d\n",mboxsize); - DebugLog(DecodeFile,"%d\n",msgs); - DebugLog(DecodeFile,"\n"); -#endif - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - for (i=0;iNext=(HYAMNMAIL)CallService(MS_YAMN_CREATEACCOUNTMAIL,(WPARAM)ActualAccount,(LPARAM)YAMN_MAILVERSION); - MsgQueuePtr=MsgQueuePtr->Next; - } - if (MsgQueuePtr==NULL) - { - ActualAccount->SystemError=EPOP3_QUEUEALLOC; - throw (DWORD)ActualAccount->SystemError; - } - } - - if (msgs) - { -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); -#endif - DataRX=MyClient->Uidl(); - ExtractUIDL(DataRX,MyClient->NetClient->Rcv,NewMails); -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); -#endif - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; -// we get "new mails" on server (NewMails will contain all mails on server not found in DeleteMails) -// but also in DeleteMails we get only those, which are still on server with their responsable numbers - SynchroMessages(ActualAccount,(HYAMNMAIL *)&DeleteMails,NULL,(HYAMNMAIL *)&NewMails,NULL); - } - } - else - SetAccountStatus(ActualAccount,TranslateT("Deleting spam")); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write wait\n"); -#endif - if (WAIT_OBJECT_0!=MsgsWaitToWrite(ActualAccount)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write wait failed\n"); -#endif - throw (DWORD)EACC_STOPPED; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write enter\n"); -#endif - if (msgs || POP3_DELETEFROMCHECK==POP3PluginParam) - { - try - { - HYAMNMAIL Temp; - - for (i=0,MsgQueuePtr=DeleteMails;MsgQueuePtr!=NULL;i++) - { - if (!(MsgQueuePtr->Flags & YAMN_MSG_VIRTUAL)) //of course we can only delete real mails, not virtual - { - DataRX=MyClient->Dele(MsgQueuePtr->Number); - Temp=MsgQueuePtr->Next; - if (POP3_FOK==MyClient->AckFlag) //if server answers that mail was deleted - { - DeleteMIMEMessage((HYAMNMAIL *)&DeleteMails,MsgQueuePtr); - HYAMNMAIL DeletedMail=FindMIMEMessageByID((HYAMNMAIL)ActualAccount->Mails,MsgQueuePtr->ID); - if ((MsgQueuePtr->Flags & YAMN_MSG_MEMDELETE)) //if mail should be deleted from memory (or disk) - { - DeleteMIMEMessage((HYAMNMAIL *)&ActualAccount->Mails,DeletedMail); //remove from queue - CallService(MS_YAMN_DELETEACCOUNTMAIL,(WPARAM)POP3Plugin,(LPARAM)DeletedMail); - } - else //else mark it only as "deleted mail" - { - DeletedMail->Flags |= (YAMN_MSG_VIRTUAL | YAMN_MSG_DELETED); - DeletedMail->Flags &= ~(YAMN_MSG_NEW | YAMN_MSG_USERDELETE | YAMN_MSG_AUTODELETE); //clear "new mail" - } - delete MsgQueuePtr->MailData; - delete[] MsgQueuePtr->ID; - delete MsgQueuePtr; - } - MsgQueuePtr=Temp; - - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - } - else - MsgQueuePtr=MsgQueuePtr->Next; - } - } - catch(...) //if any exception in the code where we have write-access to account occured, don't forget to leave write-access - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write done\n"); -#endif - MsgsWriteDone(ActualAccount); - throw; //and go to the main exception handling - } - - if (NewMails!=NULL) -// in ActualAccount->Mails we have all mails stored before calling this function -// in NewMails we have all mails not found in DeleteMails (in other words: we performed new ID checking and we -// stored all mails found on server, then we deleted the ones we wanted to delete in this function -// and NewMails queue now contains actual state of mails on server). But we will not use NewMails as actual state, because NewMails does not contain header data (subject, from...) -// We perform deleting from ActualAccount->Mails: we remove from original queue (ActualAccount->Mails) all deleted mails - SynchroMessages(ActualAccount,(HYAMNMAIL *)&ActualAccount->Mails,NULL,(HYAMNMAIL *)&NewMails,NULL); -// Now ActualAccount->Mails contains all mails when calling this function except the ones, we wanted to delete (these are in DeleteMails) -// And in NewMails we have new mails (if any) - else if (POP3_DELETEFROMCHECK!=POP3PluginParam) - { - DeleteMIMEQueue(ActualAccount,(HYAMNMAIL)ActualAccount->Mails); - ActualAccount->Mails=NULL; - } - } - else - { - DeleteMIMEQueue(ActualAccount,(HYAMNMAIL)ActualAccount->Mails); - ActualAccount->Mails=NULL; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write done\n"); -#endif - MsgsWriteDone(ActualAccount); -#ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); -#endif - -// TODO: now, we have in NewMails new mails. If NewMails is not NULL, we found some new mails, so Checking for new mail should be performed -// now, we do not call CheckPOP3 - -// if there is no waiting thread for internet connection close it -// else leave connection open -// if this functin was called from SynchroPOP3, then do not try to disconnect - if (POP3_DELETEFROMCHECK!=POP3PluginParam) - { - YAMN_MAILBROWSERPARAM Param={(HANDLE)0,ActualAccount,ActualCopied.NFlags,YAMN_ACC_MSGP,YAMNParam}; - - CallService(MS_YAMN_MAILBROWSER,(WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); - - if (0==SCGetNumber(ActualAccount->InternetQueries)) - { - DataRX=MyClient->Quit(); - if (DataRX!=NULL) - free(DataRX); - DataRX=NULL; - MyClient->NetClient->Disconnect(); - - SetAccountStatus(ActualAccount,TranslateT("Disconnected")); - } - - UsingInternet=FALSE; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:InternetFreeEV-done\n"); -#endif - SetEvent(ActualAccount->UseInternetFree); - } - SetContactStatus(ActualAccount,ActualAccount->isCounting?ID_STATUS_ONLINE:ID_STATUS_OFFLINE); - } -#ifdef DEBUG_COMM - catch(DWORD ErrorCode) -#else - catch(DWORD) -#endif - { - if (ActualAccount->Client.POP3Error==EPOP3_STOPPED) - ActualAccount->SystemError=EACC_STOPPED; -#ifdef DEBUG_COMM - DebugLog(CommFile,"ERROR %x\n",ErrorCode); -#endif - if (DataRX!=NULL) - free(DataRX); - switch(ActualAccount->SystemError) - { - case EACC_QUEUEALLOC: - case EACC_STOPPED: - ActualAccount->Client.NetClient->Disconnect(); - break; - default: - PostErrorProc(ActualAccount,YAMNParam,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 - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-done\n"); -#endif - SetEvent(ActualAccount->UseInternetFree); - } - } - - free(ActualCopied.ServerName); - free(ActualCopied.ServerLogin); - free(ActualCopied.ServerPasswd); - - DeleteMIMEQueue(ActualAccount,NewMails); - DeleteMIMEQueue(ActualAccount,DeleteMails); - -#ifdef DEBUG_COMM - DebugLog(CommFile,"\n"); -#endif -// WriteAccounts(); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"DeleteMailsPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); -#endif - SCDec(ActualAccount->UsingThreads); - return 0; -} - -void ExtractStat(char *stream,int len,int *mboxsize,int *mails) -{ - char *finder=stream; - while(WS(finder) || ENDLINE(finder)) finder++; - if (ACKLINE(finder)) - { - while(!WS(finder)) finder++; - while(WS(finder)) finder++; - } - if (1!=sscanf(finder,"%d",mails)) - throw (DWORD)EPOP3_STAT; - while(!WS(finder)) finder++; - while(WS(finder)) finder++; - if (1!=sscanf(finder,"%d",mboxsize)) - throw (DWORD)EPOP3_STAT; -} -void ExtractMail(char *stream,int len,HYAMNMAIL queue) -{ - char *finder=stream; - char *finderend; - int msgnr,i; - HYAMNMAIL queueptr=queue; - - while(WS(finder) || ENDLINE(finder)) finder++; - while(!ACKLINE(finder)) finder++; - while(!ENDLINE(finder)) finder++; //now we at the end of first ack line - while(finder<=(stream+len)) - { - while(ENDLINE(finder)) finder++; //go to the new line - if (DOTLINE(finder+1)) //at the end of stream - break; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - while(WS(finder)) finder++; //jump whitespace - if (1!=sscanf(finder,"%d",&msgnr)) - throw (DWORD)EPOP3_UIDL; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%d\n",msgnr); - #endif -// for (i=1,queueptr=queue;(queueptr->Next!=NULL) && (iNext,i++); -// if (i!=msgnr) -// throw (DWORD)EPOP3_UIDL; - while(!WS(finder)) finder++; //jump characters - while(WS(finder)) finder++; //jump whitespace - finderend=finder+1; - while(!WS(finderend) && !ENDLINE(finderend)) finderend++; - queueptr->ID=new char[finderend-finder+1]; - for (i=0;finder!=finderend;finder++,i++) - queueptr->MailData->Body[i]=*finder; - queueptr->MailData->Body[i]=0; //ends string - queueptr->Number=msgnr; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%s\n",queueptr->MailData->Body); - DebugLog(DecodeFile,"\n"); - #endif - queueptr=queueptr->Next; - while(!ENDLINE(finder)) finder++; - } -} - -void ExtractUIDL(char *stream,int len,HYAMNMAIL queue) -{ - char *finder=stream; - char *finderend; - int msgnr,i; - HYAMNMAIL queueptr=queue; - - while(WS(finder) || ENDLINE(finder)) finder++; - while(!ACKLINE(finder)) finder++; - while(!ENDLINE(finder)) finder++; //now we at the end of first ack line - while(finder<=(stream+len)) - { - while(ENDLINE(finder)) finder++; //go to the new line - if (DOTLINE(finder+1)) //at the end of stream - break; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n"); - #endif - while(WS(finder)) finder++; //jump whitespace - if (1!=sscanf(finder,"%d",&msgnr)) - throw (DWORD)EPOP3_UIDL; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%d\n",msgnr); - #endif -// for (i=1,queueptr=queue;(queueptr->Next!=NULL) && (iNext,i++); -// if (i!=msgnr) -// throw (DWORD)EPOP3_UIDL; - while(!WS(finder)) finder++; //jump characters - while(WS(finder)) finder++; //jump whitespace - finderend=finder+1; - while(!WS(finderend) && !ENDLINE(finderend)) finderend++; - queueptr->ID=new char[finderend-finder+1]; - for (i=0;finder!=finderend;finder++,i++) - queueptr->ID[i]=*finder; - queueptr->ID[i]=0; //ends string - queueptr->Number=msgnr; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%s\n",queueptr->ID); - DebugLog(DecodeFile,"\n"); - #endif - queueptr=queueptr->Next; - while(!ENDLINE(finder)) finder++; - } -} - -void ExtractList(char *stream,int len,HYAMNMAIL queue) -{ - char *finder=stream; - char *finderend; - int msgnr,i; - HYAMNMAIL queueptr; - - while(WS(finder) || ENDLINE(finder)) finder++; - while(!ACKLINE(finder)) finder++; - while(!ENDLINE(finder)) finder++; //now we at the end of first ack line - while(finder<=(stream+len)) - { - while(ENDLINE(finder)) finder++; //go to the new line - if (DOTLINE(finder+1)) //at the end of stream - break; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"\n",NULL,0); - #endif - while(WS(finder)) finder++; //jump whitespace - if (1!=sscanf(finder,"%d",&msgnr)) //message nr. - throw (DWORD)EPOP3_LIST; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%d\n",msgnr); - #endif - - for (i=1,queueptr=queue;(queueptr->Next!=NULL) && (iNext,i++); - if (i!=msgnr) - throw (DWORD)EPOP3_LIST; - while(!WS(finder)) finder++; //jump characters - while(WS(finder)) finder++; //jump whitespace - finderend=finder+1; - if (1!=sscanf(finder,"%d",&queueptr->MailData->Size)) - throw (DWORD)EPOP3_LIST; - #ifdef DEBUG_DECODE - DebugLog(DecodeFile,"%d\n",queueptr->MailData->Size); - #endif - while(!ENDLINE(finder)) finder++; - } -} - -TCHAR* WINAPI GetErrorString(DWORD Code) -{ - static TCHAR *POP3Errors[]= - { - LPGENT("Memory allocation error."), //memory allocation - LPGENT("Account is about to be stopped."), //stop account - LPGENT("Cannot connect to POP3 server."), - LPGENT("Cannot allocate memory for received data."), - LPGENT("Cannot login to POP3 server."), - LPGENT("Bad user or password."), - LPGENT("Server does not support APOP authorization."), - LPGENT("Error while executing POP3 command."), - LPGENT("Error while executing POP3 command."), - LPGENT("Error while executing POP3 command."), - }; - - static TCHAR *NetlibErrors[]= - { - LPGENT("Cannot connect to server with NetLib."), - LPGENT("Cannot send data."), - LPGENT("Cannot receive data."), - LPGENT("Cannot allocate memory for received data."), - }; - - static TCHAR *SSLErrors[]= - { - LPGENT("OpenSSL not loaded."), - LPGENT("Windows socket 2.0 init failed."), - LPGENT("DNS lookup error."), - LPGENT("Error while creating base socket."), - LPGENT("Error connecting to server with socket."), - LPGENT("Error while creating SSL structure."), - LPGENT("Error connecting socket with SSL."), - LPGENT("Server rejected connection with SSL."), - LPGENT("Cannot write SSL data."), - LPGENT("Cannot read SSL data."), - LPGENT("Cannot allocate memory for received data."), - }; - - TCHAR *ErrorString = new TCHAR[ERRORSTR_MAXLEN]; - POP3_ERRORCODE *ErrorCode=(POP3_ERRORCODE *)(UINT_PTR)Code; - - mir_sntprintf(ErrorString, ERRORSTR_MAXLEN, TranslateT("Error %d-%d-%d-%d:"),ErrorCode->AppError,ErrorCode->POP3Error,ErrorCode->NetError,ErrorCode->SystemError); - if (ErrorCode->POP3Error) - mir_sntprintf(ErrorString, ERRORSTR_MAXLEN, _T("%s\n%s"),ErrorString,TranslateTS(POP3Errors[ErrorCode->POP3Error-1])); - if (ErrorCode->NetError) { - if (ErrorCode->SSL) - mir_sntprintf(ErrorString, ERRORSTR_MAXLEN, _T("%s\n%s"),ErrorString, TranslateTS(SSLErrors[ErrorCode->NetError-1])); - else - mir_sntprintf(ErrorString, ERRORSTR_MAXLEN, _T("%s\n%s"),ErrorString, TranslateTS(NetlibErrors[ErrorCode->NetError-4])); - } - - return ErrorString; -} - -void WINAPI DeleteErrorString(LPVOID String) -{ - delete (char *)String; -} diff --git a/protocols/YAMN/proto/pop3/pop3comm.h b/protocols/YAMN/proto/pop3/pop3comm.h deleted file mode 100644 index c7eb01b5a1..0000000000 --- a/protocols/YAMN/proto/pop3/pop3comm.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef __POP3COMM_H -#define __POP3COMM_H - -#include -#include "pop3.h" - -#include "m_protoplugin.h" -//We can use synchro.h because this is internal plugin. If you use external plugin, -//and you want to use SO for your plugin, you can use YAMN's SO. -//All you need is to include synchro.h and use YAMN's exported synchronization functions. -#include "m_synchro.h" - -//For mail exported functions defintions -#include "m_mails.h" - -#include "../../debug.h" - -#define POP3_FILEVERSION 1 //Version of aditional information stored in book file - -typedef struct CPOP3Account: public CAccount -{ -// We can use SCOUNTER structure, because this is internal plugin. -// This SO is used to determine if any POP3 account is in "write access" mode - static PSCOUNTER AccountWriterSO; - -// It is usefull to have client structure in account. With this structure we have access to account's socket. -// This is related to InternetQueries and UseInternetFree -// This member should be synchronized with UseInternetFree - class CPop3Client Client; - -// This member is usefull for MIME headers. It is default codepage, if no other codepage found - WORD CP; //access only through AccountAccessSO - -// In this memeber last error code is stored - DWORD SystemError; //access through UseInternetFree - -// We use only counter from this object and it is # of threads waiting to work on internet. -// We use event UseInternet to access critical sections. -// It is usefull in 2 ways: we have mutual exclusion that only one thread works with account on internet. -// Thread, which has done its work with account on internet can close socket, but it is not needed, when any other -// thread wants to work (e.g. we have deleted mails, but when deleting, another thread wants to check new mail, so -// we delete all needed mails and check if there's thread that wants to work. If yes, we do not need to quit session, -// we leave socket open, and leave internet. Another thread then start checking and does not connect, does not send -// user and password... because socket is open- it continues) - PSCOUNTER InternetQueries; - HANDLE UseInternetFree; - - CPOP3Account(); - ~CPOP3Account(); - -} POP3ACCOUNT,*HPOP3ACCOUNT; - -typedef struct POP3LayeredError -{ - BOOL SSL; - DWORD AppError; - DWORD POP3Error; - DWORD NetError; - DWORD SystemError; -} POP3_ERRORCODE,*PPOP3_ERRORCODE; - -struct YAMNExportedFcns -{ - YAMN_SETPROTOCOLPLUGINFCNIMPORTFCN SetProtocolPluginFcnImportFcn; - YAMN_WAITTOWRITEFCN WaitToWriteFcn; - YAMN_WRITEDONEFCN WriteDoneFcn; - YAMN_WAITTOREADFCN WaitToReadFcn; - YAMN_READDONEFCN ReadDoneFcn; - YAMN_SCMANAGEFCN SCGetNumberFcn; - YAMN_SCMANAGEFCN SCIncFcn; - YAMN_SCMANAGEFCN SCDecFcn; - YAMN_SETSTATUSFCN SetStatusFcn; - YAMN_GETSTATUSFCN GetStatusFcn; -}; - -struct MailExportedFcns -{ - YAMN_SYNCHROMIMEMSGSFCN SynchroMessagesFcn; - YAMN_TRANSLATEHEADERFCN TranslateHeaderFcn; - YAMN_APPENDQUEUEFCN AppendQueueFcn; - YAMN_DELETEMIMEQUEUEFCN DeleteMessagesToEndFcn; - YAMN_DELETEMIMEMESSAGEFCN DeleteMessageFromQueueFcn; - YAMN_FINDMIMEMESSAGEFCN FindMessageByIDFcn; - YAMN_CREATENEWDELETEQUEUEFCN CreateNewDeleteQueueFcn; -}; - -enum -{ - EACC_QUEUEALLOC=1, //memory allocation - EACC_STOPPED, //stop account -}; - -#define NO_MAIL_FOR_DELETE 1 - -#define POP3_DELETEFROMCHECK 1 - -#endif diff --git a/protocols/YAMN/proto/pop3/pop3opt.cpp b/protocols/YAMN/proto/pop3/pop3opt.cpp deleted file mode 100644 index 1a265a0800..0000000000 --- a/protocols/YAMN/proto/pop3/pop3opt.cpp +++ /dev/null @@ -1,1556 +0,0 @@ -/* - * This code implements POP3 options window handling - * - * (c) majvan 2002-2003 -*/ - -#include "../../yamn.h" -#include "../../main.h" -#include "pop3comm.h" -#include "pop3opt.h" - -//-------------------------------------------------------------------------------------------------- - -static BOOL Check0,Check1,Check2,Check3,Check4,Check5,Check6,Check7,Check8,Check9; -static char DlgInput[MAX_PATH]; - -void CheckMenuItems(); - -//-------------------------------------------------------------------------------------------------- - -INT_PTR CALLBACK DlgProcYAMNOpt(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - switch(msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hDlg); - CheckDlgButton(hDlg,IDC_CHECKTTB,DBGetContactSettingByte(NULL,YAMN_DBMODULE,YAMN_TTBFCHECK,1) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_LONGDATE,(optDateTime&SHOWDATELONG) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_SMARTDATE,(optDateTime&SHOWDATENOTODAY) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_NOSECONDS,(optDateTime&SHOWDATENOSECONDS) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_MAINMENU,DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWMAINMENU, 1)); - CheckDlgButton(hDlg,IDC_YAMNASPROTO,DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWASPROTO, 1)); - CheckDlgButton(hDlg,IDC_CLOSEONDELETE,DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_CLOSEDELETE, 0)); - break; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_YAMNASPROTO: - case IDC_MAINMENU: - case IDC_CHECKTTB: - case IDC_CLOSEONDELETE: - case IDC_LONGDATE: - case IDC_SMARTDATE: - case IDC_NOSECONDS: - SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); - break; - } - break; - - case WM_NOTIFY: - switch(((LPNMHDR)lParam)->idFrom) { - case 0: - switch(((LPNMHDR)lParam)->code) { - case PSN_APPLY: - DBWriteContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWASPROTO, IsDlgButtonChecked(hDlg,IDC_YAMNASPROTO)); - DBWriteContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWMAINMENU, IsDlgButtonChecked(hDlg,IDC_MAINMENU)); - DBWriteContactSettingByte(NULL, YAMN_DBMODULE, YAMN_CLOSEDELETE, IsDlgButtonChecked(hDlg,IDC_CLOSEONDELETE)); - DBWriteContactSettingByte(NULL, YAMN_DBMODULE, YAMN_TTBFCHECK, IsDlgButtonChecked(hDlg,IDC_CHECKTTB)); - - AddTopToolbarIcon(0, 0); - CheckMenuItems(); - - optDateTime = 0; - if (IsDlgButtonChecked(hDlg,IDC_LONGDATE))optDateTime |= SHOWDATELONG; - if (IsDlgButtonChecked(hDlg,IDC_SMARTDATE))optDateTime |= SHOWDATENOTODAY; - if (IsDlgButtonChecked(hDlg,IDC_NOSECONDS))optDateTime |= SHOWDATENOSECONDS; - DBWriteContactSettingByte(NULL,YAMN_DBMODULE,YAMN_DBTIMEOPTIONS,optDateTime); - } - } - break; - } - - return FALSE; -} - -INT_PTR CALLBACK DlgProcPluginOpt(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - switch(msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hDlg); - break; - - case WM_COMMAND: - { - WORD wNotifyCode = HIWORD(wParam); - switch(LOWORD(wParam)) - { - case IDC_COMBOPLUGINS: - if (wNotifyCode==CBN_SELCHANGE) - { - HWND hCombo=GetDlgItem(hDlg,IDC_COMBOPLUGINS); - PYAMN_PROTOPLUGINQUEUE PParser; - PYAMN_FILTERPLUGINQUEUE FParser; - int index,id; - - if (CB_ERR==(index=SendMessage(hCombo,CB_GETCURSEL,0,0))) - break; - id=SendMessage(hCombo,CB_GETITEMDATA,(WPARAM)index,(LPARAM)0); - EnterCriticalSection(&PluginRegCS); - for (PParser=FirstProtoPlugin;PParser!=NULL;PParser=PParser->Next) - if (id==(INT_PTR)PParser->Plugin) - { - SetDlgItemTextA(hDlg,IDC_STVER,PParser->Plugin->PluginInfo->Ver); - SetDlgItemTextA(hDlg,IDC_STDESC,PParser->Plugin->PluginInfo->Description == NULL ? "" : PParser->Plugin->PluginInfo->Description); - SetDlgItemTextA(hDlg,IDC_STCOPY,PParser->Plugin->PluginInfo->Copyright == NULL ? "" : PParser->Plugin->PluginInfo->Copyright); - SetDlgItemTextA(hDlg,IDC_STMAIL,PParser->Plugin->PluginInfo->Email == NULL ? "" : PParser->Plugin->PluginInfo->Email); - SetDlgItemTextA(hDlg,IDC_STWWW,PParser->Plugin->PluginInfo->WWW == NULL ? "" : PParser->Plugin->PluginInfo->WWW); - break; - } - for (FParser=FirstFilterPlugin;FParser!=NULL;FParser=FParser->Next) - if (id==(INT_PTR)FParser->Plugin) - { - SetDlgItemTextA(hDlg,IDC_STVER,FParser->Plugin->PluginInfo->Ver); - SetDlgItemTextA(hDlg,IDC_STDESC,FParser->Plugin->PluginInfo->Description == NULL ? "" : FParser->Plugin->PluginInfo->Description); - SetDlgItemTextA(hDlg,IDC_STCOPY,FParser->Plugin->PluginInfo->Copyright == NULL ? "" : FParser->Plugin->PluginInfo->Copyright); - SetDlgItemTextA(hDlg,IDC_STMAIL,FParser->Plugin->PluginInfo->Email == NULL ? "" : FParser->Plugin->PluginInfo->Email); - SetDlgItemTextA(hDlg,IDC_STWWW,FParser->Plugin->PluginInfo->WWW == NULL ? "" : FParser->Plugin->PluginInfo->WWW); - break; - } - LeaveCriticalSection(&PluginRegCS); - } - break; - case IDC_STWWW: - { - char str[1024]; - GetDlgItemTextA(hDlg,IDC_STWWW,str,SIZEOF(str)); - CallService(MS_UTILS_OPENURL,1,(LPARAM)str); - break; - } - - } - break; - } - case WM_SHOWWINDOW: - if (TRUE==(BOOL)wParam) { - PYAMN_PROTOPLUGINQUEUE PParser; - PYAMN_FILTERPLUGINQUEUE FParser; - int index; - - EnterCriticalSection(&PluginRegCS); - for (PParser = FirstProtoPlugin; PParser != NULL; PParser = PParser->Next) { - index = SendDlgItemMessageA(hDlg,IDC_COMBOPLUGINS,CB_ADDSTRING,0,(LPARAM)PParser->Plugin->PluginInfo->Name); - index = SendDlgItemMessage(hDlg,IDC_COMBOPLUGINS,CB_SETITEMDATA,(WPARAM)index,(LPARAM)PParser->Plugin); - } - for (FParser = FirstFilterPlugin; FParser != NULL; FParser = FParser->Next) { - index = SendDlgItemMessageA(hDlg,IDC_COMBOPLUGINS,CB_ADDSTRING,0,(LPARAM)FParser->Plugin->PluginInfo->Name); - index = SendDlgItemMessage(hDlg,IDC_COMBOPLUGINS,CB_SETITEMDATA,(WPARAM)index,(LPARAM)FParser->Plugin); - } - - LeaveCriticalSection(&PluginRegCS); - SendDlgItemMessage(hDlg,IDC_COMBOPLUGINS,CB_SETCURSEL,(WPARAM)0,(LPARAM)0); - SendMessage(hDlg,WM_COMMAND,MAKELONG(IDC_COMBOPLUGINS,CBN_SELCHANGE),(LPARAM)NULL); - break; - } - else { //delete all items in combobox - int cbn=SendDlgItemMessage(hDlg,IDC_COMBOPLUGINS,CB_GETCOUNT,(WPARAM)0,(LPARAM)0); - for (int i=0;iStatusFlags & YAMN_ACC_ST0 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST1,ActualAccount->StatusFlags & YAMN_ACC_ST1 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST2,ActualAccount->StatusFlags & YAMN_ACC_ST2 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST3,ActualAccount->StatusFlags & YAMN_ACC_ST3 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST4,ActualAccount->StatusFlags & YAMN_ACC_ST4 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST5,ActualAccount->StatusFlags & YAMN_ACC_ST5 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST6,ActualAccount->StatusFlags & YAMN_ACC_ST6 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST7,ActualAccount->StatusFlags & YAMN_ACC_ST7 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST8,ActualAccount->StatusFlags & YAMN_ACC_ST8 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST9,ActualAccount->StatusFlags & YAMN_ACC_ST9 ? BST_CHECKED : BST_UNCHECKED); - ReadDone(ActualAccount); - } - else - { - CheckDlgButton(hDlg,IDC_CHECKST0,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST1,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST2,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST3,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST4,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST5,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST6,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST7,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST8,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST9,BST_CHECKED); - } - return TRUE; -} -BOOL DlgShowAccountPopup(HWND hDlg,WPARAM wParam,LPARAM lParam) -{ - HPOP3ACCOUNT ActualAccount=(HPOP3ACCOUNT)lParam; - - if ((DWORD)wParam==M_SHOWACTUAL) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read wait\n"); - #endif - WaitToRead(ActualAccount); //we do not need to check if account is deleted. It is not deleted, because only thread that can delete account is this thread - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read enter\n"); - #endif - SetDlgItemInt(hDlg,IDC_EDITPOPS,ActualAccount->NewMailN.PopUpTime,FALSE); - SetDlgItemInt(hDlg,IDC_EDITNPOPS,ActualAccount->NoNewMailN.PopUpTime,FALSE); - SetDlgItemInt(hDlg,IDC_EDITFPOPS,ActualAccount->BadConnectN.PopUpTime,FALSE); - - - CheckDlgButton(hDlg,IDC_CHECKPOP,ActualAccount->NewMailN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKCOL,ActualAccount->NewMailN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKNPOP,ActualAccount->NoNewMailN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKNCOL,ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFPOP,ActualAccount->BadConnectN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFCOL,ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_RADIOPOPN,ActualAccount->Flags & YAMN_ACC_POPN ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_RADIOPOP1,ActualAccount->Flags & YAMN_ACC_POPN ? BST_UNCHECKED : BST_CHECKED); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read done\n"); - #endif - ReadDone(ActualAccount); - } - else //default - { - - SetDlgItemInt(hDlg,IDC_EDITPOPS,0,FALSE); - SetDlgItemInt(hDlg,IDC_EDITNPOPS,0,FALSE); - SetDlgItemInt(hDlg,IDC_EDITFPOPS,0,FALSE); - CheckDlgButton(hDlg,IDC_CHECKPOP,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKCOL,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKNPOP,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKNCOL,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKFPOP,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKFCOL,BST_CHECKED); - CheckDlgButton(hDlg,IDC_RADIOPOPN,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_RADIOPOP1,BST_CHECKED); - } - return TRUE; -} -BOOL DlgShowAccount(HWND hDlg,WPARAM wParam,LPARAM lParam) -{ - HPOP3ACCOUNT ActualAccount=(HPOP3ACCOUNT)lParam; - int i; - - if ((DWORD)wParam==M_SHOWACTUAL) - { - TCHAR accstatus[256]; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read wait\n"); - #endif - WaitToRead(ActualAccount); //we do not need to check if account is deleted. It is not deleted, because only thread that can delete account is this thread - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read enter\n"); - #endif - DlgSetItemText(hDlg, IDC_EDITSERVER, ActualAccount->Server->Name); - DlgSetItemText(hDlg, IDC_EDITNAME, ActualAccount->Name); - DlgSetItemText(hDlg, IDC_EDITLOGIN, ActualAccount->Server->Login); - DlgSetItemText(hDlg, IDC_EDITPASS, ActualAccount->Server->Passwd); - DlgSetItemTextW(hDlg, IDC_EDITAPP, ActualAccount->NewMailN.App); - DlgSetItemTextW(hDlg, IDC_EDITAPPPARAM, ActualAccount->NewMailN.AppParam); - SetDlgItemInt(hDlg,IDC_EDITPORT,ActualAccount->Server->Port,FALSE); - SetDlgItemInt(hDlg,IDC_EDITINTERVAL,ActualAccount->Interval/60,FALSE); - SetDlgItemInt(hDlg,IDC_EDITPOPS,ActualAccount->NewMailN.PopUpTime,FALSE); - SetDlgItemInt(hDlg,IDC_EDITNPOPS,ActualAccount->NoNewMailN.PopUpTime,FALSE); - SetDlgItemInt(hDlg,IDC_EDITFPOPS,ActualAccount->BadConnectN.PopUpTime,FALSE); - for (i=0;i<=CPLENSUPP;i++) - if ((iCP)) - { - SendMessage(GetDlgItem(hDlg,IDC_COMBOCP),CB_SETCURSEL,(WPARAM)i,(LPARAM)0); - break; - } - if (i==CPLENSUPP) - SendMessage(GetDlgItem(hDlg,IDC_COMBOCP),CB_SETCURSEL,(WPARAM)CPDEFINDEX,(LPARAM)0); - - CheckDlgButton(hDlg,IDC_CHECK,ActualAccount->Flags & YAMN_ACC_ENA ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKSND,ActualAccount->NewMailN.Flags & YAMN_ACC_SND ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKMSG,ActualAccount->NewMailN.Flags & YAMN_ACC_MSG ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKICO,ActualAccount->NewMailN.Flags & YAMN_ACC_ICO ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKPOP,ActualAccount->NewMailN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKCOL,ActualAccount->NewMailN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKAPP,ActualAccount->NewMailN.Flags & YAMN_ACC_APP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKKBN,ActualAccount->NewMailN.Flags & YAMN_ACC_KBN ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKNPOP,ActualAccount->NoNewMailN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKNCOL,ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKNMSGP,ActualAccount->NoNewMailN.Flags & YAMN_ACC_MSGP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFSND,ActualAccount->BadConnectN.Flags & YAMN_ACC_SND ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFMSG,ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFICO,ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFPOP,ActualAccount->BadConnectN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFCOL,ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_RADIOPOPN,ActualAccount->Flags & YAMN_ACC_POPN ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_RADIOPOP1,ActualAccount->Flags & YAMN_ACC_POPN ? BST_UNCHECKED : BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKSSL,ActualAccount->Flags & YAMN_ACC_SSL23 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKNOTLS,ActualAccount->Flags & YAMN_ACC_NOTLS ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKAPOP,ActualAccount->Flags & YAMN_ACC_APOP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_AUTOBODY,ActualAccount->Flags & YAMN_ACC_BODY ? BST_CHECKED : BST_UNCHECKED); - /*CheckDlgButton(hDlg,IDC_CHECKST0,ActualAccount->StatusFlags & YAMN_ACC_ST0 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST1,ActualAccount->StatusFlags & YAMN_ACC_ST1 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST2,ActualAccount->StatusFlags & YAMN_ACC_ST2 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST3,ActualAccount->StatusFlags & YAMN_ACC_ST3 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST4,ActualAccount->StatusFlags & YAMN_ACC_ST4 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST5,ActualAccount->StatusFlags & YAMN_ACC_ST5 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST6,ActualAccount->StatusFlags & YAMN_ACC_ST6 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST7,ActualAccount->StatusFlags & YAMN_ACC_ST7 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST8,ActualAccount->StatusFlags & YAMN_ACC_ST8 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST9,ActualAccount->StatusFlags & YAMN_ACC_ST9 ? BST_CHECKED : BST_UNCHECKED);*/ - Check0=ActualAccount->StatusFlags & YAMN_ACC_ST0; - Check1=ActualAccount->StatusFlags & YAMN_ACC_ST1; - Check2=ActualAccount->StatusFlags & YAMN_ACC_ST2; - Check3=ActualAccount->StatusFlags & YAMN_ACC_ST3; - Check4=ActualAccount->StatusFlags & YAMN_ACC_ST4; - Check5=ActualAccount->StatusFlags & YAMN_ACC_ST5; - Check6=ActualAccount->StatusFlags & YAMN_ACC_ST6; - Check7=ActualAccount->StatusFlags & YAMN_ACC_ST7; - Check8=ActualAccount->StatusFlags & YAMN_ACC_ST8; - Check9=ActualAccount->StatusFlags & YAMN_ACC_ST9; - CheckDlgButton(hDlg,IDC_CHECKSTART,ActualAccount->StatusFlags & YAMN_ACC_STARTS ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFORCE,ActualAccount->StatusFlags & YAMN_ACC_FORCE ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKCONTACT,ActualAccount->NewMailN.Flags & YAMN_ACC_CONT ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKCONTACTNICK,ActualAccount->NewMailN.Flags & YAMN_ACC_CONTNICK ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKCONTACTNOEVENT,ActualAccount->NewMailN.Flags & YAMN_ACC_CONTNOEVENT ? BST_CHECKED : BST_UNCHECKED); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read done\n"); -#endif - GetAccountStatus(ActualAccount,accstatus); - SetDlgItemText(hDlg,IDC_STSTATUS,accstatus); - ReadDone(ActualAccount); - } - else //default - { - DlgSetItemText(hDlg,(WPARAM)IDC_EDITSERVER,(LPARAM)NULL); - DlgSetItemText(hDlg,(WPARAM)IDC_EDITNAME,(LPARAM)NULL); - DlgSetItemText(hDlg,(WPARAM)IDC_EDITLOGIN,(LPARAM)NULL); - DlgSetItemText(hDlg,(WPARAM)IDC_EDITPASS,(LPARAM)NULL); - DlgSetItemText(hDlg,(WPARAM)IDC_EDITAPP,(LPARAM)NULL); - DlgSetItemText(hDlg,(WPARAM)IDC_EDITAPPPARAM,(LPARAM)NULL); - DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); - SetDlgItemInt(hDlg,IDC_EDITPORT,110,FALSE); - SetDlgItemInt(hDlg,IDC_EDITINTERVAL,30,FALSE); - SetDlgItemInt(hDlg,IDC_EDITPOPS,0,FALSE); - SetDlgItemInt(hDlg,IDC_EDITNPOPS,0,FALSE); - SetDlgItemInt(hDlg,IDC_EDITFPOPS,0,FALSE); - SendMessage(GetDlgItem(hDlg,IDC_COMBOCP),CB_SETCURSEL,(WPARAM)CPDEFINDEX,(LPARAM)0); - CheckDlgButton(hDlg,IDC_CHECK,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKSND,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKMSG,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKICO,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKPOP,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKCOL,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKAPP,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKPOP,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKCOL,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKFSND,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFMSG,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFICO,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKFPOP,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKFCOL,BST_CHECKED); - /*CheckDlgButton(hDlg,IDC_CHECKST0,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST1,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST2,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST3,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST4,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST5,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST6,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKST7,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST8,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST9,BST_CHECKED);*/ - CheckDlgButton(hDlg,IDC_CHECKSTART,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKFORCE,BST_CHECKED); - CheckDlgButton(hDlg,IDC_RADIOPOPN,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_RADIOPOP1,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKSSL,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKNOTLS,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKAPOP,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_AUTOBODY,BST_UNCHECKED); - CheckDlgButton(hDlg,IDC_CHECKCONTACT,BST_CHECKED); - - SetDlgItemText(hDlg,IDC_STSTATUS,TranslateT("No account selected")); - } - return TRUE; -} - -BOOL DlgShowAccountColors(HWND hDlg,WPARAM wParam,LPARAM lParam) -{ - HPOP3ACCOUNT ActualAccount=(HPOP3ACCOUNT)lParam; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:SHOWACCOUNTCOLORS:ActualAccountSO-read wait\n"); -#endif - WaitToRead(ActualAccount); //we do not need to check if account is deleted. It is not deleted, because only thread that can delete account is this thread -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:SHOWACCOUNTCOLORS:ActualAccountSO-read enter\n"); -#endif - if (ActualAccount->NewMailN.Flags & YAMN_ACC_POPC) - { - SendDlgItemMessage(hDlg,IDC_CPB,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->NewMailN.PopUpB); - SendDlgItemMessage(hDlg,IDC_CPT,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->NewMailN.PopUpT); - } - else - { - SendDlgItemMessage(hDlg,IDC_CPB,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_BTNFACE)); - SendDlgItemMessage(hDlg,IDC_CPT,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_WINDOWTEXT)); - } - if (ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC) - { - SendDlgItemMessage(hDlg,IDC_CPFB,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->BadConnectN.PopUpB); - SendDlgItemMessage(hDlg,IDC_CPFT,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->BadConnectN.PopUpT); - } - else - { - SendDlgItemMessage(hDlg,IDC_CPFB,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_BTNFACE)); - SendDlgItemMessage(hDlg,IDC_CPFT,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_WINDOWTEXT)); - } - if (ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC) - { - SendDlgItemMessage(hDlg,IDC_CPNB,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->NoNewMailN.PopUpB); - SendDlgItemMessage(hDlg,IDC_CPNT,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->NoNewMailN.PopUpT); - } - else - { - SendDlgItemMessage(hDlg,IDC_CPNB,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_BTNFACE)); - SendDlgItemMessage(hDlg,IDC_CPNT,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_WINDOWTEXT)); - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:SHOWACCOUNTCOLORS:ActualAccountSO-read done\n"); -#endif - ReadDone(ActualAccount); //we do not need to check if account is deleted. It is not deleted, because only thread that can delete account is this thread - return TRUE; -} - -BOOL DlgSetItemText(HWND hDlg, WPARAM wParam,const char* str) -{ - if (str == NULL) - SetDlgItemTextA(hDlg, wParam, ""); - else - SetDlgItemTextA(hDlg, wParam, str); - return TRUE; -} - -BOOL DlgSetItemTextW(HWND hDlg,WPARAM wParam,const WCHAR* str) -{ - if (str == NULL) - SetDlgItemTextW(hDlg, wParam, L""); - else - SetDlgItemTextW(hDlg, wParam, str); - return TRUE; -} - -INT_PTR CALLBACK DlgProcPOP3AccStatusOpt(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - static HPOP3ACCOUNT ActualAccount; - switch(msg) - { - case WM_INITDIALOG: - { - ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput); - if (ActualAccount != NULL) - { - DlgShowAccountStatus(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); - DlgEnableAccountStatus(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); - } - else - { - CheckDlgButton(hDlg,IDC_CHECKST0,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST1,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST2,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST3,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST4,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST5,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST6,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST7,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST8,BST_CHECKED); - CheckDlgButton(hDlg,IDC_CHECKST9,BST_CHECKED); - } - TranslateDialogDefault(hDlg); - SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,0); - return TRUE; - break; - } - case WM_COMMAND: - { - - WORD wNotifyCode = HIWORD(wParam); - switch(LOWORD(wParam)) - { - case IDOK: - Check0 = (IsDlgButtonChecked(hDlg,IDC_CHECKST0)==BST_CHECKED); - Check1 = (IsDlgButtonChecked(hDlg,IDC_CHECKST1)==BST_CHECKED); - Check2 = (IsDlgButtonChecked(hDlg,IDC_CHECKST2)==BST_CHECKED); - Check3 = (IsDlgButtonChecked(hDlg,IDC_CHECKST3)==BST_CHECKED); - Check4 = (IsDlgButtonChecked(hDlg,IDC_CHECKST4)==BST_CHECKED); - Check5 = (IsDlgButtonChecked(hDlg,IDC_CHECKST5)==BST_CHECKED); - Check6 = (IsDlgButtonChecked(hDlg,IDC_CHECKST6)==BST_CHECKED); - Check7 = (IsDlgButtonChecked(hDlg,IDC_CHECKST7)==BST_CHECKED); - Check8 = (IsDlgButtonChecked(hDlg,IDC_CHECKST8)==BST_CHECKED); - Check9 = (IsDlgButtonChecked(hDlg,IDC_CHECKST9)==BST_CHECKED); - WindowList_BroadcastAsync(YAMNVar.MessageWnds,WM_YAMN_CHANGESTATUSOPTION,(WPARAM)0,(LPARAM)0); - EndDialog(hDlg,0); - DestroyWindow(hDlg); - break; - - case IDCANCEL: - EndDialog(hDlg,0); - DestroyWindow(hDlg); - break; - - default: - break; - } - } - default: - break; - } - return FALSE; -} - - -INT_PTR CALLBACK DlgProcPOP3AccOpt(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - BOOL Changed=FALSE; - INT_PTR Result; - static BOOL InList=FALSE; - static HPOP3ACCOUNT ActualAccount; - static UCHAR ActualStatus; -// static struct CPOP3Options POP3Options; - - switch(msg) - { - case WM_INITDIALOG: - { - int i; - - EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); - - DlgEnableAccount(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); - DlgShowAccount(hDlg,(WPARAM)M_SHOWDEFAULT,0); - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read wait\n"); - #endif - WaitToReadSO(POP3Plugin->AccountBrowserSO); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read enter\n"); - #endif - - for (ActualAccount=(HPOP3ACCOUNT)POP3Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=(HPOP3ACCOUNT)ActualAccount->Next) - if (ActualAccount->Name != NULL) - SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_ADDSTRING,0,(LPARAM)ActualAccount->Name); - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read done\n"); - #endif - ReadDoneSO(POP3Plugin->AccountBrowserSO); - SendDlgItemMessage(hDlg, IDC_COMBOCP, CB_ADDSTRING, 0, (LPARAM)TranslateT("Default")); - for (i=1; i < CPLENSUPP; i++) { - CPINFOEX info; GetCPInfoEx(CodePageNamesSupp[i].CP,0,&info); - size_t len = lstrlen(info.CodePageName+7); - info.CodePageName[len+6]=0; - SendDlgItemMessage(hDlg,IDC_COMBOCP,CB_ADDSTRING,0,(LPARAM)(info.CodePageName+7)); - } - - SendMessage(GetDlgItem(hDlg,IDC_COMBOCP),CB_SETCURSEL,(WPARAM)CPDEFINDEX,(LPARAM)0); - ActualAccount=NULL; - TranslateDialogDefault(hDlg); - SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,0); - return TRUE; - } - - case WM_SHOWWINDOW: - if ( wParam == FALSE) { - WindowList_Remove(pYAMNVar->MessageWnds,hDlg); - SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,(LPARAM)0); - } - else WindowList_Add(pYAMNVar->MessageWnds,hDlg,NULL); - return TRUE; - - case WM_YAMN_CHANGESTATUS: - if ((HPOP3ACCOUNT)wParam == ActualAccount) { - TCHAR accstatus[256]; - GetAccountStatus(ActualAccount,accstatus); - SetDlgItemText(hDlg,IDC_STSTATUS,accstatus); - return TRUE; - } - break; - - case WM_YAMN_CHANGESTATUSOPTION: - Changed=TRUE; - SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); - return TRUE; - - case WM_YAMN_CHANGETIME: - if ((HPOP3ACCOUNT)wParam == ActualAccount) { - TCHAR Text[256]; - mir_sntprintf(Text,SIZEOF(Text),TranslateT("Time left to next check [s]: %d"),(DWORD)lParam); - SetDlgItemText(hDlg,IDC_STTIMELEFT,Text); - } - return TRUE; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_COMBOACCOUNT: - switch( HIWORD(wParam)) { - case CBN_EDITCHANGE : - ActualAccount=NULL; - DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); - - if (GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT,DlgInput,sizeof(DlgInput))) - DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)FALSE); - else - DlgEnableAccount(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); - break; - - case CBN_KILLFOCUS: - GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT,DlgInput,sizeof(DlgInput)); - if (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput))) { - DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); - EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); - if (lstrlenA(DlgInput)) - DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); - else - DlgEnableAccount(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); - } - else { - DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); - DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); - EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),TRUE); - } - break; - - case CBN_SELCHANGE: - if (CB_ERR!=(Result=SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,0,0))) - SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_GETLBTEXT,(WPARAM)Result,(LPARAM)DlgInput); - - if ((Result==CB_ERR) || (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput)))) { - DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); - EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); - } - else { - DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); - DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)FALSE); - EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),TRUE); - } - break; - } - break; - - case IDC_COMBOCP: - { - int sel = SendDlgItemMessage(hDlg,IDC_COMBOCP,CB_GETCURSEL,0,0); - CPINFOEX info; GetCPInfoEx(CodePageNamesSupp[sel].CP,0,&info); - DlgSetItemTextT(hDlg, IDC_STSTATUS, info.CodePageName); - } - case IDC_CHECK: - case IDC_CHECKSND: - case IDC_CHECKMSG: - case IDC_CHECKICO: - case IDC_CHECKFSND: - case IDC_CHECKFMSG: - case IDC_CHECKFICO: - case IDC_CHECKST0: - case IDC_CHECKST1: - case IDC_CHECKST2: - case IDC_CHECKST3: - case IDC_CHECKST4: - case IDC_CHECKST5: - case IDC_CHECKST6: - case IDC_CHECKST7: - case IDC_CHECKST8: - case IDC_CHECKST9: - case IDC_CHECKSTART: - case IDC_CHECKFORCE: - case IDC_EDITAPPPARAM: - case IDC_CHECKAPOP: - case IDC_AUTOBODY: - case IDC_CHECKCONTACTNICK: - case IDC_CHECKCONTACTNOEVENT: - case IDC_CHECKNOTLS: - Changed=TRUE; - break; - - case IDC_CHECKCONTACT: - Changed=IsDlgButtonChecked(hDlg,IDC_CHECKCONTACT)==BST_CHECKED; - EnableWindow(GetDlgItem(hDlg,IDC_CHECKCONTACTNICK),Changed); - EnableWindow(GetDlgItem(hDlg,IDC_CHECKCONTACTNOEVENT),Changed); - Changed=TRUE; - break; - - case IDC_CHECKSSL: - { - BOOL SSLC = (IsDlgButtonChecked(hDlg,IDC_CHECKSSL)==BST_CHECKED); - SetDlgItemInt(hDlg,IDC_EDITPORT,SSLC ? 995 : 110,FALSE); - EnableWindow(GetDlgItem(hDlg,IDC_CHECKNOTLS),SSLC?0:1); - } - Changed=TRUE; - break; - - case IDC_CPB: - case IDC_CPT: - case IDC_CPFB: - case IDC_CPFT: - case IDC_CPNB: - case IDC_CPNT: - if (HIWORD(wParam)!=CPN_COLOURCHANGED) - break; - - case IDC_CHECKKBN: - Changed=TRUE; - break; - - case IDC_CHECKAPP: - Changed=TRUE; - EnableWindow(GetDlgItem(hDlg,IDC_BTNAPP),IsDlgButtonChecked(hDlg,IDC_CHECKAPP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_EDITAPP),IsDlgButtonChecked(hDlg,IDC_CHECKAPP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_EDITAPPPARAM),IsDlgButtonChecked(hDlg,IDC_CHECKAPP)==BST_CHECKED); - break; - - case IDC_BTNSTATUS: - DialogBoxParamW(pYAMNVar->hInst,MAKEINTRESOURCEW(IDD_CHOOSESTATUSMODES),hDlg,DlgProcPOP3AccStatusOpt,NULL); - break; - - case IDC_BTNADD: - DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); - DlgShowAccount(hDlg,(WPARAM)M_SHOWDEFAULT,0); - DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); - EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); - DlgSetItemTextT(hDlg, IDC_EDITNAME, TranslateT("New Account")); - { - int index = SendDlgItemMessage(hDlg, IDC_COMBOACCOUNT, CB_ADDSTRING, 0, (LPARAM)TranslateT("New Account")); - if ( index != CB_ERR && index != CB_ERRSPACE ) - SendDlgItemMessage(hDlg, IDC_COMBOACCOUNT, CB_SETCURSEL, index, (LPARAM)TranslateT("New Account")); - } - break; - - case IDC_BTNAPP: - { - TCHAR filter[MAX_PATH]; - mir_sntprintf(filter, SIZEOF(filter), _T("%s (*.exe;*.bat;*.cmd;*.com)%c*.exe;*.bat;*.cmd;*.com%c%s (*.*)%c*.*%c"), - TranslateT("Executables"), 0, 0, TranslateT("All Files"), 0, 0); - - OPENFILENAME OFNStruct = { 0 }; - OFNStruct.lStructSize = sizeof(OPENFILENAME); - OFNStruct.hwndOwner = hDlg; - OFNStruct.lpstrFilter= filter; - OFNStruct.nFilterIndex=1; - OFNStruct.nMaxFile=MAX_PATH; - OFNStruct.lpstrFile=new TCHAR[MAX_PATH]; - OFNStruct.lpstrFile[0]=(TCHAR)0; - OFNStruct.lpstrTitle=TranslateT("Select executable used for notification"); - OFNStruct.Flags=OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR; - if (!GetOpenFileName(&OFNStruct)) - { - if (CommDlgExtendedError()) - MessageBox(hDlg,_T("Dialog box error"),_T("Failed"),MB_OK); - } - else DlgSetItemTextT(hDlg, IDC_EDITAPP, OFNStruct.lpstrFile); - delete[] OFNStruct.lpstrFile; - } - break; - - case IDC_BTNDEFAULT: - DlgShowAccount(hDlg,(WPARAM)M_SHOWDEFAULT,0); - break; - - case IDC_BTNDEL: - GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT,DlgInput,sizeof(DlgInput)); - EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); - if ((CB_ERR==(Result=SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,0,0))) - || (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput)))) - return TRUE; - - if (IDOK!=MessageBox(hDlg,TranslateT("Do you really want to delete this account?"),TranslateT("Delete account confirmation"),MB_OKCANCEL | MB_ICONWARNING)) - return TRUE; - - DlgSetItemTextT(hDlg, IDC_STTIMELEFT, TranslateT("Please wait while no account is in use.")); - - if (ActualAccount->hContact != NULL) - CallService(MS_DB_CONTACT_DELETE,(WPARAM)(HANDLE) ActualAccount->hContact, 0); - - CallService(MS_YAMN_DELETEACCOUNT,(WPARAM)POP3Plugin,(LPARAM)ActualAccount); - - //We can consider our account as deleted. - - SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_DELETESTRING,(WPARAM)Result,0); - DlgSetItemText(hDlg,(WPARAM)IDC_COMBOACCOUNT,(LPARAM)NULL); - DlgEnableAccount(hDlg,(WPARAM)FALSE,0); - DlgShowAccount(hDlg,(WPARAM)M_SHOWDEFAULT,0); - break; - - case IDC_BTNRESET: - if (ActualAccount != NULL) - ActualAccount->TimeLeft=ActualAccount->Interval; - return 1; - } - - if (HIWORD(wParam) == EN_CHANGE) - Changed = TRUE; - break; - - case WM_NOTIFY: - if (((LPNMHDR)lParam)->idFrom == 0 && ((LPNMHDR)lParam)->code == PSN_APPLY ) { - char Text[MAX_PATH]; - WCHAR TextW[MAX_PATH]; - BOOL Translated,NewAcc=FALSE,Check,CheckMsg,CheckSnd,CheckIco,CheckApp, CheckAPOP; - BOOL CheckNMsgP,CheckFMsg,CheckFSnd,CheckFIco; - BOOL CheckKBN, CheckContact,CheckContactNick,CheckContactNoEvent; - BOOL CheckSSL, CheckABody, CheckNoTLS; - //BOOL Check0,Check1,Check2,Check3,Check4,Check5,Check6,Check7,Check8,Check9, - BOOL CheckStart,CheckForce; - size_t Length,index; - UINT Port,Interval; - - if ( GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT, Text, sizeof(Text))) { - Check = (IsDlgButtonChecked(hDlg,IDC_CHECK)==BST_CHECKED); - CheckSSL = (IsDlgButtonChecked(hDlg,IDC_CHECKSSL)==BST_CHECKED); - CheckNoTLS = (IsDlgButtonChecked(hDlg,IDC_CHECKNOTLS)==BST_CHECKED); - CheckAPOP = (IsDlgButtonChecked(hDlg,IDC_CHECKAPOP)==BST_CHECKED); - - CheckABody = (IsDlgButtonChecked(hDlg,IDC_AUTOBODY)==BST_CHECKED); - CheckMsg = (IsDlgButtonChecked(hDlg,IDC_CHECKMSG)==BST_CHECKED); - CheckSnd = (IsDlgButtonChecked(hDlg,IDC_CHECKSND)==BST_CHECKED); - CheckIco = (IsDlgButtonChecked(hDlg,IDC_CHECKICO)==BST_CHECKED); - - CheckApp = (IsDlgButtonChecked(hDlg,IDC_CHECKAPP)==BST_CHECKED); - CheckKBN = (IsDlgButtonChecked(hDlg,IDC_CHECKKBN)==BST_CHECKED); - CheckContact = (IsDlgButtonChecked(hDlg,IDC_CHECKCONTACT)==BST_CHECKED); - CheckContactNick = (IsDlgButtonChecked(hDlg,IDC_CHECKCONTACTNICK)==BST_CHECKED); - CheckContactNoEvent = (IsDlgButtonChecked(hDlg,IDC_CHECKCONTACTNOEVENT)==BST_CHECKED); - - CheckFSnd = (IsDlgButtonChecked(hDlg,IDC_CHECKFSND)==BST_CHECKED); - CheckFMsg = (IsDlgButtonChecked(hDlg,IDC_CHECKFMSG)==BST_CHECKED); - CheckFIco = (IsDlgButtonChecked(hDlg,IDC_CHECKFICO)==BST_CHECKED); - - CheckNMsgP = (IsDlgButtonChecked(hDlg,IDC_CHECKNMSGP)==BST_CHECKED); - - Port = GetDlgItemInt(hDlg, IDC_EDITPORT, &Translated, FALSE); - if ( !Translated ) { - MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); - SetFocus(GetDlgItem(hDlg,IDC_EDITPORT)); - break; - } - Interval = GetDlgItemInt(hDlg,IDC_EDITINTERVAL,&Translated,FALSE); - if ( !Translated ) { - MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); - SetFocus(GetDlgItem(hDlg,IDC_EDITINTERVAL)); - break; - } - - GetDlgItemTextA(hDlg, IDC_EDITAPP, Text, sizeof(Text)); - if (CheckApp && !(Length = strlen(Text))) { - MessageBox(hDlg,TranslateT("Please select application to run"),TranslateT("Input error"),MB_OK); - break; - } - - GetDlgItemTextA(hDlg, IDC_COMBOACCOUNT, Text, sizeof(Text)); - if ( !( Length = strlen(Text))) { - GetDlgItemTextA(hDlg,IDC_EDITNAME, Text, sizeof(Text)); - if ( !(Length = strlen( Text ))) - break; - } - - DlgSetItemTextT(hDlg, IDC_STTIMELEFT, TranslateT("Please wait while no account is in use.")); - - if (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)Text))) { - NewAcc=TRUE; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write wait\n"); - #endif - WaitToWriteSO(POP3Plugin->AccountBrowserSO); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write enter\n"); - #endif - if (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_GETNEXTFREEACCOUNT,(WPARAM)POP3Plugin,(LPARAM)YAMN_ACCOUNTVERSION))) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write done\n"); - #endif - WriteDoneSO(POP3Plugin->AccountBrowserSO); - MessageBox(hDlg,TranslateT("Cannot allocate memory space for new account"),TranslateT("Memory error"),MB_OK); - break; - } - } - else { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write wait\n"); - #endif - //We have to get full access to AccountBrowser, so other iterating thrads cannot get new account until new account is right set - WaitToWriteSO(POP3Plugin->AccountBrowserSO); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write enter\n"); - #endif - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write wait\n"); - #endif - if (WAIT_OBJECT_0!=WaitToWrite(ActualAccount)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write wait failed\n"); - #endif - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:ActualBrowserSO-write done\n"); - #endif - WriteDoneSO(POP3Plugin->AccountBrowserSO); - - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write enter\n"); - #endif - - GetDlgItemTextA(hDlg, IDC_EDITNAME, Text, sizeof(Text)); - if ( !(Length = strlen( Text ))) - break; - if (NULL != ActualAccount->Name) - delete[] ActualAccount->Name; - ActualAccount->Name = new char[ strlen(Text)+1]; - strcpy(ActualAccount->Name,Text); - - GetDlgItemTextA(hDlg,IDC_EDITSERVER,Text,sizeof(Text)); - if (NULL!=ActualAccount->Server->Name) - delete[] ActualAccount->Server->Name; - ActualAccount->Server->Name=new char[ strlen(Text)+1]; - strcpy(ActualAccount->Server->Name,Text); - - GetDlgItemTextA(hDlg,IDC_EDITLOGIN,Text,sizeof(Text)); - if (NULL!=ActualAccount->Server->Login) - delete[] ActualAccount->Server->Login; - ActualAccount->Server->Login=new char[ strlen(Text)+1]; - strcpy(ActualAccount->Server->Login,Text); - - GetDlgItemTextA(hDlg,IDC_EDITPASS,Text,sizeof(Text)); - if (NULL!=ActualAccount->Server->Passwd) - delete[] ActualAccount->Server->Passwd; - ActualAccount->Server->Passwd=new char[ strlen(Text)+1]; - strcpy(ActualAccount->Server->Passwd,Text); - - GetDlgItemTextW(hDlg,IDC_EDITAPP,TextW,SIZEOF(TextW)); - if (NULL!=ActualAccount->NewMailN.App) - delete[] ActualAccount->NewMailN.App; - ActualAccount->NewMailN.App=new WCHAR[wcslen(TextW)+1]; - wcscpy(ActualAccount->NewMailN.App,TextW); - - GetDlgItemTextW(hDlg,IDC_EDITAPPPARAM,TextW,SIZEOF(TextW)); - if (NULL!=ActualAccount->NewMailN.AppParam) - delete[] ActualAccount->NewMailN.AppParam; - ActualAccount->NewMailN.AppParam=new WCHAR[wcslen(TextW)+1]; - wcscpy(ActualAccount->NewMailN.AppParam,TextW); - - ActualAccount->Server->Port=Port; - ActualAccount->Interval=Interval*60; - - if (CB_ERR==(index=SendDlgItemMessage(hDlg,IDC_COMBOCP,CB_GETCURSEL,0,0))) - index = CPDEFINDEX; - ActualAccount->CP = CodePageNamesSupp[index].CP; - - if (NewAcc) - ActualAccount->TimeLeft=Interval*60; - - CheckStart = (IsDlgButtonChecked(hDlg,IDC_CHECKSTART)==BST_CHECKED); - CheckForce = (IsDlgButtonChecked(hDlg,IDC_CHECKFORCE)==BST_CHECKED); - - ActualAccount->Flags= - (Check ? YAMN_ACC_ENA : 0) | - (CheckSSL ? YAMN_ACC_SSL23 : 0) | - (CheckNoTLS ? YAMN_ACC_NOTLS : 0) | - (CheckAPOP ? YAMN_ACC_APOP : 0) | - (CheckABody ? YAMN_ACC_BODY : 0) | - (ActualAccount->Flags & YAMN_ACC_POPN); - - ActualAccount->StatusFlags= - (Check0 ? YAMN_ACC_ST0 : 0) | - (Check1 ? YAMN_ACC_ST1 : 0) | - (Check2 ? YAMN_ACC_ST2 : 0) | - (Check3 ? YAMN_ACC_ST3 : 0) | - (Check4 ? YAMN_ACC_ST4 : 0) | - (Check5 ? YAMN_ACC_ST5 : 0) | - (Check6 ? YAMN_ACC_ST6 : 0) | - (Check7 ? YAMN_ACC_ST7 : 0) | - (Check8 ? YAMN_ACC_ST8 : 0) | - (Check9 ? YAMN_ACC_ST9 : 0) | - (CheckStart ? YAMN_ACC_STARTS : 0) | - (CheckForce ? YAMN_ACC_FORCE : 0); - - ActualAccount->NewMailN.Flags= - (CheckSnd ? YAMN_ACC_SND : 0) | - (CheckMsg ? YAMN_ACC_MSG : 0) | - (CheckIco ? YAMN_ACC_ICO : 0) | - (ActualAccount->NewMailN.Flags & YAMN_ACC_POP) | - (ActualAccount->NewMailN.Flags & YAMN_ACC_POPC) | - (CheckApp ? YAMN_ACC_APP : 0) | - (CheckKBN ? YAMN_ACC_KBN : 0) | - (CheckContact ? YAMN_ACC_CONT : 0) | - (CheckContactNick ? YAMN_ACC_CONTNICK : 0) | - (CheckContactNoEvent ? YAMN_ACC_CONTNOEVENT : 0) | - YAMN_ACC_MSGP; //this is default: when new mail arrives and window was displayed, leave it displayed. - - ActualAccount->NoNewMailN.Flags= - (ActualAccount->NoNewMailN.Flags & YAMN_ACC_POP) | - (ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC) | - (CheckNMsgP ? YAMN_ACC_MSGP : 0); - - ActualAccount->BadConnectN.Flags= - (CheckFSnd ? YAMN_ACC_SND : 0) | - (CheckFMsg ? YAMN_ACC_MSG : 0) | - (CheckFIco ? YAMN_ACC_ICO : 0) | - (ActualAccount->BadConnectN.Flags & YAMN_ACC_POP) | - (ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC); - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write done\n"); - #endif - WriteDone(ActualAccount); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write done\n"); - #endif - WriteDoneSO(POP3Plugin->AccountBrowserSO); - - EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),TRUE); - - DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); - - index = SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,(WPARAM)0,(LPARAM)0); - - HPOP3ACCOUNT temp = ActualAccount; - - SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_RESETCONTENT,0,(LPARAM)0); - if (POP3Plugin->FirstAccount!=NULL) - for (ActualAccount=(HPOP3ACCOUNT)POP3Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=(HPOP3ACCOUNT)ActualAccount->Next) - if (ActualAccount->Name!=NULL) - SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_ADDSTRING,0,(LPARAM)ActualAccount->Name); - - ActualAccount = temp; - SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_SETCURSEL,(WPARAM)index,(LPARAM)ActualAccount->Name); - - WritePOP3Accounts(); - RefreshContact(); - return TRUE; - } - } - break; - } - if (Changed) - SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); - return FALSE; -} - -INT_PTR CALLBACK DlgProcPOP3AccPopup(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) -{ - BOOL Changed=FALSE; - static BOOL InList=FALSE; - static HPOP3ACCOUNT ActualAccount; - static UCHAR ActualStatus; -// static struct CPOP3Options POP3Options; - - switch(msg) - { - case WM_INITDIALOG: - { - DlgEnableAccountPopup(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); - DlgShowAccountPopup(hDlg,(WPARAM)M_SHOWDEFAULT,0); - //DlgShowAccountColors(hDlg,0,(LPARAM)ActualAccount); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read wait\n"); - #endif - WaitToReadSO(POP3Plugin->AccountBrowserSO); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read enter\n"); - #endif - if (POP3Plugin->FirstAccount!=NULL) - for (ActualAccount=(HPOP3ACCOUNT)POP3Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=(HPOP3ACCOUNT)ActualAccount->Next) - if (ActualAccount->Name!=NULL) - SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_ADDSTRING,0,(LPARAM)ActualAccount->Name); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read done\n"); - #endif - ReadDoneSO(POP3Plugin->AccountBrowserSO); - ActualAccount=NULL; - - - TranslateDialogDefault(hDlg); - SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,0); - return TRUE; - } - - case WM_SHOWWINDOW: - if ((BOOL)wParam==FALSE) - { - WindowList_Remove(pYAMNVar->MessageWnds,hDlg); - SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,(LPARAM)0); - } - else - { - WindowList_Add(pYAMNVar->MessageWnds,hDlg,NULL); - - int index = SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,(WPARAM)0,(LPARAM)0); - HPOP3ACCOUNT temp = ActualAccount; - SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_RESETCONTENT,0,(LPARAM)0); - - if (POP3Plugin->FirstAccount!=NULL) - for (ActualAccount=(HPOP3ACCOUNT)POP3Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=(HPOP3ACCOUNT)ActualAccount->Next) - if (ActualAccount->Name!=NULL) - SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_ADDSTRING,0,(LPARAM)ActualAccount->Name); - - ActualAccount = temp; - - if (ActualAccount != NULL) - { - SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_SETCURSEL,(WPARAM)index,(LPARAM)ActualAccount->Name); - DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); - DlgShowAccountColors(hDlg,0,(LPARAM)ActualAccount); - DlgEnableAccountPopup(hDlg,(WPARAM)TRUE,(LPARAM)FALSE); - } - else - { - DlgShowAccountPopup(hDlg,(WPARAM)M_SHOWDEFAULT,0); - DlgEnableAccountPopup(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); - } - - } - return TRUE; - - case WM_COMMAND: - { - WORD wNotifyCode = HIWORD(wParam); - switch(LOWORD(wParam)) - { - LONG Result; - case IDC_COMBOACCOUNT: - switch(wNotifyCode) - { - - case CBN_KILLFOCUS: - GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT,DlgInput,sizeof(DlgInput)); - if (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput))) - { - DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); - if (lstrlenA(DlgInput)) - DlgEnableAccountPopup(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); - else - DlgEnableAccountPopup(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); - } - else - { - DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); - DlgShowAccountColors(hDlg,0,(LPARAM)ActualAccount); - DlgEnableAccountPopup(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); - } - break; - case CBN_SELCHANGE: - if (CB_ERR!=(Result=SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,0,0))) - SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_GETLBTEXT,(WPARAM)Result,(LPARAM)DlgInput); - if ((Result==CB_ERR) || (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput)))) - { - DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); - } - else - { - DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); - DlgShowAccountColors(hDlg,0,(LPARAM)ActualAccount); - DlgEnableAccountPopup(hDlg,(WPARAM)TRUE,(LPARAM)FALSE); - } - break; - } - break; - case IDC_COMBOCP: - { - int sel = SendDlgItemMessage(hDlg,IDC_COMBOCP,CB_GETCURSEL,0,0); - CPINFOEX info; GetCPInfoEx(CodePageNamesSupp[sel].CP,0,&info); - DlgSetItemTextT(hDlg, IDC_STSTATUS, info.CodePageName); - } - case IDC_RADIOPOPN: - case IDC_RADIOPOP1: - Changed=TRUE; - break; - case IDC_CPB: - case IDC_CPT: - case IDC_CPFB: - case IDC_CPFT: - case IDC_CPNB: - case IDC_CPNT: - if (HIWORD(wParam)!=CPN_COLOURCHANGED) - break; - case IDC_CHECKCOL: - case IDC_CHECKFCOL: - case IDC_CHECKNCOL: - EnableWindow(GetDlgItem(hDlg,IDC_CPB),(IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED) && wParam); - EnableWindow(GetDlgItem(hDlg,IDC_CPT),(IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED) && wParam); - EnableWindow(GetDlgItem(hDlg,IDC_CPNB),(IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED) && wParam); - EnableWindow(GetDlgItem(hDlg,IDC_CPNT),(IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED) && wParam); - EnableWindow(GetDlgItem(hDlg,IDC_CPFB),(IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED) && wParam); - EnableWindow(GetDlgItem(hDlg,IDC_CPFT),(IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED) && wParam); - Changed=TRUE; - break; - - case IDC_PREVIEW: - { - POPUPDATAT Tester; - POPUPDATAT TesterF; - POPUPDATAT TesterN; - BOOL TesterC = (IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED); - BOOL TesterFC = (IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED); - BOOL TesterNC = (IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED); - - ZeroMemory(&Tester,sizeof(Tester)); - ZeroMemory(&TesterF,sizeof(TesterF)); - ZeroMemory(&TesterF,sizeof(TesterN)); - Tester.lchContact=NULL; - TesterF.lchContact=NULL; - TesterN.lchContact=NULL; - Tester.lchIcon=g_LoadIconEx(2); - TesterF.lchIcon=g_LoadIconEx(3); - TesterN.lchIcon=g_LoadIconEx(1); - - lstrcpyn(Tester.lptzContactName,TranslateT("Account Test"),MAX_CONTACTNAME); - lstrcpyn(TesterF.lptzContactName,TranslateT("Account Test (failed)"),MAX_CONTACTNAME); - lstrcpyn(TesterN.lptzContactName,TranslateT("Account Test"),MAX_CONTACTNAME); - lstrcpyn(Tester.lptzText,TranslateT("You have N new mail messages"),MAX_SECONDLINE); - lstrcpyn(TesterF.lptzText,TranslateT("Connection failed message"),MAX_SECONDLINE); - lstrcpyn(TesterN.lptzText,TranslateT("No new mail message"),MAX_SECONDLINE); - if (TesterC) - { - Tester.colorBack=SendDlgItemMessage(hDlg,IDC_CPB,CPM_GETCOLOUR,0,0); - Tester.colorText=SendDlgItemMessage(hDlg,IDC_CPT,CPM_GETCOLOUR,0,0); - } - else - { - Tester.colorBack=GetSysColor(COLOR_BTNFACE); - Tester.colorText=GetSysColor(COLOR_WINDOWTEXT); - } - if (TesterFC) - { - TesterF.colorBack=SendDlgItemMessage(hDlg,IDC_CPFB,CPM_GETCOLOUR,0,0); - TesterF.colorText=SendDlgItemMessage(hDlg,IDC_CPFT,CPM_GETCOLOUR,0,0); - } - else - { - TesterF.colorBack=GetSysColor(COLOR_BTNFACE); - TesterF.colorText=GetSysColor(COLOR_WINDOWTEXT); - } - if (TesterNC) - { - TesterN.colorBack=SendDlgItemMessage(hDlg,IDC_CPNB,CPM_GETCOLOUR,0,0); - TesterN.colorText=SendDlgItemMessage(hDlg,IDC_CPNT,CPM_GETCOLOUR,0,0); - } - else - { - TesterN.colorBack=GetSysColor(COLOR_BTNFACE); - TesterN.colorText=GetSysColor(COLOR_WINDOWTEXT); - } - Tester.PluginWindowProc=NULL; - TesterF.PluginWindowProc=NULL; - TesterN.PluginWindowProc=NULL; - Tester.PluginData=NULL; - TesterF.PluginData=NULL; - TesterN.PluginData=NULL; - - if (IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED) - PUAddPopUpT(&Tester); - if (IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED) - PUAddPopUpT(&TesterF); - if (IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED) - PUAddPopUpT(&TesterN); - Changed=TRUE; - } - break; - case IDC_CHECKKBN: - Changed=TRUE; - break; - case IDC_CHECKPOP: - Changed=TRUE; - EnableWindow(GetDlgItem(hDlg,IDC_CHECKCOL),IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_CPB),(IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_CPT),(IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_RADIOPOPN),(IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED)); - EnableWindow(GetDlgItem(hDlg,IDC_RADIOPOP1),(IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED)); - EnableWindow(GetDlgItem(hDlg,IDC_EDITPOPS),(IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED)); - break; - case IDC_CHECKFPOP: - Changed=TRUE; - EnableWindow(GetDlgItem(hDlg,IDC_CHECKFCOL),IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_CPFB),(IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_CPFT),(IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_EDITFPOPS),(IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED)); - break; - case IDC_CHECKNPOP: - Changed=TRUE; - EnableWindow(GetDlgItem(hDlg,IDC_CHECKNCOL),IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_CPNB),(IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_CPNT),(IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED); - EnableWindow(GetDlgItem(hDlg,IDC_EDITNPOPS),(IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED)); - break; - - } - if (HIWORD(wParam)==EN_CHANGE) - Changed=TRUE; - break; - } - case WM_NOTIFY: - switch(((LPNMHDR)lParam)->idFrom) - { - case 0: - switch(((LPNMHDR)lParam)->code) - { - case PSN_APPLY: - { - TCHAR Text[MAX_PATH]; - BOOL Translated,NewAcc=FALSE,CheckPopup,CheckPopupW; - BOOL CheckNPopup,CheckNPopupW,CheckFPopup,CheckFPopupW; - BOOL CheckPopN; - UINT Time,TimeN,TimeF; - - if (GetDlgItemText(hDlg,IDC_COMBOACCOUNT,Text,sizeof(Text)/sizeof(TCHAR))) - { - CheckPopup = (IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED); - CheckPopupW = (IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED); - - CheckFPopup = (IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED); - CheckFPopupW = (IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED); - - CheckNPopup = (IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED); - CheckNPopupW = (IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED); - - CheckPopN = (IsDlgButtonChecked(hDlg,IDC_RADIOPOPN)==BST_CHECKED); - - - Time=GetDlgItemInt(hDlg,IDC_EDITPOPS,&Translated,FALSE); - if (!Translated) - { - MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); - SetFocus(GetDlgItem(hDlg,IDC_EDITPOPS)); - break; - } - TimeN=GetDlgItemInt(hDlg,IDC_EDITNPOPS,&Translated,FALSE); - if (!Translated) - { - MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); - SetFocus(GetDlgItem(hDlg,IDC_EDITNPOPS)); - break; - } - TimeF=GetDlgItemInt(hDlg,IDC_EDITFPOPS,&Translated,FALSE); - if (!Translated) - { - MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); - SetFocus(GetDlgItem(hDlg,IDC_EDITFPOPS)); - break; - } - - - DlgSetItemTextT(hDlg, IDC_STTIMELEFT, TranslateT("Please wait while no account is in use.")); - - ActualAccount->Flags= - (ActualAccount->Flags & YAMN_ACC_ENA) | - (ActualAccount->Flags & YAMN_ACC_SSL23) | - (ActualAccount->Flags & YAMN_ACC_NOTLS) | - (ActualAccount->Flags & YAMN_ACC_APOP) | - (ActualAccount->Flags & YAMN_ACC_BODY) | - (CheckPopN ? YAMN_ACC_POPN : 0); - - ActualAccount->NewMailN.Flags= - (ActualAccount->NewMailN.Flags & YAMN_ACC_SND) | - (ActualAccount->NewMailN.Flags & YAMN_ACC_MSG) | - (ActualAccount->NewMailN.Flags & YAMN_ACC_ICO) | - (CheckPopup ? YAMN_ACC_POP : 0) | - (CheckPopupW ? YAMN_ACC_POPC : 0) | - (ActualAccount->NewMailN.Flags & YAMN_ACC_APP) | - (ActualAccount->NewMailN.Flags & YAMN_ACC_KBN) | - (ActualAccount->NewMailN.Flags & YAMN_ACC_CONT) | - (ActualAccount->NewMailN.Flags & YAMN_ACC_CONTNICK) | - (ActualAccount->NewMailN.Flags & YAMN_ACC_CONTNOEVENT) | - YAMN_ACC_MSGP; - - ActualAccount->NoNewMailN.Flags= - (CheckNPopup ? YAMN_ACC_POP : 0) | - (CheckNPopupW ? YAMN_ACC_POPC : 0) | - (ActualAccount->NoNewMailN.Flags & YAMN_ACC_MSGP); - - ActualAccount->BadConnectN.Flags= - (ActualAccount->BadConnectN.Flags & YAMN_ACC_SND) | - (ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG) | - (ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO) | - (CheckFPopup ? YAMN_ACC_POP : 0) | - (CheckFPopupW ? YAMN_ACC_POPC : 0); - - ActualAccount->NewMailN.PopUpB=SendDlgItemMessage(hDlg,IDC_CPB,CPM_GETCOLOUR,0,0); - ActualAccount->NewMailN.PopUpT=SendDlgItemMessage(hDlg,IDC_CPT,CPM_GETCOLOUR,0,0); - ActualAccount->NewMailN.PopUpTime=Time; - - ActualAccount->NoNewMailN.PopUpB=SendDlgItemMessage(hDlg,IDC_CPNB,CPM_GETCOLOUR,0,0); - ActualAccount->NoNewMailN.PopUpT=SendDlgItemMessage(hDlg,IDC_CPNT,CPM_GETCOLOUR,0,0); - ActualAccount->NoNewMailN.PopUpTime=TimeN; - - ActualAccount->BadConnectN.PopUpB=SendDlgItemMessage(hDlg,IDC_CPFB,CPM_GETCOLOUR,0,0); - ActualAccount->BadConnectN.PopUpT=SendDlgItemMessage(hDlg,IDC_CPFT,CPM_GETCOLOUR,0,0); - ActualAccount->BadConnectN.PopUpTime=TimeF; - - - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write done\n"); - #endif - WriteDone(ActualAccount); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write done\n"); - #endif - WriteDoneSO(POP3Plugin->AccountBrowserSO); - -// if (0==WritePOP3Accounts()) -// Beep(500,100); - WritePOP3Accounts(); - RefreshContact(); - return TRUE; - } - } - break; - } - break; - } - break; - } - if (Changed) - SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); - return FALSE; -} - diff --git a/protocols/YAMN/proto/pop3/pop3opt.h b/protocols/YAMN/proto/pop3/pop3opt.h deleted file mode 100644 index 6a678284fa..0000000000 --- a/protocols/YAMN/proto/pop3/pop3opt.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef __OPTIONS_H -#define __OPTIONS_H - -#define M_SHOWACTUAL 0 -#define M_SHOWDEFAULT 1 - - -//Enables account in options -BOOL DlgEnableAccount(HWND hDlg,WPARAM wParam,LPARAM lParam); - -//Sets dialog controls to match current account -BOOL DlgShowAccount(HWND hDlg,WPARAM wParam,LPARAM lParam); - -//Sets colors to match colors of actual account -BOOL DlgShowAccountColors(HWND hDlg,WPARAM wParam,LPARAM lParam); - -//Options dialog procedure -INT_PTR CALLBACK DlgProcPOP3AccOpt(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); - -//Options dialog procedure -INT_PTR CALLBACK DlgProcPOP3AccStatusOpt(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); - -//Options dialog procedure -INT_PTR CALLBACK DlgProcYAMNOpt(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); - -//Options dialog procedure -INT_PTR CALLBACK DlgProcPOP3AccPopup(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); - -//Initializes POP3 options for Miranda -int POP3OptInit(WPARAM wParam,LPARAM lParam); - -//Sets dialog item text -BOOL DlgSetItemText(HWND hDlg,WPARAM wParam,const char*); -BOOL DlgSetItemTextW(HWND hDlg,WPARAM wParam,const WCHAR*); - - -#define DlgSetItemTextT DlgSetItemTextW - - -#endif diff --git a/protocols/YAMN/proto_yamn/proto_YAMN_10.vcxproj b/protocols/YAMN/proto_yamn/proto_YAMN_10.vcxproj new file mode 100644 index 0000000000..2338196c5f --- /dev/null +++ b/protocols/YAMN/proto_yamn/proto_YAMN_10.vcxproj @@ -0,0 +1,131 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + Proto_YAMN + {C1CDB82C-6BBF-496E-88F4-CC57E60B0CA9} + + + + DynamicLibrary + Unicode + + + DynamicLibrary + Unicode + + + DynamicLibrary + Unicode + + + DynamicLibrary + Unicode + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(Configuration)\Icons\ + $(SolutionDir)$(Configuration)64\Icons\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)\Icons\ + $(SolutionDir)$(Configuration)64\Icons\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ + true + + + + NDEBUG;%(PreprocessorDefinitions) + ..\..\..\include\msapi + + + Windows + true + false + true + true + $(SolutionDir)\lib + + + + + NDEBUG;%(PreprocessorDefinitions) + ..\..\..\include\msapi + + + Windows + true + false + true + true + $(SolutionDir)\lib + + + + + _DEBUG;%(PreprocessorDefinitions) + ..\..\..\include\msapi + + + Windows + true + false + $(SolutionDir)\lib + + + + + _DEBUG;%(PreprocessorDefinitions) + ..\..\..\include\msapi + + + Windows + true + false + $(SolutionDir)\lib + + + + + + + + + + + + \ No newline at end of file diff --git a/protocols/YAMN/proto_yamn/proto_YAMN_10.vcxproj.filters b/protocols/YAMN/proto_yamn/proto_YAMN_10.vcxproj.filters new file mode 100644 index 0000000000..3fa00bebfb --- /dev/null +++ b/protocols/YAMN/proto_yamn/proto_YAMN_10.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4726e1d1-39cd-435a-bd59-51fdb6745f46} + ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + {81ae85e6-6c6b-42dc-be93-6b2bdc29210f} + + + + + Header Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/protocols/YAMN/proto_yamn/res/icoaway.ico b/protocols/YAMN/proto_yamn/res/icoaway.ico new file mode 100644 index 0000000000..a99cbe0a60 Binary files /dev/null and b/protocols/YAMN/proto_yamn/res/icoaway.ico differ diff --git a/protocols/YAMN/proto_yamn/res/icooccupied.ico b/protocols/YAMN/proto_yamn/res/icooccupied.ico new file mode 100644 index 0000000000..81dd9fe467 Binary files /dev/null and b/protocols/YAMN/proto_yamn/res/icooccupied.ico differ diff --git a/protocols/YAMN/proto_yamn/res/icooffline.ico b/protocols/YAMN/proto_yamn/res/icooffline.ico new file mode 100644 index 0000000000..78f925ede7 Binary files /dev/null and b/protocols/YAMN/proto_yamn/res/icooffline.ico differ diff --git a/protocols/YAMN/proto_yamn/res/icoonline.ico b/protocols/YAMN/proto_yamn/res/icoonline.ico new file mode 100644 index 0000000000..b2605bb9d4 Binary files /dev/null and b/protocols/YAMN/proto_yamn/res/icoonline.ico differ diff --git a/protocols/YAMN/proto_yamn/res/proto_YAMN.rc b/protocols/YAMN/proto_yamn/res/proto_YAMN.rc new file mode 100644 index 0000000000..087ee444c9 --- /dev/null +++ b/protocols/YAMN/proto_yamn/res/proto_YAMN.rc @@ -0,0 +1,16 @@ +#include "..\src\resource.h" + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. + +IDI_ICON1 ICON "icooffline.ico" +IDI_ICON2 ICON "icoonline.ico" +IDI_ICON5 ICON "icooffline.ico" +IDI_ICON7 ICON "icooccupied.ico" +IDI_ICON3 ICON "icoaway.ico" diff --git a/protocols/YAMN/proto_yamn/src/resource.h b/protocols/YAMN/proto_yamn/src/resource.h new file mode 100644 index 0000000000..0532df3fa6 --- /dev/null +++ b/protocols/YAMN/proto_yamn/src/resource.h @@ -0,0 +1,20 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Proto_YAMN.rc +// +#define IDI_ICON1 105 +#define IDI_ICON2 104 +#define IDI_ICON3 128 +#define IDI_ICON5 131 +#define IDI_ICON7 159 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 110 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/protocols/YAMN/protoplugin.cpp b/protocols/YAMN/protoplugin.cpp deleted file mode 100644 index 479b54ce67..0000000000 --- a/protocols/YAMN/protoplugin.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * YAMN plugin export functions for protocols - * - * (c) majvan 2002-2004 - */ - -#include "yamn.h" - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -PYAMN_PROTOPLUGINQUEUE FirstProtoPlugin=NULL; - -INT_PTR RegisterProtocolPluginSvc(WPARAM,LPARAM); - -//Removes plugin from queue and deletes registration structures -INT_PTR UnregisterProtocolPlugin(HYAMNPROTOPLUGIN Plugin); - -INT_PTR UnregisterProtocolPluginSvc(WPARAM,LPARAM); - -//Removes plugins from queue and deletes registration structures -INT_PTR UnregisterProtoPlugins(); - -//Sets imported functions for an plugin and therefore it starts plugin to be registered and running -// Plugin- plugin, which wants to set its functions -// YAMNFcn- pointer to imported functions with accounts -// YAMNFcnVer- version of YAMN_PROTOIMPORTFCN, use YAMN_PROTOIMPORTFCNVERSION -// YAMNMailFcn- pointer to imported functions with mails -// YAMNMailFcnVer- version of YAMN_MAILIMPORTFCN, use YAMN_MAILIMPORTFCNVERSION -// returns nonzero if success -int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin,PYAMN_PROTOIMPORTFCN YAMNFcn,DWORD YAMNFcnVer,PYAMN_MAILIMPORTFCN YAMNMailFcn,DWORD YAMNMailFcnVer); - -struct CExportedFunctions ProtoPluginExportedFcn[]= -{ - {YAMN_SETPROTOCOLPLUGINFCNIMPORTID,(void *)SetProtocolPluginFcnImportFcn}, -}; - -struct CExportedServices ProtoPluginExportedSvc[]= -{ - {MS_YAMN_REGISTERPROTOPLUGIN,RegisterProtocolPluginSvc}, - {MS_YAMN_UNREGISTERPROTOPLUGIN,UnregisterProtocolPluginSvc}, - {MS_YAMN_GETFILENAME,GetFileNameSvc}, - {MS_YAMN_DELETEFILENAME,DeleteFileNameSvc}, -}; - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -INT_PTR RegisterProtocolPluginSvc(WPARAM wParam,LPARAM lParam) -{ - PYAMN_PROTOREGISTRATION Registration=(PYAMN_PROTOREGISTRATION)wParam; - HYAMNPROTOPLUGIN Plugin; - - if (lParam!=YAMN_PROTOREGISTRATIONVERSION) - return 0; - if ((Registration->Name==NULL) || (Registration->Ver==NULL)) - return (INT_PTR)NULL; - if (NULL==(Plugin=new YAMN_PROTOPLUGIN)) - return (INT_PTR)NULL; - - Plugin->PluginInfo=Registration; - - Plugin->FirstAccount=NULL; - - Plugin->AccountBrowserSO=new SWMRG; - SWMRGInitialize(Plugin->AccountBrowserSO,NULL); - - Plugin->Fcn=NULL; - Plugin->MailFcn=NULL; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- new protocol registered: %0x (%s) :::\n",Plugin,Registration->Name); -#endif - return (INT_PTR)Plugin; -} - -int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin,PYAMN_PROTOIMPORTFCN YAMNFcn,DWORD YAMNFcnVer,PYAMN_MAILIMPORTFCN YAMNMailFcn,DWORD YAMNMailFcnVer) -{ - PYAMN_PROTOPLUGINQUEUE Parser; - - if (YAMNFcnVer!=YAMN_PROTOIMPORTFCNVERSION) - return 0; - if (YAMNMailFcnVer!=YAMN_MAILIMPORTFCNVERSION) - return 0; - if (YAMNFcn==NULL) - return 0; - if (YAMNMailFcn==NULL) - return 0; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- protocol %0x import succeed :::\n",Plugin); -#endif - Plugin->Fcn=YAMNFcn; - Plugin->MailFcn=YAMNMailFcn; - - EnterCriticalSection(&PluginRegCS); -//We add protocol to the protocol list - for (Parser=FirstProtoPlugin;Parser!=NULL && Parser->Next!=NULL;Parser=Parser->Next); - if (Parser==NULL) - { - FirstProtoPlugin=new YAMN_PROTOPLUGINQUEUE; - Parser=FirstProtoPlugin; - } - else - { - Parser->Next=new YAMN_PROTOPLUGINQUEUE; - Parser=Parser->Next; - } - - Parser->Plugin=Plugin; - Parser->Next=NULL; - - LeaveCriticalSection(&PluginRegCS); - return 1; -} - -INT_PTR UnregisterProtocolPlugin(HYAMNPROTOPLUGIN Plugin) -{ - PYAMN_PROTOPLUGINQUEUE Parser,Found; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"Entering UnregisterProtocolPlugin\n"); -#endif - if (FirstProtoPlugin->Plugin==Plugin) - { - Found=FirstProtoPlugin; - FirstProtoPlugin=FirstProtoPlugin->Next; - } - else - { - for (Parser=FirstProtoPlugin;(Parser->Next!=NULL) && (Plugin!=Parser->Next->Plugin);Parser=Parser->Next); - if (Parser->Next!=NULL) - { - Found=Parser->Next; - Parser->Next=Parser->Next->Next; - } - else - Found=NULL; - } - if (Found!=NULL) - { - StopAccounts(Plugin); - DeleteAccounts(Plugin); - if (Plugin->Fcn->UnLoadFcn!=NULL) - Plugin->Fcn->UnLoadFcn((void *)0); - - delete Found->Plugin->AccountBrowserSO; - delete Found->Plugin; - delete Found; - -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"::: YAMN- protocol %0x unregistered :::\n",Plugin); -#endif - } - else - return 0; - return 1; -} - -INT_PTR UnregisterProtocolPluginSvc(WPARAM wParam,LPARAM lParam) -{ - HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; - - EnterCriticalSection(&PluginRegCS); - UnregisterProtocolPlugin(Plugin); - LeaveCriticalSection(&PluginRegCS); - return 1; - -} - -INT_PTR UnregisterProtoPlugins() -{ - EnterCriticalSection(&PluginRegCS); -//We remove protocols from the protocol list - while(FirstProtoPlugin!=NULL) - UnregisterProtocolPlugin(FirstProtoPlugin->Plugin); - LeaveCriticalSection(&PluginRegCS); - return 1; -} - -INT_PTR GetFileNameSvc(WPARAM wParam,LPARAM) -{ - TCHAR *FileName = new TCHAR[MAX_PATH]; - if (FileName == NULL) - return NULL; - - mir_sntprintf(FileName, MAX_PATH, _T("%s\\yamn-accounts.%s.%s.book"), UserDirectory, wParam, ProfileName); - return (INT_PTR)FileName; -} - -INT_PTR DeleteFileNameSvc(WPARAM wParam,LPARAM) -{ - if (( TCHAR* )wParam != NULL) - delete[] ( TCHAR* ) wParam; - - return 0; -} diff --git a/protocols/YAMN/res/YAMN.rc b/protocols/YAMN/res/YAMN.rc new file mode 100644 index 0000000000..a002fe7ef8 --- /dev/null +++ b/protocols/YAMN/res/YAMN.rc @@ -0,0 +1,337 @@ +// Microsoft Visual C++ generated resource script. +// +#include "..\src\resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Neutral resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +#pragma code_page(1251) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "..\\src\\resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_DLGVIEWMESSAGES, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 455 + TOPMARGIN, 5 + BOTTOMMARGIN, 105 + END + + IDD_DLGSHOWMESSAGE, DIALOG + BEGIN + END + + IDD_DLGBADCONNECT, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 179 + TOPMARGIN, 7 + BOTTOMMARGIN, 43 + END + + IDD_PLUGINOPT, DIALOG + BEGIN + LEFTMARGIN, 7 + VERTGUIDE, 13 + VERTGUIDE, 85 + VERTGUIDE, 160 + VERTGUIDE, 307 + TOPMARGIN, 4 + HORZGUIDE, 5 + HORZGUIDE, 20 + HORZGUIDE, 147 + HORZGUIDE, 157 + HORZGUIDE, 173 + HORZGUIDE, 184 + HORZGUIDE, 207 + HORZGUIDE, 217 + END + + IDD_POP3ACCOUNTOPT, DIALOG + BEGIN + VERTGUIDE, 155 + VERTGUIDE, 236 + END + + IDD_CHOOSESTATUSMODES, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 219 + TOPMARGIN, 7 + BOTTOMMARGIN, 147 + END + + IDD_YAMNOPT, DIALOG + BEGIN + RIGHTMARGIN, 310 + VERTGUIDE, 8 + END + + IDD_POP3ACCOUNTPOPUP, DIALOG + BEGIN + VERTGUIDE, 155 + VERTGUIDE, 236 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_DLGVIEWMESSAGES DIALOG 50, 200, 460, 110 +STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +FONT 8, "MS Shell Dlg" +BEGIN + CONTROL "List4",IDC_LISTMAILS,"SysListView32",LVS_REPORT | LVS_EDITLABELS | WS_BORDER | WS_TABSTOP,5,5,450,70 + DEFPUSHBUTTON "",IDC_BTNOK,395,90,60,15 + PUSHBUTTON "",IDC_BTNAPP,263,90,114,15 + PUSHBUTTON "",IDC_BTNDEL,5,90,114,15 + LTEXT "",IDC_STSTATUS,5,75,450,10 + PUSHBUTTON "",IDC_BTNCHECKALL,150,91,92,14 +END + +IDD_DLGSHOWMESSAGE DIALOGEX 50, 200, 460, 132 +STYLE DS_SETFONT | DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + CONTROL "List5",IDC_LISTHEADERS,"SysListView32",LVS_REPORT | LVS_EDITLABELS | WS_BORDER | WS_TABSTOP,5,5,450,70 + CONTROL "",IDC_SPLITTER,"Static",SS_ENHMETAFILE | WS_TABSTOP,0,80,187,2,WS_EX_STATICEDGE + EDITTEXT IDC_EDITBODY,3,84,454,45,ES_MULTILINE | ES_READONLY | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL +END + +IDD_DLGBADCONNECT DIALOG 0, 0, 186, 76 +STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +FONT 8, "MS Shell Dlg" +BEGIN + DEFPUSHBUTTON "OK",IDC_BTNOK,69,55,50,14 + LTEXT "",IDC_STATICMSG,7,7,172,37 +END + +IDD_PLUGINOPT DIALOGEX 0, 0, 310, 231 +STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_VISIBLE | WS_BORDER +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "Installed plugins",IDC_STATIC,7,5,300,142 + COMBOBOX IDC_COMBOPLUGINS,13,14,287,58,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Version:",IDC_STATIC,13,30,72,11 + EDITTEXT IDC_STVER,85,30,215,12,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_GROUP + LTEXT "Description:",IDC_STATIC,13,41,72,23 + EDITTEXT IDC_STDESC,85,41,215,23,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_GROUP + LTEXT "Copyright:",IDC_STATIC,13,64,72,10 + EDITTEXT IDC_STCOPY,85,63,215,12,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_GROUP + LTEXT "Contact:",IDC_STATIC,13,77,72,11 + EDITTEXT IDC_STMAIL,85,76,214,12,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_GROUP + LTEXT "WWW:",IDC_STATIC,13,101,72,11 + CONTROL "",IDC_STWWW,"Hyperlink",WS_TABSTOP,85,101,215,11 +END + +IDD_POP3ACCOUNTOPT DIALOGEX 0, 0, 310, 230 +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,6,106,65,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP + CONTROL "Check this account",IDC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,167,32,118,10,WS_EX_TRANSPARENT + LTEXT "Check interval [min]:",IDC_STINTERVAL,168,56,94,8 + EDITTEXT IDC_EDITINTERVAL,259,53,20,12,ES_AUTOHSCROLL | ES_NUMBER,WS_EX_TRANSPARENT + GROUPBOX "Notifications",IDC_GBNEWMAIL,4,143,304,87 + CONTROL "Sound",IDC_CHECKSND,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,12,162,60,10 + CONTROL "Message",IDC_CHECKMSG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,174,135,10 + CONTROL "Tray Icon",IDC_CHECKICO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,85,163,65,10 + CONTROL "Keyboard Flash",IDC_CHECKKBN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,186,132,9 + CONTROL "Execute Application",IDC_CHECKAPP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,198,135,8 + PUSHBUTTON "...",IDC_BTNAPP,19,209,16,12 + EDITTEXT IDC_EDITAPP,41,209,65,12,ES_AUTOHSCROLL + EDITTEXT IDC_EDITAPPPARAM,111,209,40,12,ES_AUTOHSCROLL + CONTROL "Use contact notification for this account",IDC_CHECKCONTACT, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,166,107,138,10,WS_EX_TRANSPARENT + CONTROL "Replace nick name",IDC_CHECKCONTACTNICK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,187,117,117,10,WS_EX_TRANSPARENT + CONTROL "Disable Events",IDC_CHECKCONTACTNOEVENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,187,128,115,10,WS_EX_TRANSPARENT + LTEXT "",IDC_STSTATUS,218,9,88,8 + LTEXT "Server:",IDC_STSERVER,10,50,44,8 + EDITTEXT IDC_EDITSERVER,56,48,92,12,ES_AUTOHSCROLL | WS_GROUP + LTEXT "User Name:",IDC_STLOGIN,10,82,44,8 + EDITTEXT IDC_EDITLOGIN,57,80,92,12,ES_AUTOHSCROLL | WS_GROUP + LTEXT "Password:",IDC_STPASS,10,96,44,8 + EDITTEXT IDC_EDITPASS,57,94,92,12,ES_PASSWORD | ES_AUTOHSCROLL | WS_GROUP + LTEXT "Codepage:",IDC_STCP,10,111,44,8 + COMBOBOX IDC_COMBOCP,57,108,92,130,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP + LTEXT "Port:",IDC_STPORT,10,65,44,8,SS_CENTERIMAGE + EDITTEXT IDC_EDITPORT,57,64,27,12,ES_AUTOHSCROLL | ES_NUMBER | WS_GROUP + CONTROL "SSL",IDC_CHECKSSL,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,87,66,27,10 + CONTROL "Disable STLS",IDC_CHECKNOTLS,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,83,125,69,10 + CONTROL "Startup check",IDC_CHECKSTART,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,167,43,78,10 + CONTROL "Auto retrieve body",IDC_AUTOBODY,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,166,86,137,10 + CONTROL "Check from menu",IDC_CHECKFORCE,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,166,97,137,8 + PUSHBUTTON "Only check when ...",IDC_BTNSTATUS,195,69,81,13 + CONTROL "Sound notification if failed",IDC_CHECKFSND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,166,163,135,10 + CONTROL "Message notification if failed",IDC_CHECKFMSG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,166,174,135,10 + CONTROL "Tray icon notification if failed",IDC_CHECKFICO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,166,186,135,10 + PUSHBUTTON "Reset counter",IDC_BTNRESET,161,200,75,13 + PUSHBUTTON "-",IDC_BTNDEL,140,6,15,13 + PUSHBUTTON "Default",IDC_BTNDEFAULT,9,124,54,13 + LTEXT "",IDC_STTIMELEFT,163,216,141,8 + LTEXT "Status:",IDC_STATIC,175,9,34,9 + PUSHBUTTON "+",IDC_BTNADD,118,6,15,13 + GROUPBOX "Account",IDC_STATIC,4,22,151,120 + CONTROL "APOP",IDC_CHECKAPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,119,66,34,10 + LTEXT "Name:",IDC_STATIC,10,34,44,10 + EDITTEXT IDC_EDITNAME,56,32,92,12,ES_AUTOHSCROLL + GROUPBOX "Options",IDC_STATIC,161,22,147,120 + GROUPBOX "New Mail",IDC_STATIC,7,153,149,73 + GROUPBOX "Errors",IDC_STATIC,161,153,143,44 +END + +IDD_CHOOSESTATUSMODES DIALOG 0, 0, 226, 154 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Check while ..." +FONT 8, "MS Shell Dlg" +BEGIN + DEFPUSHBUTTON "OK",IDOK,112,133,50,14 + PUSHBUTTON "Cancel",IDCANCEL,169,133,50,14 + GROUPBOX "Choose modes",IDC_STATUSGROUP,7,7,212,119 + CONTROL "Offline",IDC_CHECKST0,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,19,70,9 + CONTROL "Online",IDC_CHECKST1,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,39,70,9 + CONTROL "Away",IDC_CHECKST2,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,62,70,9 + CONTROL "N/A",IDC_CHECKST3,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,83,70,9 + CONTROL "Occupied",IDC_CHECKST4,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,104,70,9 + CONTROL "DND",IDC_CHECKST5,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,19,70,9 + CONTROL "Free for chat",IDC_CHECKST6,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,39,70,9 + CONTROL "Invisible",IDC_CHECKST7,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,62,70,9 + CONTROL "On the phone",IDC_CHECKST8,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,83,70,9 + CONTROL "Out to lunch",IDC_CHECKST9,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,104,70,9 +END + +IDD_YAMNOPT DIALOGEX 0, 0, 312, 121 +STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_VISIBLE | WS_BORDER +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "YAMN General Options",IDC_STATIC,3,2,303,65 + CONTROL "TopToolBar button ""Check mail""",IDC_CHECKTTB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,15,294,11 + CONTROL "Enable YAMN Main Menu",IDC_MAINMENU,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,33,293,9 + CONTROL "Show YAMN as a Protocol (Require Restart)",IDC_YAMNASPROTO, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,50,293,9 + + GROUPBOX "MailBrowser Options",IDC_STATIC,3,68,151,47 + CONTROL "Enable Close on Delete Button",IDC_CLOSEONDELETE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,80,143,11 + CONTROL "Show long localised date",IDC_LONGDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,77,130,10 + CONTROL "Don't show today's date",IDC_SMARTDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,89,131,10 + + GROUPBOX "Date/Time Representation",IDC_STATIC,166,68,141,47 + CONTROL "Don't show seconds",IDC_NOSECONDS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,101,129,8 +END + +IDD_POP3ACCOUNTPOPUP DIALOGEX 0, 0, 315, 230 +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 + 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 + CONTROL "Use custom colour",IDC_CHECKCOL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,83,107,10 + 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 + CONTROL "Popup if no mail",IDC_CHECKNPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,161,94,10 + CONTROL "Persistant message",IDC_CHECKNMSGP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,188,110,10 + CONTROL "Use custom colour",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 + CONTROL "Popup notification if failed",IDC_CHECKFPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,110,118,10 + CONTROL "Use custom colour",IDC_CHECKFCOL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,136,95,10 + CONTROL "",IDC_CPFB,"ColourPicker",WS_TABSTOP,145,118,29,12 + CONTROL "",IDC_CPFT,"ColourPicker",WS_TABSTOP,145,134,29,12 + EDITTEXT IDC_EDITFPOPS,23,121,20,12,ES_AUTOHSCROLL + LTEXT "..s Popup duration",IDC_STATIC,45,67,70,8 + LTEXT "..s Popup duration",IDC_STATIC,45,176,70,8 + LTEXT "..s Popup duration",IDC_STATIC,45,122,70,8 + PUSHBUTTON "Preview",IDC_PREVIEW,255,215,49,13 + LTEXT "Background colour",IDC_STATIC,177,184,108,10 + LTEXT "Text colour",IDC_STATIC,177,200,107,10 + LTEXT "Background colour",IDC_STATIC,177,120,108,10 + LTEXT "Text colour",IDC_STATIC,177,136,107,10 + LTEXT "Background colour",IDC_STATIC,177,69,108,10 + LTEXT "Text colour",IDC_STATIC,177,85,107,10 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_ONLINE ICON "iconeutral.ico" +IDI_OFFLINE ICON "icooffline.ico" +IDI_NA ICON "icoyamn3.ico" +IDI_OCCUPIED ICON "iconttbdown.ico" +#endif // Neutral resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/protocols/YAMN/res/iconeutral.ico b/protocols/YAMN/res/iconeutral.ico new file mode 100644 index 0000000000..a99cbe0a60 Binary files /dev/null and b/protocols/YAMN/res/iconeutral.ico differ diff --git a/protocols/YAMN/res/iconttbdown.ico b/protocols/YAMN/res/iconttbdown.ico new file mode 100644 index 0000000000..81dd9fe467 Binary files /dev/null and b/protocols/YAMN/res/iconttbdown.ico differ diff --git a/protocols/YAMN/res/icooffline.ico b/protocols/YAMN/res/icooffline.ico new file mode 100644 index 0000000000..78f925ede7 Binary files /dev/null and b/protocols/YAMN/res/icooffline.ico differ diff --git a/protocols/YAMN/res/icoyamn3.ico b/protocols/YAMN/res/icoyamn3.ico new file mode 100644 index 0000000000..78f925ede7 Binary files /dev/null and b/protocols/YAMN/res/icoyamn3.ico differ diff --git a/protocols/YAMN/res/yamn_ver.rc b/protocols/YAMN/res/yamn_ver.rc new file mode 100644 index 0000000000..84d27568b6 --- /dev/null +++ b/protocols/YAMN/res/yamn_ver.rc @@ -0,0 +1,76 @@ +// Microsoft Visual C++ generated resource script. +// + +#include "..\src\version.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Neutral resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) +#ifdef _WIN32 +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 0,1,2,5 + PRODUCTVERSION 0,1,2,5 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "Comments", "Yet Another Mail Notifier" + VALUE "FileDescription", "Yet Another Mail Notifier" + VALUE "FileVersion", YAMN_VERSION_C + VALUE "InternalName", "YAMN" + VALUE "LegalCopyright", "Copyright © 2007" + VALUE "OriginalFilename", "YAMN.dll" + VALUE "ProductName", "YAMN tweety" + VALUE "ProductVersion", YAMN_VERSION_C + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END + +#endif // Neutral resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/protocols/YAMN/resources/YAMN.rc b/protocols/YAMN/resources/YAMN.rc deleted file mode 100644 index 54320549e4..0000000000 --- a/protocols/YAMN/resources/YAMN.rc +++ /dev/null @@ -1,344 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Neutral resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -#pragma code_page(1251) - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_DLGVIEWMESSAGES, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 455 - TOPMARGIN, 5 - BOTTOMMARGIN, 105 - END - - IDD_DLGSHOWMESSAGE, DIALOG - BEGIN - END - - IDD_DLGBADCONNECT, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 179 - TOPMARGIN, 7 - BOTTOMMARGIN, 43 - END - - IDD_PLUGINOPT, DIALOG - BEGIN - LEFTMARGIN, 7 - VERTGUIDE, 13 - VERTGUIDE, 85 - VERTGUIDE, 160 - VERTGUIDE, 307 - TOPMARGIN, 4 - HORZGUIDE, 5 - HORZGUIDE, 20 - HORZGUIDE, 147 - HORZGUIDE, 157 - HORZGUIDE, 173 - HORZGUIDE, 184 - HORZGUIDE, 207 - HORZGUIDE, 217 - END - - IDD_POP3ACCOUNTOPT, DIALOG - BEGIN - VERTGUIDE, 155 - VERTGUIDE, 236 - END - - IDD_CHOOSESTATUSMODES, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 219 - TOPMARGIN, 7 - BOTTOMMARGIN, 147 - END - - IDD_YAMNOPT, DIALOG - BEGIN - RIGHTMARGIN, 310 - VERTGUIDE, 8 - END - - IDD_POP3ACCOUNTPOPUP, DIALOG - BEGIN - VERTGUIDE, 155 - VERTGUIDE, 236 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_DLGVIEWMESSAGES DIALOG 50, 200, 460, 110 -STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME -FONT 8, "MS Shell Dlg" -BEGIN - CONTROL "List4",IDC_LISTMAILS,"SysListView32",LVS_REPORT | LVS_EDITLABELS | WS_BORDER | WS_TABSTOP,5,5,450,70 - DEFPUSHBUTTON "",IDC_BTNOK,395,90,60,15 - PUSHBUTTON "",IDC_BTNAPP,263,90,114,15 - PUSHBUTTON "",IDC_BTNDEL,5,90,114,15 - LTEXT "",IDC_STSTATUS,5,75,450,10 - PUSHBUTTON "",IDC_BTNCHECKALL,150,91,92,14 -END - -IDD_DLGSHOWMESSAGE DIALOGEX 50, 200, 460, 132 -STYLE DS_SETFONT | DS_3DLOOK | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - CONTROL "List5",IDC_LISTHEADERS,"SysListView32",LVS_REPORT | LVS_EDITLABELS | WS_BORDER | WS_TABSTOP,5,5,450,70 - CONTROL "",IDC_SPLITTER,"Static",SS_ENHMETAFILE | WS_TABSTOP,0,80,187,2,WS_EX_STATICEDGE - EDITTEXT IDC_EDITBODY,3,84,454,45,ES_MULTILINE | ES_READONLY | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL -END - -IDD_DLGBADCONNECT DIALOG 0, 0, 186, 76 -STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -FONT 8, "MS Shell Dlg" -BEGIN - DEFPUSHBUTTON "OK",IDC_BTNOK,69,55,50,14 - LTEXT "",IDC_STATICMSG,7,7,172,37 -END - -IDD_PLUGINOPT DIALOGEX 0, 0, 310, 231 -STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_VISIBLE | WS_BORDER -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - GROUPBOX "Installed plugins",IDC_STATIC,7,5,300,142 - COMBOBOX IDC_COMBOPLUGINS,13,14,287,58,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Version:",IDC_STATIC,13,30,72,11 - EDITTEXT IDC_STVER,85,30,215,12,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_GROUP - LTEXT "Description:",IDC_STATIC,13,41,72,23 - EDITTEXT IDC_STDESC,85,41,215,23,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_GROUP - LTEXT "Copyright:",IDC_STATIC,13,64,72,10 - EDITTEXT IDC_STCOPY,85,63,215,12,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_GROUP - LTEXT "Contact:",IDC_STATIC,13,77,72,11 - EDITTEXT IDC_STMAIL,85,76,214,12,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_GROUP - LTEXT "WWW:",IDC_STATIC,13,101,72,11 - CONTROL "",IDC_STWWW,"Hyperlink",WS_TABSTOP,85,101,215,11 -END - -IDD_POP3ACCOUNTOPT DIALOGEX 0, 0, 310, 230 -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,6,106,65,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP - CONTROL "Check this account",IDC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,167,32,118,10,WS_EX_TRANSPARENT - LTEXT "Check interval [min]:",IDC_STINTERVAL,168,56,94,8 - EDITTEXT IDC_EDITINTERVAL,259,53,20,12,ES_AUTOHSCROLL | ES_NUMBER,WS_EX_TRANSPARENT - GROUPBOX "Notifications",IDC_GBNEWMAIL,4,143,304,87 - CONTROL "Sound",IDC_CHECKSND,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,12,162,60,10 - CONTROL "Message",IDC_CHECKMSG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,174,135,10 - CONTROL "Tray Icon",IDC_CHECKICO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,85,163,65,10 - CONTROL "Keyboard Flash",IDC_CHECKKBN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,186,132,9 - CONTROL "Execute Application",IDC_CHECKAPP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,198,135,8 - PUSHBUTTON "...",IDC_BTNAPP,19,209,16,12 - EDITTEXT IDC_EDITAPP,41,209,65,12,ES_AUTOHSCROLL - EDITTEXT IDC_EDITAPPPARAM,111,209,40,12,ES_AUTOHSCROLL - CONTROL "Use contact notification for this account",IDC_CHECKCONTACT, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,166,107,138,10,WS_EX_TRANSPARENT - CONTROL "Replace nick name",IDC_CHECKCONTACTNICK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,187,117,117,10,WS_EX_TRANSPARENT - CONTROL "Disable Events",IDC_CHECKCONTACTNOEVENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,187,128,115,10,WS_EX_TRANSPARENT - LTEXT "",IDC_STSTATUS,218,9,88,8 - LTEXT "Server:",IDC_STSERVER,10,50,44,8 - EDITTEXT IDC_EDITSERVER,56,48,92,12,ES_AUTOHSCROLL | WS_GROUP - LTEXT "User Name:",IDC_STLOGIN,10,82,44,8 - EDITTEXT IDC_EDITLOGIN,57,80,92,12,ES_AUTOHSCROLL | WS_GROUP - LTEXT "Password:",IDC_STPASS,10,96,44,8 - EDITTEXT IDC_EDITPASS,57,94,92,12,ES_PASSWORD | ES_AUTOHSCROLL | WS_GROUP - LTEXT "Codepage:",IDC_STCP,10,111,44,8 - COMBOBOX IDC_COMBOCP,57,108,92,130,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP - LTEXT "Port:",IDC_STPORT,10,65,44,8,SS_CENTERIMAGE - EDITTEXT IDC_EDITPORT,57,64,27,12,ES_AUTOHSCROLL | ES_NUMBER | WS_GROUP - CONTROL "SSL",IDC_CHECKSSL,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,87,66,27,10 - CONTROL "Disable STLS",IDC_CHECKNOTLS,"Button",BS_AUTOCHECKBOX | BS_LEFT | WS_TABSTOP,83,125,69,10 - CONTROL "Startup check",IDC_CHECKSTART,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,167,43,78,10 - CONTROL "Auto retrieve body",IDC_AUTOBODY,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,166,86,137,10 - CONTROL "Check from menu",IDC_CHECKFORCE,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,166,97,137,8 - PUSHBUTTON "Only check when ...",IDC_BTNSTATUS,195,69,81,13 - CONTROL "Sound notification if failed",IDC_CHECKFSND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,166,163,135,10 - CONTROL "Message notification if failed",IDC_CHECKFMSG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,166,174,135,10 - CONTROL "Tray icon notification if failed",IDC_CHECKFICO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,166,186,135,10 - PUSHBUTTON "Reset counter",IDC_BTNRESET,161,200,75,13 - PUSHBUTTON "-",IDC_BTNDEL,140,6,15,13 - PUSHBUTTON "Default",IDC_BTNDEFAULT,9,124,54,13 - LTEXT "",IDC_STTIMELEFT,163,216,141,8 - LTEXT "Status:",IDC_STATIC,175,9,34,9 - PUSHBUTTON "+",IDC_BTNADD,118,6,15,13 - GROUPBOX "Account",IDC_STATIC,4,22,151,120 - CONTROL "APOP",IDC_CHECKAPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,119,66,34,10 - LTEXT "Name:",IDC_STATIC,10,34,44,10 - EDITTEXT IDC_EDITNAME,56,32,92,12,ES_AUTOHSCROLL - GROUPBOX "Options",IDC_STATIC,161,22,147,120 - GROUPBOX "New Mail",IDC_STATIC,7,153,149,73 - GROUPBOX "Errors",IDC_STATIC,161,153,143,44 -END - -IDD_CHOOSESTATUSMODES DIALOG 0, 0, 226, 154 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Check while ..." -FONT 8, "MS Shell Dlg" -BEGIN - DEFPUSHBUTTON "OK",IDOK,112,133,50,14 - PUSHBUTTON "Cancel",IDCANCEL,169,133,50,14 - GROUPBOX "Choose modes",IDC_STATUSGROUP,7,7,212,119 - CONTROL "Offline",IDC_CHECKST0,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,19,70,9 - CONTROL "Online",IDC_CHECKST1,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,39,70,9 - CONTROL "Away",IDC_CHECKST2,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,62,70,9 - CONTROL "N/A",IDC_CHECKST3,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,83,70,9 - CONTROL "Occupied",IDC_CHECKST4,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,15,104,70,9 - CONTROL "DND",IDC_CHECKST5,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,19,70,9 - CONTROL "Free for chat",IDC_CHECKST6,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,39,70,9 - CONTROL "Invisible",IDC_CHECKST7,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,62,70,9 - CONTROL "On the phone",IDC_CHECKST8,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,83,70,9 - CONTROL "Out to lunch",IDC_CHECKST9,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,134,104,70,9 -END - -IDD_YAMNOPT DIALOGEX 0, 0, 312, 121 -STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_VISIBLE | WS_BORDER -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - GROUPBOX "YAMN General Options",IDC_STATIC,3,2,303,65 - CONTROL "TopToolBar button ""Check mail""",IDC_CHECKTTB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,15,294,11 - CONTROL "Enable YAMN Main Menu",IDC_MAINMENU,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,33,293,9 - CONTROL "Show YAMN as a Protocol (Require Restart)",IDC_YAMNASPROTO, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,50,293,9 - - GROUPBOX "MailBrowser Options",IDC_STATIC,3,68,151,47 - CONTROL "Enable Close on Delete Button",IDC_CLOSEONDELETE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,80,143,11 - CONTROL "Show long localised date",IDC_LONGDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,77,130,10 - CONTROL "Don't show today's date",IDC_SMARTDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,89,131,10 - - GROUPBOX "Date/Time Representation",IDC_STATIC,166,68,141,47 - CONTROL "Don't show seconds",IDC_NOSECONDS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,101,129,8 -END - -IDD_POP3ACCOUNTPOPUP DIALOGEX 0, 0, 315, 230 -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 - 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 - CONTROL "Use custom colour",IDC_CHECKCOL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,83,107,10 - 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 - CONTROL "Popup if no mail",IDC_CHECKNPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,161,94,10 - CONTROL "Persistant message",IDC_CHECKNMSGP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,188,110,10 - CONTROL "Use custom colour",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 - CONTROL "Popup notification if failed",IDC_CHECKFPOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,110,118,10 - CONTROL "Use custom colour",IDC_CHECKFCOL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,136,95,10 - CONTROL "",IDC_CPFB,"ColourPicker",WS_TABSTOP,145,118,29,12 - CONTROL "",IDC_CPFT,"ColourPicker",WS_TABSTOP,145,134,29,12 - EDITTEXT IDC_EDITFPOPS,23,121,20,12,ES_AUTOHSCROLL - LTEXT "..s Popup duration",IDC_STATIC,45,67,70,8 - LTEXT "..s Popup duration",IDC_STATIC,45,176,70,8 - LTEXT "..s Popup duration",IDC_STATIC,45,122,70,8 - PUSHBUTTON "Preview",IDC_PREVIEW,255,215,49,13 - LTEXT "Background colour",IDC_STATIC,177,184,108,10 - LTEXT "Text colour",IDC_STATIC,177,200,107,10 - LTEXT "Background colour",IDC_STATIC,177,120,108,10 - LTEXT "Text colour",IDC_STATIC,177,136,107,10 - LTEXT "Background colour",IDC_STATIC,177,69,108,10 - LTEXT "Text colour",IDC_STATIC,177,85,107,10 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ONLINE ICON "iconeutral.ico" -IDI_OFFLINE ICON "icooffline.ico" -IDI_NA ICON "icoyamn3.ico" -IDI_OCCUPIED ICON "iconttbdown.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Bitmap -// - -IDB_ICONS BITMAP "yamn.bmp" -#endif // Neutral resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED diff --git a/protocols/YAMN/resources/iconeutral.ico b/protocols/YAMN/resources/iconeutral.ico deleted file mode 100644 index 9304f4334a..0000000000 Binary files a/protocols/YAMN/resources/iconeutral.ico and /dev/null differ diff --git a/protocols/YAMN/resources/iconttbdown.ico b/protocols/YAMN/resources/iconttbdown.ico deleted file mode 100644 index 206eba2c76..0000000000 Binary files a/protocols/YAMN/resources/iconttbdown.ico and /dev/null differ diff --git a/protocols/YAMN/resources/icooffline.ico b/protocols/YAMN/resources/icooffline.ico deleted file mode 100644 index db5b2e18fa..0000000000 Binary files a/protocols/YAMN/resources/icooffline.ico and /dev/null differ diff --git a/protocols/YAMN/resources/icoyamn3.ico b/protocols/YAMN/resources/icoyamn3.ico deleted file mode 100644 index ca11f0f4f4..0000000000 Binary files a/protocols/YAMN/resources/icoyamn3.ico and /dev/null differ diff --git a/protocols/YAMN/resources/resource.h b/protocols/YAMN/resources/resource.h deleted file mode 100644 index 8bfd74c9a3..0000000000 --- a/protocols/YAMN/resources/resource.h +++ /dev/null @@ -1,129 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by YAMN.rc -// -#define IDI_ONLINE 104 -#define IDI_OFFLINE 105 -#define IDD_DLGVIEWMESSAGES 107 -#define IDD_DLGSHOWMESSAGE 108 -#define IDI_ICOYAMN2 112 -#define IDI_ICOYAMN1 113 -#define IDD_DLGBADCONNECT 115 -#define IDD_POP3ACCOUNTOPT 121 -#define IDD_YAMNOPT 126 -#define IDB_ICONS 127 -#define IDI_NA 131 -#define IDI_ICOTTBUP 138 -#define IDD_PLUGINOPT 141 -#define IDI_OCCUPIED 159 -#define IDD_CHOOSESTATUSMODES 310 -#define IDD_OPTIONS 311 -#define IDD_POP3ACCOUNTPOPUP 312 -#define IDC_EDITSERVER 1000 -#define IDC_EDITPORT 1001 -#define IDC_EDITLOGIN 1002 -#define IDC_EDITPASS 1003 -#define IDC_COMBOACCOUNT 1005 -#define IDC_BTNDEFAULT 1006 -#define IDC_EDITINTERVAL 1007 -#define IDC_CHECKSND 1008 -#define IDC_CHECKMSG 1009 -#define IDC_CHECKAPP 1010 -#define IDC_BTNAPP 1011 -#define IDC_CHECKICO 1012 -#define IDC_CHECK 1013 -#define IDC_BTNDEL 1014 -#define IDC_STSERVER 1015 -#define IDC_CHECKFSND 1016 -#define IDC_CHECKFMSG 1017 -#define IDC_CHECKFICO 1018 -#define IDC_CHECKST0 1019 -#define IDC_CHECKST1 1020 -#define IDC_CHECKST2 1021 -#define IDC_CHECKST3 1022 -#define IDC_CHECKST4 1023 -#define IDC_CHECKST5 1024 -#define IDC_CHECKST6 1025 -#define IDC_CHECKST7 1026 -#define IDC_EDITAPP 1027 -#define IDC_CHECKST8 1028 -#define IDC_CHECKST9 1029 -#define IDC_CHECKCONTACT 1030 -#define IDC_CHECKCONTACTNICK 1031 -#define IDC_CHECKCONTACTNOEVENT 1032 -#define IDC_STTIMELEFT 1033 -#define IDC_LISTMAILS 1038 -#define IDC_LISTHEADERS 1039 -#define IDC_EDITAPPPARAM 1044 -#define IDC_BTNOK 1047 -#define IDC_COMBOCP 1050 -#define IDC_STCP 1055 -#define IDC_STATICMSG 1055 -#define IDC_STPORT 1056 -#define IDC_STLOGIN 1057 -#define IDC_STPASS 1058 -#define IDC_STINTERVAL 1059 -#define IDC_AUTOBODY 1062 -#define IDC_BTNRESET 1063 -#define IDC_CHECKSTART 1064 -#define IDC_STWCHECK 1065 -#define IDC_CHECKFORCE 1066 -#define IDC_RADIOPOP1 1068 -#define IDC_RADIOPOPN 1069 -#define IDC_CPB 1070 -#define IDC_CPNB 1071 -#define IDC_CHECKCOL 1073 -#define IDC_CPT 1074 -#define IDC_CPFB 1075 -#define IDC_CPFT 1076 -#define IDC_CHECKFCOL 1077 -#define IDC_CHECKNCOL 1078 -#define IDC_CPNT 1079 -#define IDC_CHECKPOP 1087 -#define IDC_CHECKNPOP 1088 -#define IDC_CHECKFPOP 1089 -#define IDC_EDITPOPS 1090 -#define IDC_EDITNPOPS 1091 -#define IDC_EDITFPOPS 1092 -#define IDC_GBNEWMAIL 1094 -#define IDC_GBNONEWMAIL 1095 -#define IDC_GBBADCONNECT 1096 -#define IDC_STSTATUS 1102 -#define IDC_COMBOPLUGINS 1104 -#define IDC_STWWW 1111 -#define IDC_STMAIL 1113 -#define IDC_STCOPY 1114 -#define IDC_STDESC 1115 -#define IDC_STVER 1116 -#define IDC_CHECKTTB 1117 -#define IDC_CHECKSSL 1117 -#define IDC_CHECKNMSGP 1118 -#define IDC_CHECKNOTLS 1120 -#define IDC_CHECKKBN 1121 -#define IDC_BTNSTATUS 1123 -#define IDC_OPTIONSTAB 1124 -#define IDC_BTNCHECKALL 1125 -#define IDC_MAINMENU 1126 -#define IDC_CLOSEONDELETE 1127 -#define IDC_LONGDATE 1128 -#define IDC_SMARTDATE 1129 -#define IDC_NOSECONDS 1130 -#define IDC_YAMNASPROTO 1131 -#define IDC_CHECKAPOP 1200 -#define IDC_STATUSGROUP 1338 -#define IDC_SPLITTER 1400 -#define IDC_EDITBODY 1401 -#define IDC_PREVIEW 1402 -#define IDC_BTNADD 1403 -#define IDC_EDITNAME 1404 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 143 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1407 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/protocols/YAMN/resources/yamn.bmp b/protocols/YAMN/resources/yamn.bmp deleted file mode 100644 index 91a9e34ddf..0000000000 Binary files a/protocols/YAMN/resources/yamn.bmp and /dev/null differ diff --git a/protocols/YAMN/resources/yamn_ver.rc b/protocols/YAMN/resources/yamn_ver.rc deleted file mode 100644 index e9fb345412..0000000000 --- a/protocols/YAMN/resources/yamn_ver.rc +++ /dev/null @@ -1,77 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// - -#include "resource.h" -#include "../version.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Neutral resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) -#ifdef _WIN32 -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,1,2,5 - PRODUCTVERSION 0,1,2,5 - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x40004L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "Comments", "Yet Another Mail Notifier" - VALUE "FileDescription", "Yet Another Mail Notifier" - VALUE "FileVersion", YAMN_VERSION_C - VALUE "InternalName", "YAMN" - VALUE "LegalCopyright", "Copyright © 2007" - VALUE "OriginalFilename", "YAMN.dll" - VALUE "ProductName", "YAMN tweety" - VALUE "ProductVersion", YAMN_VERSION_C - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END - -#endif // Neutral resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED diff --git a/protocols/YAMN/services.cpp b/protocols/YAMN/services.cpp deleted file mode 100644 index cd01722997..0000000000 --- a/protocols/YAMN/services.cpp +++ /dev/null @@ -1,496 +0,0 @@ - -#include "yamn.h" -#include "main.h" - -extern HANDLE hMenuItemMain, hMenuItemCont, hMenuItemContApp; - -static INT_PTR Service_GetCaps(WPARAM wParam, LPARAM lParam) -{ - if (wParam == PFLAGNUM_4) - return PF4_NOCUSTOMAUTH; - if (wParam == PFLAG_UNIQUEIDTEXT) - return (INT_PTR) Translate("Nick"); - if (wParam == PFLAG_MAXLENOFMESSAGE) - return 400; - if (wParam == PFLAG_UNIQUEIDSETTING) - return (INT_PTR) "Id"; - if (wParam == PFLAGNUM_2) - return PF2_ONLINE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND; - if (wParam == PFLAGNUM_5) { - if (DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWASPROTO, 1)) - return PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND; - return PF2_ONLINE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND; - } - return 0; -} - -static INT_PTR Service_GetStatus(WPARAM wParam, LPARAM lParam) -{ - return YAMN_STATUS; -} - -static INT_PTR Service_SetStatus(WPARAM wParam, LPARAM lParam) -{ - int newstatus = (wParam != ID_STATUS_OFFLINE)?ID_STATUS_ONLINE:ID_STATUS_OFFLINE; - if (newstatus != YAMN_STATUS){ - int oldstatus = YAMN_STATUS; - YAMN_STATUS = newstatus; - ProtoBroadcastAck(YAMN_DBMODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldstatus, newstatus); - } - return 0; - -} - -static INT_PTR Service_GetName(WPARAM wParam, LPARAM lParam) -{ - lstrcpynA((char *) lParam, YAMN_DBMODULE, wParam);; - return 0; -} - -static INT_PTR Service_LoadIcon(WPARAM wParam, LPARAM lParam) -{ - if ( LOWORD( wParam ) == PLI_PROTOCOL ) - return (INT_PTR)CopyIcon(g_LoadIconEx(0)); // noone cares about other than PLI_PROTOCOL - - return (INT_PTR)(HICON)NULL; -} - -INT_PTR ClistContactDoubleclicked(WPARAM wParam, LPARAM lParam) -{ - ContactDoubleclicked(((CLISTEVENT*)lParam)->lParam, lParam); - return 0; -} - -static int Service_ContactDoubleclicked(WPARAM wParam, LPARAM lParam) -{ - ContactDoubleclicked(wParam, lParam); - return 0; -} - -static INT_PTR ContactApplication(WPARAM wParam, LPARAM lParam) -{ - char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); - if ( lstrcmpA(szProto, YAMN_DBMODULE)) - return 0; - - DBVARIANT dbv; - if ( DBGetContactSetting((HANDLE) wParam, YAMN_DBMODULE, "Id", &dbv)) - return 0; - - HACCOUNT ActualAccount = (HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)dbv.pszVal); - if (ActualAccount != NULL) { - STARTUPINFOW si = { 0 }; - si.cb = sizeof(si); - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ContactApplication:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0 == WaitToReadFcn(ActualAccount->AccountAccessSO)) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ContactApplication:ualAccountSO-read enter\n"); - #endif - if (ActualAccount->NewMailN.App != NULL) { - WCHAR *Command; - if (ActualAccount->NewMailN.AppParam != NULL) - Command = new WCHAR[wcslen(ActualAccount->NewMailN.App)+wcslen(ActualAccount->NewMailN.AppParam)+6]; - else - Command = new WCHAR[wcslen(ActualAccount->NewMailN.App)+6]; - - if (Command != NULL) { - lstrcpyW(Command, L"\""); - lstrcatW(Command, ActualAccount->NewMailN.App); - lstrcatW(Command, L"\" "); - if (ActualAccount->NewMailN.AppParam != NULL) - lstrcatW(Command, ActualAccount->NewMailN.AppParam); - - PROCESS_INFORMATION pi; - CreateProcessW(NULL, Command, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi); - delete[] Command; - } - } - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ContactApplication:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - } - #ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile, "ContactApplication:ActualAccountSO-read enter failed\n"); - #endif - } - DBFreeVariant(&dbv); - return 0; -} - -DWORD WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, DWORD dwTimeout); -static INT_PTR AccountMailCheck(WPARAM wParam, LPARAM lParam){ - //This service will check/sincronize the account pointed by wParam - HACCOUNT ActualAccount = (HACCOUNT)wParam; - HANDLE ThreadRunningEV; - DWORD tid; - // copy/paste make mistakes - if (ActualAccount != NULL) { - //we use event to signal, that running thread has all needed stack parameters copied - if (NULL == (ThreadRunningEV = CreateEvent(NULL, FALSE, FALSE, NULL))) - 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; - - EnterCriticalSection(&PluginRegCS); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "AccountCheck:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0 != SWMRGWaitToRead(ActualAccount->AccountAccessSO, 0)) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); - #endif - } - else { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); - #endif - if ((ActualAccount->Flags & YAMN_ACC_ENA) && ActualAccount->Plugin->Fcn->SynchroFcnPtr) { - struct CheckParam ParamToPlugin = {YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, lParam?YAMN_FORCECHECK:YAMN_NORMALCHECK, (void *)0, NULL}; - HANDLE NewThread; - - ActualAccount->TimeLeft = ActualAccount->Interval; - if (NewThread = CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->SynchroFcnPtr, &ParamToPlugin, 0, &tid)) { - WaitForSingleObject(ThreadRunningEV, INFINITE); - CloseHandle(NewThread); - } - } - ReadDoneFcn(ActualAccount->AccountAccessSO); - } - LeaveCriticalSection(&PluginRegCS); - CloseHandle(ThreadRunningEV); - } - return 0; -} - -static INT_PTR ContactMailCheck(WPARAM wParam, LPARAM lParam) -{ - char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); - if ( lstrcmpA(szProto, YAMN_DBMODULE)) - return 0; - - DBVARIANT dbv; - if ( DBGetContactSetting((HANDLE) wParam, YAMN_DBMODULE, "Id", &dbv)) - return 0; - - HACCOUNT ActualAccount = (HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)dbv.pszVal); - if (ActualAccount != NULL) { - //we use event to signal, that running thread has all needed stack parameters copied - HANDLE ThreadRunningEV; - if (NULL == (ThreadRunningEV = CreateEvent(NULL, FALSE, FALSE, NULL))) - 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; - EnterCriticalSection(&PluginRegCS); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); - #endif - } - else - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); - #endif - if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) //account cannot be forced to check - { - if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr == NULL) - ReadDoneFcn(ActualAccount->AccountAccessSO); - - DWORD tid; - struct CheckParam ParamToPlugin = {YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_FORCECHECK, (void *)0, NULL}; - if (NULL == CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, &ParamToPlugin, 0, &tid)) - ReadDoneFcn(ActualAccount->AccountAccessSO); - else - WaitForSingleObject(ThreadRunningEV, INFINITE); - } - ReadDoneFcn(ActualAccount->AccountAccessSO); - } - LeaveCriticalSection(&PluginRegCS); - CloseHandle(ThreadRunningEV); - } - DBFreeVariant(&dbv); - return 0; -} - -void MainMenuAccountClicked(WPARAM wParam, LPARAM lParam) -{ -} - -/*static*/ void ContactDoubleclicked(WPARAM wParam, LPARAM lParam) -{ - char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); - if ( lstrcmpA(szProto, YAMN_DBMODULE)) - return; - - DBVARIANT dbv; - if ( DBGetContactSetting(( HANDLE )wParam, YAMN_DBMODULE, "Id", &dbv)) - return; - - HACCOUNT ActualAccount = (HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)dbv.pszVal); - if (ActualAccount != NULL) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0 == WaitToReadFcn(ActualAccount->AccountAccessSO)) { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read enter\n"); - #endif - YAMN_MAILBROWSERPARAM Param = {(HANDLE)0, ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, 0}; - - 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; - - RunMailBrowserSvc((WPARAM)&Param, (LPARAM)YAMN_MAILBROWSERVERSION); - - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read done\n"); - #endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - } - #ifdef DEBUG_SYNCHRO - else - DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read enter failed\n"); - #endif - - } - DBFreeVariant(&dbv); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -HBITMAP LoadBmpFromIcon(HICON hIcon) -{ - int IconSizeX = 16; - int IconSizeY = 16; - - HBRUSH hBkgBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); - - BITMAPINFOHEADER bih = {0}; - bih.biSize = sizeof(bih); - bih.biBitCount = 24; - bih.biPlanes = 1; - bih.biCompression = BI_RGB; - bih.biHeight = IconSizeY; - bih.biWidth = IconSizeX; - - int widthBytes = ((bih.biWidth*bih.biBitCount + 31) >> 5) * 4; - - RECT rc; - rc.top = rc.left = 0; - rc.right = bih.biWidth; - rc.bottom = bih.biHeight; - - HDC hdc = GetDC(NULL); - 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, NULL, DI_NORMAL); - SelectObject(hdcMem, hoBmp); - return hBmp; -} - -int AddTopToolbarIcon(WPARAM,LPARAM) -{ - if ( DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_TTBFCHECK, 1)) { - if ( ServiceExists(MS_TTB_REMOVEBUTTON) && hTTButton == NULL) { - TTBButton btn = {0}; - btn.cbSize = sizeof(btn); - btn.pszService = MS_YAMN_FORCECHECK; - btn.dwFlags = TTBBF_VISIBLE | TTBBF_SHOWTOOLTIP; - btn.hIconHandleUp = g_GetIconHandle(5); - btn.hIconHandleDn = g_GetIconHandle(6); - btn.name = btn.pszTooltipUp = LPGEN("Check mail"); - hTTButton = TopToolbar_AddButton(&btn); - } - } - else { - if (hTTButton != NULL) { - CallService(MS_TTB_REMOVEBUTTON, (WPARAM)hTTButton, 0); - hTTButton = NULL; - } - } - - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -int Shutdown(WPARAM, LPARAM) -{ - CallService(MS_TTB_REMOVEBUTTON, (WPARAM)hTTButton, 0); - - DBWriteContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSX, HeadPosX); - DBWriteContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSY, HeadPosY); - DBWriteContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEX, HeadSizeX); - DBWriteContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEY, HeadSizeY); - DBWriteContactSettingWord(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSSPLIT, HeadSplitPos); - YAMNVar.Shutdown = TRUE; - KillTimer(NULL, SecTimer); - - UnregisterProtoPlugins(); - UnregisterFilterPlugins(); - return 0; -} - -int SystemModulesLoaded(WPARAM, LPARAM); //in main.cpp -typedef struct { HANDLE hookHandle; const char *hookName; MIRANDAHOOK mirandaFunction;} HookDataType; -static HookDataType hookData[] = { - {0, ME_SYSTEM_MODULESLOADED, SystemModulesLoaded}, //pop3 plugin must be included after all miranda modules are loaded - {0, ME_TTB_MODULELOADED, AddTopToolbarIcon}, - {0, ME_OPT_INITIALISE, YAMNOptInitSvc}, - {0, ME_SYSTEM_PRESHUTDOWN, Shutdown}, - {0, ME_CLIST_DOUBLECLICKED, Service_ContactDoubleclicked}, - {0, 0, 0}//end marker -}; - -void HookEvents(void) -{ - //We set function which registers needed POP3 accounts. This is a part of internal POP3 plugin. - //Your plugin should do the same task in your Load fcn. Why we call it in MODULESLOADED? Because netlib - //user can be registered after all modules are loaded (see m_netlib.h in Miranda) - for (int i = 0;hookData[i].hookName;i++) { - hookData[i].hookHandle = HookEvent(hookData[i].hookName, hookData[i].mirandaFunction); - } -} -void UnhookEvents(void){ - for (int i = 0;i<(sizeof(hookData)/sizeof(hookData[0]));i++) { - if (hookData[i].hookHandle) UnhookEvent(hookData[i].hookHandle); - } -} - -typedef struct { HANDLE serviceHandle; const char *serviceName; MIRANDASERVICE serviceFunction;} ServiceDataType; -static ServiceDataType serviceData[] = { - {0, YAMN_DBMODULE PS_GETCAPS, Service_GetCaps}, - {0, YAMN_DBMODULE PS_GETSTATUS, Service_GetStatus}, - {0, YAMN_DBMODULE PS_SETSTATUS, Service_SetStatus}, - {0, YAMN_DBMODULE PS_GETNAME, Service_GetName}, - {0, YAMN_DBMODULE PS_LOADICON, Service_LoadIcon}, - - //Function with which protocol plugin can register - {0, MS_YAMN_GETFCNPTR, GetFcnPtrSvc}, - - //Function returns pointer to YAMN variables - {0, MS_YAMN_GETVARIABLES, GetVariablesSvc}, - - //Function with which protocol plugin can register - {0, MS_YAMN_REGISTERPROTOPLUGIN, RegisterProtocolPluginSvc}, - - //Function with which protocol plugin can unregister - {0, MS_YAMN_UNREGISTERPROTOPLUGIN, UnregisterProtocolPluginSvc}, - - //Function creates an account for plugin - {0, MS_YAMN_CREATEPLUGINACCOUNT, CreatePluginAccountSvc}, - - //Function deletes plugin account - {0, MS_YAMN_DELETEPLUGINACCOUNT, DeletePluginAccountSvc}, - - //Finds account for plugin by name - {0, MS_YAMN_FINDACCOUNTBYNAME, FindAccountByNameSvc}, - - //Creates next account for plugin - {0, MS_YAMN_GETNEXTFREEACCOUNT, GetNextFreeAccountSvc}, - - //Function removes account from YAMN queue. Does not delete it from memory - {0, MS_YAMN_DELETEACCOUNT, DeleteAccountSvc}, - - //Function finds accounts for specified plugin - {0, MS_YAMN_READACCOUNTS, AddAccountsFromFileSvc}, - - //Function that stores all plugin mails to one file - {0, MS_YAMN_WRITEACCOUNTS, WriteAccountsToFileSvc}, - - //Function that returns user's filename - {0, MS_YAMN_GETFILENAME, GetFileNameSvc}, - - //Releases unicode string from memory - {0, MS_YAMN_DELETEFILENAME, DeleteFileNameSvc}, - - //Checks mail - {0, MS_YAMN_FORCECHECK, ForceCheckSvc}, - - //Runs YAMN's mail browser - {0, MS_YAMN_MAILBROWSER, RunMailBrowserSvc}, - - //Runs YAMN's bad conenction window - {0, MS_YAMN_BADCONNECTION, RunBadConnectionSvc}, - - //Function creates new mail for plugin - {0, MS_YAMN_CREATEACCOUNTMAIL, CreateAccountMailSvc}, - - //Function deletes plugin account - {0, MS_YAMN_DELETEACCOUNTMAIL, DeleteAccountMailSvc}, - - //Function with which filter plugin can register - {0, MS_YAMN_REGISTERFILTERPLUGIN, RegisterFilterPluginSvc}, - - //Function with which filter plugin can unregister - {0, MS_YAMN_UNREGISTERFILTERPLUGIN, UnregisterFilterPluginSvc}, - - //Function filters mail - {0, MS_YAMN_FILTERMAIL, FilterMailSvc}, - - //Function contact list double click - {0, MS_YAMN_CLISTDBLCLICK, ClistContactDoubleclicked}, - - //Function to check individual account - {0, MS_YAMN_ACCOUNTCHECK, AccountMailCheck}, - - //Function contact list context menu click - {0, MS_YAMN_CLISTCONTEXT, ContactMailCheck}, - - //Function contact list context menu click - {0, MS_YAMN_CLISTCONTEXTAPP, ContactApplication}, - - {0, 0, 0}//end marker -}; - -void CreateServiceFunctions(void) -{ - for (int i = 0;serviceData[i].serviceName;i++) { - serviceData[i].serviceHandle = CreateServiceFunction(serviceData[i].serviceName, serviceData[i].serviceFunction); - } -}; - -void DestroyServiceFunctions(void) -{ - for (int i = 0;serviceData[i].serviceName;i++) { - if (serviceData[i].serviceHandle) DestroyServiceFunction(serviceData[i].serviceHandle); - } -}; - -//Function to put all enabled contact to the Online status -void RefreshContact(void) -{ - HACCOUNT Finder; - for (Finder = POP3Plugin->FirstAccount;Finder != NULL;Finder = Finder->Next) { - if (Finder->hContact != NULL) { - if ((Finder->Flags & YAMN_ACC_ENA) && (Finder->NewMailN.Flags & YAMN_ACC_CONT)) - DBDeleteContactSetting(Finder->hContact, "CList", "Hidden"); - else - DBWriteContactSettingByte(Finder->hContact, "CList", "Hidden", 1); - } - else if ((Finder->Flags & YAMN_ACC_ENA) && (Finder->NewMailN.Flags & YAMN_ACC_CONT)) { - Finder->hContact = (HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0); - CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)Finder->hContact, (LPARAM)YAMN_DBMODULE); - DBWriteContactSettingString(Finder->hContact, YAMN_DBMODULE, "Id", Finder->Name); - DBWriteContactSettingString(Finder->hContact, YAMN_DBMODULE, "Nick", Finder->Name); - DBWriteContactSettingString(Finder->hContact, "Protocol", "p", YAMN_DBMODULE); - DBWriteContactSettingWord(Finder->hContact, YAMN_DBMODULE, "Status", ID_STATUS_ONLINE); - DBWriteContactSettingString(Finder->hContact, "CList", "StatusMsg", Translate("No new mail message")); -} } } diff --git a/protocols/YAMN/src/YAMNopts.cpp b/protocols/YAMN/src/YAMNopts.cpp new file mode 100644 index 0000000000..99a8091366 --- /dev/null +++ b/protocols/YAMN/src/YAMNopts.cpp @@ -0,0 +1,2 @@ + + diff --git a/protocols/YAMN/src/account.cpp b/protocols/YAMN/src/account.cpp new file mode 100644 index 0000000000..d1de8b8e4c --- /dev/null +++ b/protocols/YAMN/src/account.cpp @@ -0,0 +1,1309 @@ +/* + * This code implements manipulation with accounts + * such as reading accounts from file, writing them to file, + * finding account by name etc. + * + * (c) majvan 2002-2004 + */ + +#include "yamn.h" +#include "m_mails.h" +#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) || defined(DEBUG_SYNCHRO) + #include +#endif + +//Account status CS +//When we check some account, thread should change status of account to idle, connecting etc. +//So if we want to read status, we have to successfully write and then read. +CRITICAL_SECTION AccountStatusCS; + +//File Writing CS +//When 2 threads want to write to file... +CRITICAL_SECTION FileWritingCS; + +struct CExportedFunctions AccountExportedFcn[]= +{ + {YAMN_GETSTATUSID,(void *)GetStatusFcn}, + {YAMN_SETSTATUSID,(void *)SetStatusFcn}, +}; + +struct CExportedServices AccountExportedSvc[]= +{ + {MS_YAMN_CREATEPLUGINACCOUNT,CreatePluginAccountSvc}, + {MS_YAMN_DELETEPLUGINACCOUNT,DeletePluginAccountSvc}, + {MS_YAMN_FINDACCOUNTBYNAME,FindAccountByNameSvc}, + {MS_YAMN_GETNEXTFREEACCOUNT,GetNextFreeAccountSvc}, + {MS_YAMN_DELETEACCOUNT,DeletePluginAccountSvc}, + {MS_YAMN_READACCOUNTS,AddAccountsFromFileSvc}, + {MS_YAMN_WRITEACCOUNTS,WriteAccountsToFileSvc}, +}; + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +INT_PTR CreatePluginAccountSvc(WPARAM wParam,LPARAM lParam) +{ + HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; + DWORD AccountVersion=(DWORD)lParam; + HACCOUNT NewAccount; + +//test if we are going to initialize members of suitable structure (structures of plugin and YAMN must match) + if (AccountVersion!=YAMN_ACCOUNTVERSION) + return NULL; + + if (Plugin!=NULL) + { + if (Plugin->Fcn->NewAccountFcnPtr!=NULL) + { +//Let plugin create its own structure, which can be derived from CAccount structure + NewAccount=Plugin->Fcn->NewAccountFcnPtr(Plugin,YAMN_ACCOUNTVERSION); + NewAccount->Plugin=Plugin; + } + else + { +//We suggest plugin uses standard CAccount structure, so we create it + NewAccount=new struct CAccount; + NewAccount->Plugin=Plugin; + } +//If not created successfully + if (NewAccount==NULL) + return NULL; +//Init every members of structure, used by YAMN + InitAccount(NewAccount); + + return (INT_PTR)NewAccount; + } + return NULL; +} + +INT_PTR DeletePluginAccountSvc(WPARAM wParam,LPARAM) +{ + HACCOUNT OldAccount=(HACCOUNT)wParam; + + if (OldAccount->Plugin->Fcn!=NULL) + { +//Deinit every members and allocated fields of structure used by YAMN + DeInitAccount(OldAccount); + if (OldAccount->Plugin->Fcn->DeleteAccountFcnPtr!=NULL) + { +//Let plugin delete its own CAccount derived structure + OldAccount->Plugin->Fcn->DeleteAccountFcnPtr(OldAccount); + } + else + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeletePluginAccountSvc:delete OldAccount\n"); +#endif + delete OldAccount; //consider account as standard YAMN HACCOUNT and use its own destructor + } + return 1; + } + delete OldAccount; //consider account as standard YAMN HACCOUNT, not initialized before and use its own destructor + return 1; +} + +int InitAccount(HACCOUNT Which) +{ +//initialize synchronizing objects + Which->AccountAccessSO=new SWMRG; + SWMRGInitialize(Which->AccountAccessSO,NULL); + Which->MessagesAccessSO=new SWMRG; + SWMRGInitialize(Which->MessagesAccessSO,NULL); + Which->UsingThreads=new SCOUNTER; + SWMRGInitialize(Which->MessagesAccessSO,NULL); + +//zero memory, where timestamps are stored + ZeroMemory(&Which->LastChecked,sizeof(Which->LastChecked)); + ZeroMemory(&Which->LastSChecked,sizeof(Which->LastSChecked)); + ZeroMemory(&Which->LastSynchronised,sizeof(Which->LastSynchronised)); + ZeroMemory(&Which->LastMail,sizeof(Which->LastMail)); + + Which->Name=NULL; + Which->Mails=NULL; + Which->Interval=0; + Which->Flags=0; + Which->StatusFlags=0; + Which->Next=NULL; + + Which->Server=new struct CServer; + Which->AbleToWork=TRUE; + + return 1; +} + +void DeInitAccount(HACCOUNT Which) +{ +//delete YAMN allocated fields + if (Which->Name!=NULL) + delete[] Which->Name; + if (Which->Server->Name!=NULL) + delete[] Which->Server->Name; + if (Which->Server->Login!=NULL) + delete[] Which->Server->Login; + if (Which->Server->Passwd!=NULL) + delete[] Which->Server->Passwd; + if (Which->Server!=NULL) + delete[] Which->Server; + + SWMRGDelete(Which->AccountAccessSO); + delete Which->AccountAccessSO; + SWMRGDelete(Which->MessagesAccessSO); + delete Which->MessagesAccessSO; + delete Which->UsingThreads; + DeleteMessagesToEndFcn(Which,(HYAMNMAIL)Which->Mails); +} + +void StopSignalFcn(HACCOUNT Which) +//set event that we are going to delete account +{ +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tStopSignalFcn:stop account: %x\n",Which); +#endif + Which->AbleToWork=FALSE; +//do not use synchronizing objects anymore +//any access to these objects then ends with WAIT_FAILED + SetEvent(Which->AccountAccessSO->hFinishEV); + SetEvent(Which->MessagesAccessSO->hFinishEV); +} + +void CodeDecodeString(char *Dest,BOOL Encrypt) +{ + TCHAR Code=STARTCODEPSW; + + if (Dest==NULL) + return; + + for (;*Dest!=(TCHAR)0;Dest++) + { + if (Encrypt) + *Dest=*Dest+Code; + else + *Dest=*Dest-Code; + Code+=(TCHAR)ADDCODEPSW; + } +} + +static DWORD PostFileToMemory(HANDLE File,char **MemFile,char **End) +{ + DWORD FileSize,ReadBytes; + if (!(FileSize=GetFileSize(File,NULL))) { + CloseHandle(File); + return EACC_FILESIZE; + } + + //allocate space in memory, where we copy the whole file + if (NULL==(*MemFile = new char[FileSize])) + { + CloseHandle(File); + return EACC_ALLOC; + } + + //copy file to memory + if (!ReadFile(File,(LPVOID)*MemFile,FileSize,&ReadBytes,NULL)) + { + CloseHandle(File); + delete[] *MemFile; + return EACC_SYSTEM; + } + CloseHandle(File); + *End = *MemFile + FileSize; + return 0; +} + +DWORD FileToMemory(TCHAR *FileName,char **MemFile,char **End) +{ + HANDLE hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) + return EACC_SYSTEM; + + return PostFileToMemory(hFile, MemFile, End); +} + +#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) +DWORD ReadStringFromMemory(char **Parser,TCHAR *End,char **StoreTo,TCHAR *DebugString) +{ +//This is the debug version of ReadStringFromMemory function. This version shows MessageBox where +//read string is displayed + TCHAR *Dest,*Finder; + DWORD Size; + TCHAR Debug[65536]; + + Finder=*Parser; + while((*Finder!=(TCHAR)0) && (Finder<=End)) Finder++; + _stprintf(Debug,_T("%s: %s,length is %d, remaining %d chars"),DebugString,*Parser,Finder-*Parser,End-Finder); + MessageBox(NULL,Debug,_T("debug"),MB_OK); + if (Finder>=End) + return EACC_FILECOMPATIBILITY; + if (Size=Finder-*Parser) + { + if (NULL==(Dest=*StoreTo=new TCHAR[Size+1])) + return EACC_ALLOC; + for (;*Parser<=Finder;(*Parser)++,Dest++) + *Dest=**Parser; + } + else + { + *StoreTo=NULL; + (*Parser)++; + } + return 0; +} +#endif + +DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo) +{ + char *Dest,*Finder; + DWORD Size; + + Finder=*Parser; + while((*Finder!=(TCHAR)0) && (Finder<=End)) Finder++; + if (Finder>=End) + return EACC_FILECOMPATIBILITY; + if (Size=Finder-*Parser) + { + if (NULL==(Dest=*StoreTo=new char[Size+1])) + return EACC_ALLOC; + for (;*Parser<=Finder;(*Parser)++,Dest++) + *Dest=**Parser; + } + else + { + *StoreTo=NULL; + (*Parser)++; + } + return 0; +} + + #if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) +DWORD ReadStringFromMemoryW(WCHAR **Parser,TCHAR *End,WCHAR **StoreTo,WCHAR *DebugString) +{ +//This is the debug version of ReadStringFromMemoryW function. This version shows MessageBox where +//read string is displayed + WCHAR *Dest,*Finder; + DWORD Size; + WCHAR Debug[65536]; + + Finder=*Parser; + while((*Finder!=(WCHAR)0) && (Finder<=(WCHAR *)End)) Finder++; + swprintf(Debug,L"%s: %s,length is %d, remaining %d chars",DebugString,*Parser,Finder-*Parser,(WCHAR *)End-Finder); + MessageBoxW(NULL,Debug,L"debug",MB_OK); + if (Finder>=(WCHAR *)End) + return EACC_FILECOMPATIBILITY; + if (Size=Finder-*Parser) + { + if (NULL==(Dest=*StoreTo=new WCHAR[Size+1])) + return EACC_ALLOC; + for (;*Parser<=Finder;(*Parser)++,Dest++) + *Dest=**Parser; + } + else + { + *StoreTo=NULL; + (*Parser)++; + } + return 0; +} + #endif //if defined(DEBUG...) + +DWORD ReadStringFromMemoryW(WCHAR **Parser,WCHAR *End,WCHAR **StoreTo) +{ + WCHAR *Dest,*Finder; + DWORD Size; + + Finder=*Parser; + while((*Finder!=(WCHAR)0) && (Finder<=(WCHAR *)End)) Finder++; + if (Finder>=(WCHAR *)End) + return EACC_FILECOMPATIBILITY; + if (Size=Finder-*Parser) + { + if (NULL==(Dest=*StoreTo=new WCHAR[Size+1])) + return EACC_ALLOC; + for (;*Parser<=Finder;(*Parser)++,Dest++) + *Dest=**Parser; + } + else + { + *StoreTo=NULL; + (*Parser)++; + } + return 0; +} + +static DWORD ReadNotificationFromMemory(char **Parser,char *End,YAMN_NOTIFICATION *Which) +{ + DWORD Stat; +#ifdef DEBUG_FILEREAD + TCHAR Debug[65536]; +#endif + + Which->Flags=*(DWORD *)(*Parser); + (*Parser)+=sizeof(DWORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("NFlags: %04x, remaining %d chars"),Which->Flags,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + + Which->PopUpB=*(COLORREF *)(*Parser); + (*Parser)+=sizeof(COLORREF); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("PopUpB: %04x, remaining %d chars"),Which->PopUpB,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + Which->PopUpT=*(COLORREF *)(*Parser); + (*Parser)+=sizeof(COLORREF); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("PopUpT: %04x, remaining %d chars"),Which->PopUpT,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + Which->PopUpTime=*(DWORD *)(*Parser); + (*Parser)+=sizeof(DWORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("PopUpTime: %04x, remaining %d chars"),Which->PopUpTime,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + +#ifdef DEBUG_FILEREAD + if (Stat=ReadStringFromMemoryW((WCHAR **)Parser,(WCHAR*)End,&Which->App,L"App")) +#else + if (Stat=ReadStringFromMemoryW((WCHAR **)Parser,(WCHAR*)End,&Which->App)) +#endif + return Stat; +#ifdef DEBUG_FILEREAD + if (Stat=ReadStringFromMemoryW((WCHAR **)Parser,(WCHAR*)End,&Which->AppParam,L"AppParam")) +#else + if (Stat=ReadStringFromMemoryW((WCHAR **)Parser,(WCHAR*)End,&Which->AppParam)) +#endif + return Stat; + return 0; +} + +DWORD ReadMessagesFromMemory(HACCOUNT Which,char **Parser,char *End) +{ + char *Finder; + DWORD Size,Stat; + HYAMNMAIL ActualMail=NULL; + struct CMimeItem *items; + char *ReadString; + +#ifdef DEBUG_FILEREAD + MessageBox(NULL,_T("going to read messages, if any..."),_T("debug"),MB_OK); +#endif + do + { + Finder=*Parser; + while((*Finder!=(TCHAR)0) && (Finder<=End)) Finder++; + if (Finder>=End) + return EACC_FILECOMPATIBILITY; + if (Size=Finder-*Parser) + { + if (Which->Mails==NULL) //First message in queue + { + if (NULL==(Which->Mails=ActualMail=CreateAccountMail(Which))) + return EACC_ALLOC; + } + else + { + if (NULL==(ActualMail->Next=CreateAccountMail(Which))) { + return EACC_ALLOC; + } + ActualMail=ActualMail->Next; + } + items=NULL; +#ifdef DEBUG_FILEREADMESSAGES + if (Stat=ReadStringFromMemory(Parser,End,&ActualMail->ID,_T("ID"))) +#else + if (Stat=ReadStringFromMemory(Parser,End,&ActualMail->ID)) +#endif + return Stat; +// ActualMail->MailData=new MAILDATA; !!! mem leake !!! this is alloc by CreateAccountMail, no need for doubble alloc !!!! + + ActualMail->MailData->Size=*(DWORD *)(*Parser); + (*Parser)+=sizeof(DWORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; + ActualMail->Flags=*(DWORD *)(*Parser); + (*Parser)+=sizeof(DWORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; + ActualMail->Number=*(DWORD *)(*Parser); + (*Parser)+=sizeof(DWORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; + + if ((NULL!=Which->Plugin->MailFcn) && (NULL!=Which->Plugin->MailFcn->ReadMailOptsFcnPtr)) + Which->Plugin->MailFcn->ReadMailOptsFcnPtr(ActualMail,Parser,End); //read plugin mail settings from file + + do + { +#if defined(DEBUG_FILEREADMESSAGES) || defined(DEBUG_FILEREAD) + if (Stat=ReadStringFromMemory(Parser,End,&ReadString,_T("Name"))) +#else + if (Stat=ReadStringFromMemory(Parser,End,&ReadString)) +#endif + return Stat; + if (ReadString==NULL) + break; + +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%s",ReadString); +#endif + + if (items==NULL) + items=ActualMail->MailData->TranslatedHeader=new struct CMimeItem; + else + { + items->Next=new struct CMimeItem; + items=items->Next; + } + if (items==NULL) + return EACC_ALLOC; + items->name=ReadString; + +#ifdef DEBUG_FILEREADMESSAGES + if (Stat=ReadStringFromMemory(Parser,End,&ReadString,_T("Value"))) +#else + if (Stat=ReadStringFromMemory(Parser,End,&ReadString)) +#endif + return Stat; + items->value=ReadString; +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%s\n",ReadString); +#endif + }while(1); + } + else + break; //no next messages, new account! + + }while(1); + (*Parser)++; + return 0; +} + +DWORD ReadAccountFromMemory(HACCOUNT Which,char **Parser,char *End) +{ + DWORD Stat; +#ifdef DEBUG_FILEREAD + TCHAR Debug[65536]; +#endif + //Read name of account + +#ifdef DEBUG_FILEREAD + if (Stat=ReadStringFromMemory(Parser,End,&Which->Name,_T("Name"))) +#else + if (Stat=ReadStringFromMemory(Parser,End,&Which->Name)) +#endif + return Stat; + if (Which->Name==NULL) + return EACC_FILECOMPATIBILITY; + + //Read server parameters +#ifdef DEBUG_FILEREAD + if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Name,_T("Server"))) +#else + if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Name)) +#endif + return Stat; + Which->Server->Port=*(WORD *)(*Parser); + (*Parser)+=sizeof(WORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("Port: %d, remaining %d chars"),Which->Server->Port,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif +#ifdef DEBUG_FILEREAD + if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Login,_T("Login"))) +#else + if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Login)) +#endif + return Stat; +#ifdef DEBUG_FILEREAD + if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Passwd,_T("Password"))) +#else + if (Stat=ReadStringFromMemory(Parser,End,&Which->Server->Passwd)) +#endif + return Stat; + CodeDecodeString(Which->Server->Passwd,FALSE); + + //Read account flags + Which->Flags=*(DWORD *)(*Parser); + (*Parser)+=sizeof(DWORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("Flags: %04x, remaining %d chars"),Which->Flags,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + Which->StatusFlags=*(DWORD *)(*Parser); + (*Parser)+=sizeof(DWORD); +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("STFlags: %04x, remaining %d chars"),Which->StatusFlags,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + Which->PluginFlags=*(DWORD *)(*Parser); + (*Parser)+=sizeof(DWORD); +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("PFlags: %04x, remaining %d chars"),Which->PluginFlags,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + + //Read account miscellaneous parameters + Which->Interval=*(WORD *)(*Parser); + Which->TimeLeft=Which->Interval; //check on loading + (*Parser)+=sizeof(WORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("Interval: %d, remaining %d chars"),Which->Interval,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + + //Read notification parameters + if (Stat=ReadNotificationFromMemory(Parser,End,&Which->NewMailN)) + return Stat; + if (Stat=ReadNotificationFromMemory(Parser,End,&Which->NoNewMailN)) + return Stat; + if (Stat=ReadNotificationFromMemory(Parser,End,&Which->BadConnectN)) + return Stat; + + //Let plugin read its own data stored in file + if (Which->Plugin->Fcn!=NULL && Which->Plugin->Fcn->ReadPluginOptsFcnPtr!=NULL) + if (Stat=Which->Plugin->Fcn->ReadPluginOptsFcnPtr(Which,Parser,End)) + return Stat; + //Read mails +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write wait\n"); +#endif + WaitToWriteFcn(Which->MessagesAccessSO); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write enter\n"); +#endif + if (Stat=ReadMessagesFromMemory(Which,Parser,End)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write done\n"); +#endif + WriteDoneFcn(Which->MessagesAccessSO); + return Stat; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"ReadAccountFromMemory:ActualAccountMsgsSO-write done\n"); +#endif + WriteDoneFcn(Which->MessagesAccessSO); + + //Read timestamps + Which->LastChecked=*(SYSTEMTIME *)(*Parser); + (*Parser)+=sizeof(SYSTEMTIME); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("LastChecked: %04x, remaining %d chars"),Which->LastChecked,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + Which->LastSChecked=*(SYSTEMTIME *)(*Parser); + (*Parser)+=sizeof(SYSTEMTIME); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("LastSChecked: %04x, remaining %d chars"),Which->LastSChecked,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + Which->LastSynchronised=*(SYSTEMTIME *)(*Parser); + (*Parser)+=sizeof(SYSTEMTIME); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("LastSynchronised: %04x, remaining %d chars"),Which->LastSynchronised,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + Which->LastMail=*(SYSTEMTIME *)(*Parser); + (*Parser)+=sizeof(SYSTEMTIME); + if (*Parser>End) //WARNING! There's only > at the end of testing + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("LastMail: %04x, remaining %d chars"),Which->LastMail,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + if (*Parser==End) + return EACC_ENDOFFILE; + return 0; + +} + +static INT_PTR PerformAccountReading(HYAMNPROTOPLUGIN Plugin,char *MemFile,char *End) +{ + //Retrieve info for account from memory + char *Parser; + DWORD Ver,Stat; + + HACCOUNT ActualAccount,FirstAllocatedAccount; + + Ver=*(DWORD *)MemFile; + if (Ver>YAMN_ACCOUNTFILEVERSION) + { + delete[] MemFile; + return EACC_FILEVERSION; + } + Parser=MemFile+sizeof(Ver); + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write wait\n"); +#endif + SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write enter\n"); +#endif + if (NULL==(ActualAccount=(HACCOUNT)CallService(MS_YAMN_GETNEXTFREEACCOUNT,(WPARAM)Plugin,(LPARAM)YAMN_ACCOUNTVERSION))) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n"); +#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); + delete[] MemFile; + return EACC_ALLOC; + } + FirstAllocatedAccount=ActualAccount; + + do + { + HACCOUNT Temp; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write wait\n"); +#endif + WaitToWriteFcn(ActualAccount->AccountAccessSO); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write enter\n"); +#endif + Stat=ReadAccountFromMemory(ActualAccount,&Parser,End); + + if (ActualAccount->StatusFlags & (YAMN_ACC_STARTA | YAMN_ACC_STARTS)) + ActualAccount->TimeLeft=1; //check on loading + + if (Stat && (Stat!=EACC_ENDOFFILE)) + { + for (ActualAccount=FirstAllocatedAccount;ActualAccount!=NULL;ActualAccount=Temp) + { + Temp=ActualAccount->Next; + delete ActualAccount; + } + delete[] MemFile; + if (Plugin->FirstAccount==FirstAllocatedAccount) + Plugin->FirstAccount=NULL; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write done\n"); +#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); + return (INT_PTR)Stat; + } + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"AddAccountsFromFile:ActualAccountSO-write done\n"); +#endif + WriteDoneFcn(ActualAccount->AccountAccessSO); + + if ((Stat!=EACC_ENDOFFILE) && (NULL==(ActualAccount=(HACCOUNT)CallService(MS_YAMN_GETNEXTFREEACCOUNT,(WPARAM)Plugin,(LPARAM)YAMN_ACCOUNTVERSION)))) + { + for (ActualAccount=FirstAllocatedAccount;ActualAccount!=NULL;ActualAccount=Temp) + { + Temp=ActualAccount->Next; + delete ActualAccount; + } + delete[] MemFile; + if (Plugin->FirstAccount==FirstAllocatedAccount) + Plugin->FirstAccount=NULL; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n"); +#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); + return EACC_ALLOC; + } + }while(Stat!=EACC_ENDOFFILE); + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"AddAccountsFromFile:AccountBrowserSO-write done\n"); +#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); + delete[] MemFile; + + return 0; +} + +// Add accounts from file to memory +INT_PTR AddAccountsFromFileSvc(WPARAM wParam,LPARAM lParam) +{ + char *MemFile,*End; + DWORD Stat = FileToMemory(( TCHAR* )lParam, &MemFile, &End); + if ( Stat != NO_ERROR ) + return (INT_PTR)Stat; + + return PerformAccountReading((HYAMNPROTOPLUGIN)wParam,MemFile,End); +} + +DWORD WriteStringToFile(HANDLE File,char *Source) +{ + DWORD Length,WrittenBytes; + char null = 0; + + if ((Source==NULL) || !(Length=(DWORD)strlen(Source))) { + if (!WriteFile(File,&null,1,&WrittenBytes,NULL)) { + CloseHandle(File); + return EACC_SYSTEM; + } + } + else if (!WriteFile(File,Source,(Length+1),&WrittenBytes,NULL)) { + CloseHandle(File); + return EACC_SYSTEM; + } + return 0; +} + +DWORD WriteStringToFileW(HANDLE File,WCHAR *Source) +{ + DWORD Length,WrittenBytes; + WCHAR null=(WCHAR)0; + + if ((Source==NULL) || !(Length=(DWORD)wcslen(Source))) + { + if (!WriteFile(File,&null,sizeof(WCHAR),&WrittenBytes,NULL)) + { + CloseHandle(File); + return EACC_SYSTEM; + } + } + else if (!WriteFile(File,Source,(Length+1)*sizeof(WCHAR),&WrittenBytes,NULL)) + return EACC_SYSTEM; + return 0; +} + +DWORD WriteMessagesToFile(HANDLE File,HACCOUNT Which) +{ + DWORD WrittenBytes,Stat; + HYAMNMAIL ActualMail=(HYAMNMAIL)Which->Mails; + struct CMimeItem *items; + + while(ActualMail!=NULL) + { + if (Stat=WriteStringToFile(File,ActualMail->ID)) + return Stat; + if (!WriteFile(File,(char *)&ActualMail->MailData->Size,sizeof(ActualMail->MailData->Size),&WrittenBytes,NULL) || + !WriteFile(File,(char *)&ActualMail->Flags,sizeof(ActualMail->Flags),&WrittenBytes,NULL) || + !WriteFile(File,(char *)&ActualMail->Number,sizeof(ActualMail->Number),&WrittenBytes,NULL)) + return EACC_SYSTEM; + if ((NULL!=Which->Plugin->MailFcn) && (NULL!=Which->Plugin->MailFcn->WriteMailOptsFcnPtr)) + Which->Plugin->MailFcn->WriteMailOptsFcnPtr(File,ActualMail); //write plugin mail options to file + for (items=ActualMail->MailData->TranslatedHeader;items!=NULL;items=items->Next) + { + if (Stat=WriteStringToFile(File,items->name)) + return Stat; + if (Stat=WriteStringToFile(File,items->value)) + return Stat; + } + if (Stat=WriteStringToFile(File,"")) + return Stat; + ActualMail=ActualMail->Next; + } + if (Stat=WriteStringToFile(File,"")) + return Stat; + return 0; +} + +static INT_PTR PerformAccountWriting(HYAMNPROTOPLUGIN Plugin,HANDLE File) +{ + DWORD WrittenBytes,Stat; + HACCOUNT ActualAccount; + DWORD Ver=YAMN_ACCOUNTFILEVERSION; + BOOL Writed=FALSE; + DWORD ReturnValue=0,EnterCode; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read wait\n"); +#endif + SWMRGWaitToRead(Plugin->AccountBrowserSO,INFINITE); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read enter\n"); +#endif + try + { + for (ActualAccount=Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=ActualAccount->Next) + { +/* TCHAR DEBUG[100]; + Beep(3000,100);Sleep(200); + _stprintf(DEBUG,_T("Browsing account %s"),ActualAccount->Name==NULL ? _T("(null)") : ActualAccount->Name); + MessageBox(NULL,DEBUG,_T("debug- WriteAccount..."),MB_OK); +*/ +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait\n"); +#endif + EnterCode=WaitToReadFcn(ActualAccount->AccountAccessSO); + if (EnterCode==WAIT_FINISH) //account is about to delete + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read wait failed\n"); +#endif + ActualAccount=ActualAccount->Next; + continue; + } + if (EnterCode==WAIT_FAILED) //account is deleted + break; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read enter\n"); +#endif + if ((ActualAccount->Name==NULL) || (*ActualAccount->Name==(TCHAR)0)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); +#endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + continue; + } + + if (!Writed && !WriteFile(File,&Ver,sizeof(Ver),&WrittenBytes,NULL)) + throw (DWORD)EACC_SYSTEM; + Writed=TRUE; + + if (Stat=WriteStringToFile(File,ActualAccount->Name)) + throw (DWORD)Stat; + + if (Stat=WriteStringToFile(File,ActualAccount->Server->Name)) + throw (DWORD)Stat; + + if (!WriteFile(File,(char *)&ActualAccount->Server->Port,2,&WrittenBytes,NULL)) + throw (DWORD)EACC_SYSTEM; + + if ((Stat=WriteStringToFile(File,ActualAccount->Server->Login))) + throw (DWORD)Stat; + + CodeDecodeString(ActualAccount->Server->Passwd,TRUE); + + if (Stat=WriteStringToFile(File,ActualAccount->Server->Passwd)) + { + CodeDecodeString(ActualAccount->Server->Passwd,FALSE); + throw (DWORD)Stat; + } + CodeDecodeString(ActualAccount->Server->Passwd,FALSE); + + if ((!WriteFile(File,(char *)&ActualAccount->Flags,sizeof(DWORD),&WrittenBytes,NULL) || + (!WriteFile(File,(char *)&ActualAccount->StatusFlags,sizeof(DWORD),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->PluginFlags,sizeof(DWORD),&WrittenBytes,NULL)))) + throw (DWORD)EACC_SYSTEM; + + if (!WriteFile(File,(char *)&ActualAccount->Interval,sizeof(WORD),&WrittenBytes,NULL)) + throw (DWORD)EACC_SYSTEM; + + if ((!WriteFile(File,(char *)&ActualAccount->NewMailN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopUpB,sizeof(COLORREF),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopUpT,sizeof(COLORREF),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->NewMailN.PopUpTime,sizeof(DWORD),&WrittenBytes,NULL))) + throw (DWORD)EACC_SYSTEM; + + if ((Stat=WriteStringToFileW(File,ActualAccount->NewMailN.App)) || + (Stat=WriteStringToFileW(File,ActualAccount->NewMailN.AppParam))) + throw (DWORD)Stat; + + if ((!WriteFile(File,(char *)&ActualAccount->NoNewMailN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopUpB,sizeof(COLORREF),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopUpT,sizeof(COLORREF),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->NoNewMailN.PopUpTime,sizeof(DWORD),&WrittenBytes,NULL))) + throw (DWORD)EACC_SYSTEM; + + if ((Stat=WriteStringToFileW(File,ActualAccount->NoNewMailN.App)) || + (Stat=WriteStringToFileW(File,ActualAccount->NoNewMailN.AppParam))) + throw (DWORD)Stat; + + if ((!WriteFile(File,(char *)&ActualAccount->BadConnectN.Flags,sizeof(DWORD),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopUpB,sizeof(COLORREF),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopUpT,sizeof(COLORREF),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->BadConnectN.PopUpTime,sizeof(DWORD),&WrittenBytes,NULL))) + throw (DWORD)EACC_SYSTEM; + + if ((Stat=WriteStringToFileW(File,ActualAccount->BadConnectN.App)) || + (Stat=WriteStringToFileW(File,ActualAccount->BadConnectN.AppParam))) + throw (DWORD)Stat; + +//Let plugin write its own values into file + if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr!=NULL) + if (Stat=ActualAccount->Plugin->Fcn->WritePluginOptsFcnPtr(File,ActualAccount)) + throw (DWORD)Stat; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read wait\n"); +#endif + WaitToReadFcn(ActualAccount->MessagesAccessSO); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read enter\n"); +#endif + if (Stat=WriteMessagesToFile(File,ActualAccount)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n"); +#endif + ReadDoneFcn(ActualAccount->MessagesAccessSO); + throw (DWORD)Stat; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountMsgsSO-read done\n"); +#endif + ReadDoneFcn(ActualAccount->MessagesAccessSO); + + if ((!WriteFile(File,(char *)&ActualAccount->LastChecked,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->LastSChecked,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->LastSynchronised,sizeof(SYSTEMTIME),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&ActualAccount->LastMail,sizeof(SYSTEMTIME),&WrittenBytes,NULL))) + throw (DWORD)Stat; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); +#endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + } + } + catch(DWORD ErrorCode) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:ActualAccountSO-read done\n"); +#endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + ReturnValue=ErrorCode; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WriteAccountsToFile:AccountBrowserSO-read done\n"); +#endif + SWMRGDoneReading(Plugin->AccountBrowserSO); + CloseHandle(File); + return 0; +} + +//Writes accounts to file +INT_PTR WriteAccountsToFileSvc(WPARAM wParam,LPARAM lParam) +{ + HYAMNPROTOPLUGIN Plugin = ( HYAMNPROTOPLUGIN )wParam; + TCHAR* tszFileName = ( TCHAR* )lParam; + + EnterCriticalSection( &FileWritingCS ); + HANDLE hFile = CreateFile(tszFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); + if ( hFile == INVALID_HANDLE_VALUE ) { + LeaveCriticalSection(&FileWritingCS); + return EACC_SYSTEM; + } + + INT_PTR rv = PerformAccountWriting(Plugin, hFile); + LeaveCriticalSection(&FileWritingCS); + + return rv; +} + +INT_PTR FindAccountByNameSvc(WPARAM wParam,LPARAM lParam) +{ + HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; + char *SearchedAccount=(char *)lParam; + HACCOUNT Finder; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read wait\n"); +#endif + SWMRGWaitToRead(Plugin->AccountBrowserSO,INFINITE); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read enter\n"); +#endif + for (Finder=Plugin->FirstAccount;Finder!=NULL;Finder=Finder->Next) + if ((Finder->Name!=NULL) && (0 == strcmp(SearchedAccount,Finder->Name))) + break; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"FindAccountByName:AccountBrowserSO-read done\n"); +#endif + SWMRGDoneReading(Plugin->AccountBrowserSO); + return (INT_PTR)Finder; +} + +INT_PTR GetNextFreeAccountSvc(WPARAM wParam,LPARAM lParam) +{ + HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; + HACCOUNT Finder; + + if (Plugin->FirstAccount==NULL) + { + Plugin->FirstAccount=(HACCOUNT)CallService(MS_YAMN_CREATEPLUGINACCOUNT,wParam,lParam); + return (INT_PTR)Plugin->FirstAccount; + } + for (Finder=Plugin->FirstAccount;Finder->Next!=NULL;Finder=Finder->Next); + Finder->Next=(HACCOUNT)CallService(MS_YAMN_CREATEPLUGINACCOUNT,wParam,lParam); + return (INT_PTR)Finder->Next; +} + +/* +int FindPluginAccount(WPARAM wParam,LPARAM lParam) +{ + HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; + HACCOUNT Finder=(HACCOUNT)lParam; + + if (Finder=NULL) Finder=Plugin->FirstAccount; + +// for (;Finder!=NULL && Finder->PluginID!=Plugin->PluginInfo->PluginID;Finder=(HACCOUNT)Finder->Next); + return (int)Finder; +} +*/ +INT_PTR DeleteAccountSvc(WPARAM wParam,LPARAM lParam) +{ +//Deleting account works on these steps: +//1. set signal that account should stop activity (set event) +// setting this event we achieve, that any access to account is failed, +// so threads do not start any work with accounts (better saying threads of plugins should not start) +//2. wait to get write access to chained list of accounts +//3. we can write to chained list, so we change chain not to show to actual account +// now, any thread browsing list of accounts does not browse through actual account +// actual account seems to be hidden (it exists, but it is not in accounts chained list (chained list=queue)) +//Now, we should delete account from memory, BUT!!! +// Any thread can still be waked up and start asking account synchronizing object +// If account is deleted, asking about access to read account can throw memory exception (reading for +// a synchronizing object from memory, that was deleted) +//So, we cannot now delete account. We have to wait until we are sure no thread will be using account anymore +// (or to the end of Miranda, but problem is in allocated memory- it is allocated and Miranda is SMALLER, faster, easier, isn't it?) +// This deleting is achieved in 2 ways: +// We have event in UsingThreads synchronization objects. This event signals that no thread will use actual account +// 1. Any thread using account first increment UsingThread, so we know that account is used +// 2. If thread is about to close, it should decrement UsingThread +// 3. If thread creates another thread, that will use account, caller has to wait until the new thread does not +// increment UsingThreads (imagine that caller ends before the new thread set it: if no other thread is using +// account, account is automaticaly (decreasing UsingThreads) signaled as "not used" and we delete it. But then +// new thread is going to read account...). +//4. wait until UsingThread Event is signaled +//5. delete account from memory + + HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; + HACCOUNT Which=(HACCOUNT)lParam; + HACCOUNT Finder; + DWORD tid; + +//1. set stop signal + StopSignalFcn(Which); + WindowList_BroadcastAsync(YAMNVar.MessageWnds,WM_YAMN_STOPACCOUNT,(WPARAM)Which,(LPARAM)0); + if (Plugin->Fcn->StopAccountFcnPtr!=NULL) + Plugin->Fcn->StopAccountFcnPtr(Which); + +//2. wait to get write access +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write wait\n"); +#endif + SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write enter\n"); +#endif + +//3. remove from queue (chained list) + if (Plugin->FirstAccount==NULL) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write done\n"); +#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); + return 0; + } + if (Plugin->FirstAccount==Which) + { + Finder=Plugin->FirstAccount->Next; + Plugin->FirstAccount=Finder; + } + else + { + for (Finder=Plugin->FirstAccount;Which!=Finder->Next;Finder=Finder->Next); + Finder->Next=Finder->Next->Next; + } +//leave write access +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteAccount:AccountBrowserSO-write done\n"); +#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); + +//4. wait while event "UsingThread" is not signaled +// And what to do, if this event will be signaled in 1 hour? (Although it's paranoia, because we have sent "delete signal", so +// other threads do not start any new work with actual account) We will wait in blocked state? +// No, of course not. We will create new thread, that will wait and additionally remove our thread in background. +//5. So, the last point (deleting from memory) is performed in new DeleteAccountInBackground thread + + if ((Plugin->Fcn!=NULL) && (Plugin->Fcn->WriteAccountsFcnPtr!=NULL)) + Plugin->Fcn->WriteAccountsFcnPtr(); + CloseHandle(CreateThread(NULL,0,DeleteAccountInBackground,(LPVOID)Which,0,&tid)); + +//Now, plugin can consider account as deleted, but plugin really can achieve deleting this account from memory when using +//event UsingThreads. + return 1; +} + +DWORD WINAPI DeleteAccountInBackground(LPVOID Value) +{ + HACCOUNT Which=(HACCOUNT)Value; + WaitForSingleObject(Which->UsingThreads->Event,INFINITE); + CallService(MS_YAMN_DELETEPLUGINACCOUNT,(WPARAM)Which,(LPARAM)0); + return 0; +} + +int StopAccounts(HYAMNPROTOPLUGIN Plugin) +{ + HACCOUNT Finder; + +//1. wait to get write access +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write wait\n"); +#endif + SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write enter\n"); +#endif + for (Finder=Plugin->FirstAccount;Finder!=NULL;Finder=Finder->Next) + { +//2. set stop signal + StopSignalFcn(Finder); + WindowList_BroadcastAsync(YAMNVar.MessageWnds,WM_YAMN_STOPACCOUNT,(WPARAM)Finder,(LPARAM)0); + if (Plugin->Fcn->StopAccountFcnPtr!=NULL) + Plugin->Fcn->StopAccountFcnPtr(Finder); + } + +//leave write access +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"StopAccounts:AccountBrowserSO-write done\n"); +#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); + +//Now, account is stopped. It can be removed from memory... + return 1; +} + +int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin,BOOL GetAccountBrowserAccess) +{ + HACCOUNT Finder; + + if (GetAccountBrowserAccess) + { +//1. wait to get write access +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write wait\n"); +#endif + SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write enter\n"); +#endif + } + for (Finder=Plugin->FirstAccount;Finder!=NULL;Finder=Finder->Next) + { +//2. wait for signal that account is not in use +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WaitForAllAccounts:waiting for UsingThreadEV %x (account %x)\n",Finder->UsingThreads,Finder); +#endif + WaitForSingleObject(Finder->UsingThreads->Event,INFINITE); + SetEvent(Finder->UsingThreads->Event); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WaitForAllAccounts:UsingThreadEV signaled\n"); +#endif + } + if (GetAccountBrowserAccess) + { +//leave write access +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"WaitForAllAccounts:AccountBrowserSO-write done\n"); +#endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); + } + + return 1; +} + +int DeleteAccounts(HYAMNPROTOPLUGIN Plugin) +{ + HACCOUNT Finder; + + //1. wait to get write access + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write wait\n"); + #endif + SWMRGWaitToWrite(Plugin->AccountBrowserSO,INFINITE); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write enter\n"); + #endif + + WaitForAllAccounts(Plugin,FALSE); + + for (Finder=Plugin->FirstAccount;Finder!=NULL;) + { + HACCOUNT Next = Finder->Next; + DeletePluginAccountSvc((WPARAM)Finder,(LPARAM)0); + Finder = Next; + } + + //leave write access + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteAccounts:AccountBrowserSO-write done\n"); + #endif + SWMRGDoneWriting(Plugin->AccountBrowserSO); + + return 1; +} + +void WINAPI GetStatusFcn(HACCOUNT Which,TCHAR *Value) +{ + if (Which==NULL) + return; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tGetStatus:AccountStatusCS-cs wait\n"); +#endif + EnterCriticalSection(&AccountStatusCS); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tGetStatus:AccountStatusCS-cs enter\n"); +#endif + lstrcpy(Value,Which->Status); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tGetStatus:AccountStatusCS-cs done\n"); +#endif + LeaveCriticalSection(&AccountStatusCS); + return; +} + +void WINAPI SetStatusFcn(HACCOUNT Which,TCHAR *Value) +{ + if (Which==NULL) + return; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tSetStatus:AccountStatusCS-cs wait\n"); +#endif + EnterCriticalSection(&AccountStatusCS); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tSetStatus:AccountStatusCS-cs enter\n"); +#endif + lstrcpy(Which->Status,Value); + WindowList_BroadcastAsync(YAMNVar.MessageWnds,WM_YAMN_CHANGESTATUS,(WPARAM)Which,(LPARAM)0); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tSetStatus:AccountStatusCS-cs done\n"); +#endif + LeaveCriticalSection(&AccountStatusCS); +} + +/* +#ifdef DEBUG_ACCOUNTS +int GetAccounts() +{ + HACCOUNT Finder; + int cnt=0; + + for (Finder=Account;Finder!=NULL;Finder=Finder->Next) + cnt++; + return cnt; +} + +void WriteAccounts() +{ + HACCOUNT Finder; + + for (Finder=Account;Finder!=NULL;Finder=Finder->Next) + MessageBoxA(NULL,Finder->Name,"Browsing account",MB_OK); +} +#endif +*/ diff --git a/protocols/YAMN/src/browser/badconnect.cpp b/protocols/YAMN/src/browser/badconnect.cpp new file mode 100644 index 0000000000..785508d066 --- /dev/null +++ b/protocols/YAMN/src/browser/badconnect.cpp @@ -0,0 +1,345 @@ +/* + * This code implements window handling (connection error) + * + * (c) majvan 2002,2004 + */ + +#include "../yamn.h" +#include "../main.h" + +#define BADCONNECTTITLE "%s - connection error" +#define BADCONNECTMSG "An error occured. Error code: %d" + +//-------------------------------------------------------------------------------------------------- + +LRESULT CALLBACK BadConnectPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) +{ + DWORD PluginParam; + switch(msg) + { + case WM_COMMAND: + if ((HIWORD(wParam)==STN_CLICKED) && (CallService(MS_POPUP_GETPLUGINDATA,(WPARAM)hWnd,(LPARAM)&PluginParam))) //if clicked and it's new mail popup window + { + PROCESS_INFORMATION pi; + STARTUPINFOW si; + HACCOUNT ActualAccount; + + ZeroMemory(&si,sizeof(si)); + si.cb=sizeof(si); + ActualAccount=(HACCOUNT)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read wait\n"); +#endif + if (WAIT_OBJECT_0==WaitToReadFcn(ActualAccount->AccountAccessSO)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter\n"); +#endif + if (ActualAccount->BadConnectN.App!=NULL) + { + WCHAR *Command; + if (ActualAccount->BadConnectN.AppParam!=NULL) + Command=new WCHAR[wcslen(ActualAccount->BadConnectN.App)+wcslen(ActualAccount->BadConnectN.AppParam)+6]; + else + Command=new WCHAR[wcslen(ActualAccount->BadConnectN.App)+6]; + + if (Command!=NULL) + { + lstrcpyW(Command,L"\""); + lstrcatW(Command,ActualAccount->BadConnectN.App); + lstrcatW(Command,L"\" "); + if (ActualAccount->BadConnectN.AppParam!=NULL) + lstrcatW(Command,ActualAccount->BadConnectN.AppParam); + CreateProcessW(NULL,Command,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); + delete[] Command; + } + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read done\n"); +#endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + } +#ifdef DEBUG_SYNCHRO + else + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter failed\n"); +#endif + SendMessage(hWnd,UM_DESTROYPOPUP,0,0); + } + break; + case UM_FREEPLUGINDATA: + //Here we'd free our own data, if we had it. + return FALSE; + case UM_INITPOPUP: + //This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups. + break; + case WM_CONTEXTMENU: + SendMessage(hWnd,UM_DESTROYPOPUP,0,0); + break; + case WM_NOTIFY: +/* switch(((LPNMHDR)lParam)->code) + { + case NM_CLICK: + { + } + } + break; +*/ default: + break; + } + return DefWindowProc(hWnd,msg,wParam,lParam); +} + +INT_PTR CALLBACK DlgProcYAMNBadConnection(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch(msg) + { + case WM_INITDIALOG: + { + BOOL ShowPopUp,ShowMsg,ShowIco; + HACCOUNT ActualAccount; + DWORD ErrorCode; + char* TitleStrA; + char *Message1A=NULL; + TCHAR *Message1W=NULL; + POPUPDATAT BadConnectPopUp; + + ActualAccount=((struct BadConnectionParam *)lParam)->account; + ErrorCode=((struct BadConnectionParam *)lParam)->errcode; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait\n"); +#endif + if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait failed\n"); +#endif + return FALSE; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read enter\n"); +#endif + TitleStrA = new char[strlen(ActualAccount->Name)+strlen(Translate(BADCONNECTTITLE))]; + wsprintfA(TitleStrA,Translate(BADCONNECTTITLE),ActualAccount->Name); + + ShowPopUp=ActualAccount->BadConnectN.Flags & YAMN_ACC_POP; + ShowMsg=ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG; + ShowIco=ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO; + + if (ShowPopUp) + { + BadConnectPopUp.lchContact=ActualAccount; + BadConnectPopUp.lchIcon=g_LoadIconEx(3); + BadConnectPopUp.colorBack=ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? ActualAccount->BadConnectN.PopUpB : GetSysColor(COLOR_BTNFACE); + BadConnectPopUp.colorText=ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? ActualAccount->BadConnectN.PopUpT : GetSysColor(COLOR_WINDOWTEXT); + BadConnectPopUp.iSeconds=ActualAccount->BadConnectN.PopUpTime; + + BadConnectPopUp.PluginWindowProc=BadConnectPopUpProc; + BadConnectPopUp.PluginData=0; //it's bad connect popup + lstrcpyn(BadConnectPopUp.lptzContactName,_A2T(ActualAccount->Name),SIZEOF(BadConnectPopUp.lptzContactName)); + } + + if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr!=NULL) + { + Message1W=ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode); + SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); + lstrcpyn(BadConnectPopUp.lptzText,Message1W,sizeof(BadConnectPopUp.lptzText)); + if (ShowPopUp) + PUAddPopUpT(&BadConnectPopUp); + } + else if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->GetErrorStringAFcnPtr!=NULL) + { + Message1W=ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode); + SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); + lstrcpyn(BadConnectPopUp.lptzText,Message1W,sizeof(BadConnectPopUp.lptzText)); + if (ShowPopUp) + PUAddPopUpT(&BadConnectPopUp); + } + else + { + Message1W=TranslateT("Unknown error"); + SetDlgItemText(hDlg,IDC_STATICMSG,Message1W); + lstrcpyn(BadConnectPopUp.lptzText,Message1W,sizeof(BadConnectPopUp.lptzText)); + if (ShowPopUp) + PUAddPopUpT(&BadConnectPopUp); + } + + if (!ShowMsg && !ShowIco) + DestroyWindow(hDlg); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read done\n"); +#endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + + SetWindowTextA(hDlg, TitleStrA); + delete[] TitleStrA; + if (Message1A!=NULL) + delete[] Message1A; + if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr!=NULL && Message1A!=NULL) + ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr(Message1A); + if (ActualAccount->Plugin->Fcn!=NULL && ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr!=NULL && Message1W!=NULL) + ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr(Message1W); + return 0; + } + case WM_DESTROY: + { + NOTIFYICONDATA nid; + + ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); + nid.cbSize=sizeof(NOTIFYICONDATA); + nid.hWnd=hDlg; + nid.uID=0; + Shell_NotifyIcon(NIM_DELETE,&nid); + PostQuitMessage(0); + break; + } + case WM_YAMN_NOTIFYICON: + switch (lParam) + { + case WM_LBUTTONDBLCLK: + ShowWindow(hDlg,SW_SHOWNORMAL); + SetForegroundWindow(hDlg); + break; + } + return 0; + case WM_CHAR: + switch((TCHAR)wParam) + { + case 27: + case 13: + DestroyWindow(hDlg); + break; + } + break; + case WM_SYSCOMMAND: + switch(wParam) + { + case SC_CLOSE: + DestroyWindow(hDlg); + break; + } + case WM_COMMAND: + { + WORD wNotifyCode = HIWORD(wParam); + switch(LOWORD(wParam)) + { + case IDC_BTNOK: + DestroyWindow(hDlg); + break; + } + break; + } + } + return 0; +} + +DWORD WINAPI BadConnection(LPVOID Param) +{ + MSG msg; + HWND hBadConnect; + HACCOUNT ActualAccount; + struct BadConnectionParam MyParam; + NOTIFYICONDATA nid; + char *NotIconText = Translate(" - connection error"), *src; + TCHAR *dest; + int i; + + MyParam=*(struct BadConnectionParam *)Param; + ActualAccount=MyParam.account; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:Incrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); +#endif + SCIncFcn(ActualAccount->UsingThreads); + +// we will not use params in stack anymore + SetEvent(MyParam.ThreadRunningEV); + + __try + { + hBadConnect=CreateDialogParam(YAMNVar.hInst,MAKEINTRESOURCE(IDD_DLGBADCONNECT),NULL,DlgProcYAMNBadConnection,(LPARAM)&MyParam); + SendMessage(hBadConnect,WM_SETICON,ICON_BIG,(LPARAM)g_LoadIconEx(3)); + SendMessage(hBadConnect,WM_SETICON,ICON_SMALL,(LPARAM)g_LoadIconEx(3)); + + ZeroMemory(&nid,sizeof(nid)); + nid.cbSize=sizeof(NOTIFYICONDATA); + nid.hWnd=hBadConnect; + nid.hIcon=g_LoadIconEx(3); + nid.uID=0; + nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP; + nid.uCallbackMessage=WM_YAMN_NOTIFYICON; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait\n"); +#endif + if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read wait failed\n"); +#endif + return 0; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read enter\n"); +#endif + for (src=ActualAccount->Name,dest=nid.szTip,i=0;(*src!=(TCHAR)0) && (i+1BadConnectN.Flags & YAMN_ACC_SND) + CallService(MS_SKIN_PLAYSOUND,0,(LPARAM)YAMN_CONNECTFAILSOUND); + if (ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG) + ShowWindow(hBadConnect,SW_SHOWNORMAL); + if (ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO) + Shell_NotifyIcon(NIM_ADD,&nid); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:ActualAccountSO-read done\n"); +#endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + + UpdateWindow(hBadConnect); + while(GetMessage(&msg,NULL,0,0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + +// now, write to file. Why? Because we want to write when was new mail last checked + if ((ActualAccount->Plugin->Fcn!=NULL) && (ActualAccount->Plugin->Fcn->WriteAccountsFcnPtr!=NULL) && ActualAccount->AbleToWork) + ActualAccount->Plugin->Fcn->WriteAccountsFcnPtr(); + } + __finally + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"BadConnect:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); +#endif + SCDecFcn(ActualAccount->UsingThreads); + } + return 0; +} + + +INT_PTR RunBadConnectionSvc(WPARAM wParam,LPARAM lParam) +{ + DWORD tid; +//an event for successfull copy parameters to which point a pointer in stack for new thread + HANDLE ThreadRunningEV; + PYAMN_BADCONNECTIONPARAM Param=(PYAMN_BADCONNECTIONPARAM)wParam; + + if ((DWORD)lParam!=YAMN_BADCONNECTIONVERSION) + return 0; + + if (NULL!=(ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) + { + HANDLE NewThread; + + Param->ThreadRunningEV=ThreadRunningEV; + if (NULL!=(NewThread=CreateThread(NULL,0,BadConnection,Param,0,&tid))) + { + WaitForSingleObject(ThreadRunningEV,INFINITE); + CloseHandle(NewThread); + } + CloseHandle(ThreadRunningEV); + + return 1; + } + return 0; +} diff --git a/protocols/YAMN/src/browser/m_browser.h b/protocols/YAMN/src/browser/m_browser.h new file mode 100644 index 0000000000..8b05e3d84a --- /dev/null +++ b/protocols/YAMN/src/browser/m_browser.h @@ -0,0 +1,42 @@ +#ifndef __MAILBROWSER_H +#define __MAILBROWSER_H + +#include "m_account.h" +#include "../debug.h" + +typedef struct MailBrowserWinParam +{ +#define YAMN_MAILBROWSERVERSION 1 + HANDLE ThreadRunningEV; + HACCOUNT account; + DWORD nflags; //flags YAMN_ACC_??? when new mails + DWORD nnflags; //flags YAMN_ACC_??? when no new mails + void *Param; +} YAMN_MAILBROWSERPARAM,*PYAMN_MAILBROWSERPARAM; + +typedef struct MailShowMsgWinParam +{ + HANDLE ThreadRunningEV; + HACCOUNT account; + HYAMNMAIL mail; +} YAMN_MAILSHOWPARAM, *PYAMN_MAILSHOWPARAM; + +typedef struct NoNewMailParam +{ +#define YAMN_NONEWMAILVERSION 1 + HANDLE ThreadRunningEV; + HACCOUNT account; + DWORD flags; + void *Param; +} YAMN_NONEWMAILPARAM,*PYAMN_NONEWMAILPARAM; + +typedef struct BadConnectionParam +{ +#define YAMN_BADCONNECTIONVERSION 1 + HANDLE ThreadRunningEV; + HACCOUNT account; + UINT_PTR errcode; + void *Param; +} YAMN_BADCONNECTIONPARAM,*PYAMN_BADCONNECTIONPARAM; + +#endif diff --git a/protocols/YAMN/src/browser/mailbrowser.cpp b/protocols/YAMN/src/browser/mailbrowser.cpp new file mode 100644 index 0000000000..15b24d0356 --- /dev/null +++ b/protocols/YAMN/src/browser/mailbrowser.cpp @@ -0,0 +1,2605 @@ +/* + * This code implements window handling (new mail) + * + * (c) majvan 2002-2004 + */ +/* There can be problems when compiling this file, because in this file + * we are using both unicode and no-unicode functions and compiler does not + * like it in one file + * When you got errors, try to comment the #define and compile, then + * put it back to uncommented and compile again :) + */ +#ifndef _WIN32_IE + #define _WIN32_IE 0x0400 +#endif +#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 +#endif + +#include "../yamn.h" +#include "../main.h" + +#define TIMER_FLASHING 0x09061979 +#define MAILBROWSER_MINXSIZE 200 //min size of mail browser window +#define MAILBROWSER_MINYSIZE 130 + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- +char* s_MonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +bool bDate = false,bSub=false,bSize=false,bFrom=false; +int PosX=0,PosY=0,SizeX=460,SizeY=100; +int HeadSizeX = 0x2b2, HeadSizeY = 0x0b5, HeadPosX = 100, HeadPosY = 100; +int HeadSplitPos=250; // per-mils of the size +static int FromWidth=250,SubjectWidth=280,SizeWidth=50,SizeDate=205; +unsigned char optDateTime = (SHOWDATELONG | SHOWDATENOTODAY); + +static WNDPROC OldListViewSubclassProc; + +struct CMailNumbersSub +{ + int Total; //any mail + int New; //uses YAMN_MSG_NEW flag + int UnSeen; //uses YAMN_MSG_UNSEEN flag +// int Browser; //uses YAMN_MSG_BROWSER flag + int BrowserUC; //uses YAMN_MSG_BROWSER flag and YAMN_MSG_UNSEEN flag + int Display; //uses YAMN_MSG_DISPLAY flag + int DisplayTC; //uses YAMN_MSG_DISPLAY flag and YAMN_MSG_DISPLAYC flag + int DisplayUC; //uses YAMN_MSG_DISPLAY flag and YAMN_MSG_DISPLAYC flag and YAMN_MSG_UNSEEN flag + int PopUp; //uses YAMN_MSG_POPUP flag + int PopUpTC; //uses YAMN_MSG_POPUPC flag + int PopUpNC; //uses YAMN_MSG_POPUPC flag and YAMN_MSG_NEW flag + int PopUpRun; //uses YAMN_MSG_POPUP flag and YAMN_MSG_NEW flag + int PopUpSL2NC; //uses YAMN_MSG_SPAML2 flag and YAMN_MSG_NEW flag + int PopUpSL3NC; //uses YAMN_MSG_SPAML3 flag and YAMN_MSG_NEW flag +// int SysTray; //uses YAMN_MSG_SYSTRAY flag + int SysTrayUC; //uses YAMN_MSG_SYSTRAY flag and YAMN_MSG_UNSEEN flag +// int Sound; //uses YAMN_MSG_SOUND flag + int SoundNC; //uses YAMN_MSG_SOUND flag and YAMN_MSG_NEW flag +// int App; //uses YAMN_MSG_APP flag + int AppNC; //uses YAMN_MSG_APP flag and YAMN_MSG_NEW flag + int EventNC; //uses YAMN_MSG_NEVENT flag and YAMN_MSG_NEW flag +}; + +struct CMailNumbers +{ + struct CMailNumbersSub Real; + struct CMailNumbersSub Virtual; +}; + +struct CMailWinUserInfo +{ + HACCOUNT Account; + int TrayIconState; + BOOL UpdateMailsMessagesAccess; + BOOL Seen; + BOOL RunFirstTime; +}; + +struct CChangeContent +{ + DWORD nflags; + DWORD nnflags; +}; + +struct CUpdateMails +{ + struct CChangeContent *Flags; + BOOL Waiting; + HANDLE Copied; +}; +struct CSortList +{ + HWND hDlg; + int iSubItem; +}; + +//Retrieves HACCOUNT, whose mails are displayed in ListMails +// hLM- handle of dialog window +// returns handle of account +inline HACCOUNT GetWindowAccount(HWND hDialog); + +//Looks to mail flags and increment mail counter (e.g. if mail is new, increments the new mail counter +// msgq- mail, which increments the counters +// MN- counnters structure +void IncrementMailCounters(HYAMNMAIL msgq,struct CMailNumbers *MN); + +enum +{ + UPDATE_FAIL=0, //function failed + UPDATE_NONE, //none update has been performed + UPDATE_OK, //some changes occured, update performed +}; +//Just looks for mail changes in account and update the mail browser window +// hDlg- dialog handle +// ActualAccount- account handle +// nflags- flags what to do when new mail arrives +// nnflags- flags what to do when no new mail arrives +// returns one of UPDATE_XXX value(not implemented yet) +int UpdateMails(HWND hDlg,HACCOUNT ActualAccount,DWORD nflags,DWORD nnflags); + +//When new mail occurs, shows window, plays sound, runs application... +// hDlg- dialog handle. Dialog of mailbrowser is already created and actions are performed over this window +// ActualAccount- handle of account, whose mails are to be notified +// MN- statistics of mails in account +// nflags- what to do or not to do (e.g. to show mailbrowser window or prohibit to show) +// nflags- flags what to do when new mail arrives +// nnflags- flags what to do when no new mail arrives +void DoMailActions(HWND hDlg,HACCOUNT ActualAccount,struct CMailNumbers *MN,DWORD nflags,DWORD nnflags); + +//Looks for items in mailbrowser and if they were deleted, delete them from browser window +// hListView- handle of listview window +// ActualAccount- handle of account, whose mails are show +// MailNumbers- pointer to structure, in which function stores numbers of mails with some property +// returns one of UPDATE_XXX value (not implemented yet) +int ChangeExistingMailStatus(HWND hListView,HACCOUNT ActualAccount,struct CMailNumbers *MN); + +//Adds new mails to ListView and if any new, shows multi popup (every new message is new popup window created by popup plugin) +// hListView- handle of listview window +// ActualAccount- handle of account, whose mails are show +// NewMailPopUp- pointer to prepared structure for popup plugin, can be NULL if no popup show +// MailNumbers- pointer to structure, in which function stores numbers of mails with some property +// nflags- flags what to do when new mail arrives +// returns one of UPDATE_XXX value (not implemented yet) +int AddNewMailsToListView(HWND hListView,HACCOUNT ActualAccount,struct CMailNumbers *MailNumbers,DWORD nflags); + +//Window callback procedure for popup window (created by popup plugin) +LRESULT CALLBACK NewMailPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam); + +//Window callback procedure for popup window (created by popup plugin) +LRESULT CALLBACK NoNewMailPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam); + +//Dialog callback procedure for mail browser +INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam); + +//MailBrowser thread function creates window if needed, tray icon and plays sound +DWORD WINAPI MailBrowser(LPVOID Param); + +LRESULT CALLBACK ListViewSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + +//Runs mail browser in new thread +INT_PTR RunMailBrowserSvc(WPARAM,LPARAM); + +#define YAMN_BROWSER_SHOWPOPUP 0x01 + + // list view items' order criteria + #define LVORDER_NOORDER -1 + #define LVORDER_STRING 0 + #define LVORDER_NUMERIC 1 + #define LVORDER_DATETIME 2 + + // list view order direction + #define LVORDER_ASCENDING 1 + #define LVORDER_NONE 0 + #define LVORDER_DESCENDING -1 + + // list view sort type + #define LVSORTPRIORITY_NONE -1 + + // List view column info. + typedef struct _SAMPLELISTVIEWCOLUMN + { + UINT uCXCol; // index + int nSortType; // sorting type (STRING = 0, NUMERIC, DATE, DATETIME) + int nSortOrder; // sorting order (ASCENDING = -1, NONE, DESCENDING) + int nPriority; // sort priority (-1 for none, 0, 1, ..., nColumns - 1 maximum) + TCHAR lpszName[128]; // column name + } SAMPLELISTVIEWCOLUMN; + + // Compare priority + typedef struct _LVCOMPAREINFO + { + int iIdx; // Index + int iPriority; // Priority + } LVCOMPAREINFO, *LPLVCOMPAREINFO; + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +LPARAM readItemLParam(HWND hwnd,DWORD iItem) +{ + LVITEM item; + + item.mask = LVIF_PARAM; + item.iItem = iItem; + item.iSubItem = 0; + SendMessage(hwnd,LVM_GETITEM,0,(LPARAM)&item); + return item.lParam; +} + +inline HACCOUNT GetWindowAccount(HWND hDlg) +{ + struct CMailWinUserInfo *mwui; + + if (NULL==(mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER))) + return NULL; + return mwui->Account; +} + +void IncrementMailCounters(HYAMNMAIL msgq,struct CMailNumbers *MN) +{ + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.Total++; + else + MN->Real.Total++; + + if (msgq->Flags & YAMN_MSG_NEW) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.New++; + else + MN->Real.New++; + if (msgq->Flags & YAMN_MSG_UNSEEN) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.UnSeen++; + else + MN->Real.UnSeen++; + if ((msgq->Flags & (YAMN_MSG_UNSEEN | YAMN_MSG_BROWSER)) == (YAMN_MSG_UNSEEN | YAMN_MSG_BROWSER)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.BrowserUC++; + else + MN->Real.BrowserUC++; + if (msgq->Flags & YAMN_MSG_DISPLAY) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.Display++; + else + MN->Real.Display++; + if ((msgq->Flags & (YAMN_MSG_DISPLAYC | YAMN_MSG_DISPLAY)) == (YAMN_MSG_DISPLAYC | YAMN_MSG_DISPLAY)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.DisplayTC++; + else + MN->Real.DisplayTC++; + if ((msgq->Flags & (YAMN_MSG_UNSEEN | YAMN_MSG_DISPLAYC | YAMN_MSG_DISPLAY)) == (YAMN_MSG_UNSEEN | YAMN_MSG_DISPLAYC | YAMN_MSG_DISPLAY)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.DisplayUC++; + else + MN->Real.DisplayUC++; + if (msgq->Flags & YAMN_MSG_POPUP) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.PopUp++; + else + MN->Real.PopUp++; + if ((msgq->Flags & YAMN_MSG_POPUPC) == YAMN_MSG_POPUPC) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.PopUpTC++; + else + MN->Real.PopUpTC++; + if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_POPUPC)) == (YAMN_MSG_NEW | YAMN_MSG_POPUPC)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.PopUpNC++; + else + MN->Real.PopUpNC++; + if ((msgq->Flags & (YAMN_MSG_NEW | YAMN_MSG_POPUP)) == (YAMN_MSG_NEW | YAMN_MSG_POPUP)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.PopUpRun++; + else + MN->Real.PopUpRun++; + if ((msgq->Flags & YAMN_MSG_NEW) && YAMN_MSG_SPAML(msgq->Flags,YAMN_MSG_SPAML2)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.PopUpSL2NC++; + else + MN->Real.PopUpSL2NC++; + if ((msgq->Flags & YAMN_MSG_NEW) && YAMN_MSG_SPAML(msgq->Flags,YAMN_MSG_SPAML3)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.PopUpSL3NC++; + else + MN->Real.PopUpSL3NC++; +/* if (msgq->MailData->Flags & YAMN_MSG_SYSTRAY) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.SysTray++; + else + MN->Real.SysTray++; +*/ if ((msgq->Flags & (YAMN_MSG_UNSEEN | YAMN_MSG_SYSTRAY)) == (YAMN_MSG_UNSEEN|YAMN_MSG_SYSTRAY)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.SysTrayUC++; + else + MN->Real.SysTrayUC++; +/* if (msgq->MailData->Flags & YAMN_MSG_SOUND) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.Sound++; + else + MN->Real.Sound++; +*/ if ((msgq->Flags & (YAMN_MSG_NEW|YAMN_MSG_SOUND)) == (YAMN_MSG_NEW|YAMN_MSG_SOUND)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.SoundNC++; + else + MN->Real.SoundNC++; +/* if (msgq->MailData->Flags & YAMN_MSG_APP) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.App++; + else + MN->Real.App++; +*/ if ((msgq->Flags & (YAMN_MSG_NEW|YAMN_MSG_APP)) == (YAMN_MSG_NEW|YAMN_MSG_APP)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.AppNC++; + else + MN->Real.AppNC++; + if ((msgq->Flags & (YAMN_MSG_NEW|YAMN_MSG_NEVENT)) == (YAMN_MSG_NEW|YAMN_MSG_NEVENT)) + if (msgq->Flags & YAMN_MSG_VIRTUAL) + MN->Virtual.EventNC++; + else + MN->Real.EventNC++; +} + +int UpdateMails(HWND hDlg,HACCOUNT ActualAccount,DWORD nflags,DWORD nnflags) +{ +#define MAILBROWSERTITLE "%s - %d new mail messages, %d total" + + struct CMailWinUserInfo *mwui; + struct CMailNumbers MN; + + HYAMNMAIL msgq; + BOOL Loaded; + BOOL RunMailBrowser,RunPopUps; + + mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER); + //now we ensure read access for account and write access for its mails + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read wait failed\n"); + #endif + PostMessage(hDlg,WM_DESTROY,(WPARAM)0,(LPARAM)0); + + return UPDATE_FAIL; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read enter\n"); + #endif + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UpdateMails:ActualAccountMsgsSO-write wait\n"); + #endif + if (WAIT_OBJECT_0!=WaitToWriteFcn(ActualAccount->MessagesAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UpdateMails:ActualAccountMsgsSO-write wait failed\n"); + DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + + PostMessage(hDlg,WM_DESTROY,(WPARAM)0,(LPARAM)0); + return UPDATE_FAIL; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UpdateMails:ActualAccountMsgsSO-write enter\n"); + #endif + + ZeroMemory(&MN,sizeof(MN)); + + for (msgq=(HYAMNMAIL)ActualAccount->Mails;msgq!=NULL;msgq=msgq->Next) + { + if (!LoadedMailData(msgq)) //check if mail is already in memory + { + Loaded=false; + if (NULL==LoadMailData(msgq)) //if we could not load mail to memory, consider this mail deleted and do not display it + continue; + } + else + Loaded=true; + + IncrementMailCounters(msgq,&MN); + + if (!Loaded) + UnloadMailData(msgq); //do not keep data for mail in memory + } + + if (mwui!=NULL) + mwui->UpdateMailsMessagesAccess=TRUE; + + //Now we are going to check if extracting data from mail headers are needed. + //If popups will be displayed or mailbrowser window + if ((((mwui!=NULL) && !(mwui->RunFirstTime)) && + ( + ((nnflags & YAMN_ACC_MSGP) && !(MN.Real.BrowserUC+MN.Virtual.BrowserUC)) || + ((nflags & YAMN_ACC_MSGP) && (MN.Real.BrowserUC+MN.Virtual.BrowserUC)) + ) + ) || //if mail window was displayed before and flag YAMN_ACC_MSGP is set + ((nnflags & YAMN_ACC_MSG) && !(MN.Real.BrowserUC+MN.Virtual.BrowserUC)) || //if needed to run mailbrowser when no unseen and no unseen mail found + ((nflags & YAMN_ACC_MSG) && (MN.Real.BrowserUC+MN.Virtual.BrowserUC)) || //if unseen mails found, we sure run mailbrowser + ((nflags & YAMN_ACC_ICO) && (MN.Real.SysTrayUC+MN.Virtual.SysTrayUC)) + ) //if needed to run systray + RunMailBrowser=TRUE; + else RunMailBrowser=FALSE; + + if ( (nflags & YAMN_ACC_POP) && + (ActualAccount->Flags & YAMN_ACC_POPN) && + (MN.Real.PopUpNC+MN.Virtual.PopUpNC)) //if some popups with mails are needed to show + RunPopUps=TRUE; + else RunPopUps=FALSE; + + if (RunMailBrowser) + ChangeExistingMailStatus(GetDlgItem(hDlg,IDC_LISTMAILS),ActualAccount,&MN); + if (RunMailBrowser || RunPopUps) + AddNewMailsToListView(hDlg==NULL ? NULL : GetDlgItem(hDlg,IDC_LISTMAILS),ActualAccount,&MN,nflags); + + if (RunMailBrowser) + { + size_t len = strlen(ActualAccount->Name)+strlen(Translate(MAILBROWSERTITLE))+10; //+10 chars for numbers + char *TitleStrA=new char[len]; + WCHAR *TitleStrW=new WCHAR[len]; + + sprintf(TitleStrA,Translate(MAILBROWSERTITLE),ActualAccount->Name,MN.Real.DisplayUC+MN.Virtual.DisplayUC,MN.Real.Display+MN.Virtual.Display); + MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,TitleStrA,-1,TitleStrW,(int)strlen(TitleStrA)+1); + SendMessageW(hDlg,WM_SETTEXT,(WPARAM)0,(LPARAM)TitleStrW); + delete[] TitleStrA; + delete[] TitleStrW; + } + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UpdateMails:Do mail actions\n"); + #endif + + DoMailActions(hDlg,ActualAccount,&MN,nflags,nnflags); + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UpdateMails:Do mail actions done\n"); + #endif + + SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails,YAMN_MSG_NEW,0,YAMN_MSG_NEW,YAMN_FLAG_REMOVE); //rempve the new flag + if (!RunMailBrowser) + SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails,YAMN_MSG_UNSEEN,YAMN_MSG_STAYUNSEEN,YAMN_MSG_UNSEEN,YAMN_FLAG_REMOVE); //remove the unseen flag when it was not displayed and it has not "stay unseen" flag set + + if (mwui!=NULL) + { + mwui->UpdateMailsMessagesAccess=FALSE; + mwui->RunFirstTime=FALSE; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UpdateMails:ActualAccountMsgsSO-write done\n"); + DebugLog(SynchroFile,"UpdateMails:ActualAccountSO-read done\n"); + #endif + WriteDoneFcn(ActualAccount->MessagesAccessSO); + ReadDoneFcn(ActualAccount->AccountAccessSO); + + if (RunMailBrowser) + UpdateWindow(GetDlgItem(hDlg,IDC_LISTMAILS)); + else if (hDlg!=NULL) + DestroyWindow(hDlg); + + return 1; +} + +int ChangeExistingMailStatus(HWND hListView,HACCOUNT ActualAccount,struct CMailNumbers *MN) +{ + int i,in; + LVITEMW item; + HYAMNMAIL mail,msgq; + + in=ListView_GetItemCount(hListView); + item.mask=LVIF_PARAM; + + for (i=0;iMails;(msgq!=NULL)&&(msgq!=mail);msgq=msgq->Next); //found the same mail in account queue + if (msgq==NULL) //if mail was not found + if (TRUE==ListView_DeleteItem(hListView,i)) + { + in--;i--; + continue; + } + } + + return TRUE; +} + +void MimeDateToLocalizedDateTime(char *datein, WCHAR *dateout, int lendateout); +int AddNewMailsToListView(HWND hListView,HACCOUNT ActualAccount,struct CMailNumbers *MN,DWORD nflags) +{ + HYAMNMAIL msgq; + POPUPDATAT NewMailPopUp = {0}; + + WCHAR *FromStr; + WCHAR SizeStr[20]; + WCHAR LocalDateStr[128]; + + LVITEMW item; + LVFINDINFO fi; + + int foundi,lfoundi; + struct CHeader UnicodeHeader; + BOOL Loaded,Extracted,FromStrNew=FALSE; + + ZeroMemory(&item,sizeof(item)); + ZeroMemory(&UnicodeHeader,sizeof(UnicodeHeader)); + + if (hListView!=NULL) + { + item.mask=LVIF_TEXT | LVIF_PARAM; + item.iItem=0; + ZeroMemory(&fi,sizeof(fi)); + fi.flags=LVFI_PARAM; //let's go search item by lParam number + lfoundi=0; + } + + NewMailPopUp.lchContact=(ActualAccount->hContact != NULL) ? ActualAccount->hContact : ActualAccount; + NewMailPopUp.lchIcon=g_LoadIconEx(2); + NewMailPopUp.colorBack=nflags & YAMN_ACC_POPC ? ActualAccount->NewMailN.PopUpB : GetSysColor(COLOR_BTNFACE); + NewMailPopUp.colorText=nflags & YAMN_ACC_POPC ? ActualAccount->NewMailN.PopUpT : GetSysColor(COLOR_WINDOWTEXT); + NewMailPopUp.iSeconds=ActualAccount->NewMailN.PopUpTime; + + NewMailPopUp.PluginWindowProc=NewMailPopUpProc; + NewMailPopUp.PluginData=(void *)0; //it's new mail popup + + for (msgq=(HYAMNMAIL)ActualAccount->Mails;msgq!=NULL;msgq=msgq->Next,lfoundi++) + { +// now we hide mail pointer to item's lParam member. We can later use it to retrieve mail datas + + Extracted=FALSE;FromStr=NULL;FromStrNew=FALSE; + + if (hListView!=NULL) + { + fi.lParam=(LPARAM)msgq; + if (-1!=(foundi=ListView_FindItem(hListView,-1,&fi))) //if mail is already in window + { + lfoundi=foundi; + continue; //do not insert any item + } + + item.iItem=lfoundi; //insert after last found item + item.lParam=(LPARAM)msgq; + } + + if (!LoadedMailData(msgq)) //check if mail is already in memory + { + Loaded=false; + if (NULL==LoadMailData(msgq)) //if we could not load mail to memory, consider this mail deleted and do not display it + continue; + } + else + Loaded=true; + + if (((hListView!=NULL) && (msgq->Flags & YAMN_MSG_DISPLAY)) || + ((nflags & YAMN_ACC_POP) && (ActualAccount->Flags & YAMN_ACC_POPN) && (msgq->Flags & YAMN_MSG_POPUP) && (msgq->Flags & YAMN_MSG_NEW))) + { + + if (!Extracted) ExtractHeader(msgq->MailData->TranslatedHeader,msgq->MailData->CP,&UnicodeHeader); + Extracted=TRUE; + + if ((UnicodeHeader.From!=NULL) && (UnicodeHeader.FromNick!=NULL)) + { + FromStr=new WCHAR[wcslen(UnicodeHeader.From)+wcslen(UnicodeHeader.FromNick)+4]; + swprintf(FromStr,L"%s <%s>",UnicodeHeader.FromNick,UnicodeHeader.From); + FromStrNew=TRUE; + } + else if (UnicodeHeader.From!=NULL) + FromStr=UnicodeHeader.From; + else if (UnicodeHeader.FromNick!=NULL) + FromStr=UnicodeHeader.FromNick; + else if (UnicodeHeader.ReturnPath!=NULL) + FromStr=UnicodeHeader.ReturnPath; + + if (NULL==FromStr) + { + FromStr=L""; + FromStrNew=FALSE; + } + } + + + if ((hListView!=NULL) && (msgq->Flags & YAMN_MSG_DISPLAY)) + { + item.iSubItem=0; + item.pszText=FromStr; + item.iItem=SendMessageW(hListView,LVM_INSERTITEMW,(WPARAM)0,(LPARAM)&item); + + item.iSubItem=1; + item.pszText=(NULL!=UnicodeHeader.Subject ? UnicodeHeader.Subject : (WCHAR*)L""); + SendMessageW(hListView,LVM_SETITEMTEXTW,(WPARAM)item.iItem,(LPARAM)&item); + + item.iSubItem=2; + swprintf(SizeStr,L"%d kB",msgq->MailData->Size/1024); + item.pszText=SizeStr; + SendMessageW(hListView,LVM_SETITEMTEXTW,(WPARAM)item.iItem,(LPARAM)&item); + + item.iSubItem=3; + item.pszText=L""; + { CMimeItem *heads; + for (heads=msgq->MailData->TranslatedHeader;heads!=NULL;heads=heads->Next) { + if (!_stricmp(heads->name,"Date")) { + MimeDateToLocalizedDateTime(heads->value,LocalDateStr,128); + item.pszText=LocalDateStr; + break; + } } } + SendMessageW(hListView,LVM_SETITEMTEXTW,(WPARAM)item.iItem,(LPARAM)&item); + } + + if ((nflags & YAMN_ACC_POP) && (ActualAccount->Flags & YAMN_ACC_POPN) && (msgq->Flags & YAMN_MSG_POPUP) && (msgq->Flags & YAMN_MSG_NEW)) + { + WideCharToMultiByte(CP_ACP,0,FromStr,-1,(char *)NewMailPopUp.lptzContactName,sizeof(NewMailPopUp.lptzContactName),NULL,NULL); + if (!WideCharToMultiByte(CP_ACP,0,UnicodeHeader.Subject,-1,(char *)NewMailPopUp.lptzText,sizeof(NewMailPopUp.lptzText),NULL,NULL)) + NewMailPopUp.lptzText[0]=0; + PYAMN_MAILSHOWPARAM MailParam = (PYAMN_MAILSHOWPARAM)malloc(sizeof(YAMN_MAILSHOWPARAM)); + if (MailParam) { + MailParam->account = ActualAccount; + MailParam->mail = msgq; + MailParam->ThreadRunningEV = 0; + NewMailPopUp.PluginData=MailParam; + PUAddPopUpT(&NewMailPopUp); + } + } + + if ((msgq->Flags & YAMN_MSG_UNSEEN) && (ActualAccount->NewMailN.Flags & YAMN_ACC_KBN)) + CallService(MS_KBDNOTIFY_EVENTSOPENED,(WPARAM)1,NULL); + + if (FromStrNew) + delete[] FromStr; + + if (Extracted) + { + DeleteHeaderContent(&UnicodeHeader); + ZeroMemory(&UnicodeHeader,sizeof(UnicodeHeader)); + } + + if (!Loaded) + { + SaveMailData(msgq); + UnloadMailData(msgq); //do not keep data for mail in memory + } + } + + return TRUE; +} + +void DoMailActions(HWND hDlg,HACCOUNT ActualAccount,struct CMailNumbers *MN,DWORD nflags,DWORD nnflags) +{ + char *NotIconText = Translate("- new mail message(s)"); + NOTIFYICONDATA nid; + + ZeroMemory(&nid,sizeof(nid)); + + if (MN->Real.EventNC+MN->Virtual.EventNC) + NotifyEventHooks(hNewMailHook,0,0); + + if ((nflags & YAMN_ACC_KBN) && (MN->Real.PopUpRun+MN->Virtual.PopUpRun)) + { + CallService(MS_KBDNOTIFY_STARTBLINK,(WPARAM)MN->Real.PopUpNC+MN->Virtual.PopUpNC,NULL); + } + + if ((nflags & YAMN_ACC_CONT) && (MN->Real.PopUpRun+MN->Virtual.PopUpRun)) + { + char sMsg[250]; + _snprintf(sMsg,249,Translate("%s : %d new mail message(s), %d total"),ActualAccount->Name,MN->Real.PopUpNC+MN->Virtual.PopUpNC,MN->Real.PopUpTC+MN->Virtual.PopUpTC); + if (!(nflags & YAMN_ACC_CONTNOEVENT)) { + CLISTEVENT cEvent; + cEvent.cbSize = sizeof(CLISTEVENT); + cEvent.hContact = ActualAccount->hContact; + cEvent.hIcon = g_LoadIconEx(2); + cEvent.hDbEvent = (HANDLE)ActualAccount->hContact; + cEvent.lParam = (LPARAM) ActualAccount->hContact; + cEvent.pszService = MS_YAMN_CLISTDBLCLICK; + cEvent.pszTooltip = sMsg; + cEvent.flags = 0; + CallServiceSync(MS_CLIST_ADDEVENT, 0,(LPARAM)&cEvent); + } + DBWriteContactSettingString(ActualAccount->hContact, "CList", "StatusMsg", sMsg); + + if (nflags & YAMN_ACC_CONTNICK) + { + DBWriteContactSettingString(ActualAccount->hContact, YAMN_DBMODULE, "Nick",sMsg); + } + } + + if ((nflags & YAMN_ACC_POP) && + !(ActualAccount->Flags & YAMN_ACC_POPN) && + (MN->Real.PopUpRun+MN->Virtual.PopUpRun)) + { + POPUPDATAT NewMailPopUp ={0}; + + NewMailPopUp.lchContact=(ActualAccount->hContact != NULL) ? ActualAccount->hContact : ActualAccount; + NewMailPopUp.lchIcon=g_LoadIconEx(2); + NewMailPopUp.colorBack=nflags & YAMN_ACC_POPC ? ActualAccount->NewMailN.PopUpB : GetSysColor(COLOR_BTNFACE); + NewMailPopUp.colorText=nflags & YAMN_ACC_POPC ? ActualAccount->NewMailN.PopUpT : GetSysColor(COLOR_WINDOWTEXT); + NewMailPopUp.iSeconds=ActualAccount->NewMailN.PopUpTime; + + NewMailPopUp.PluginWindowProc=NewMailPopUpProc; + NewMailPopUp.PluginData=(void *)0; //multiple popups + + lstrcpyn(NewMailPopUp.lptzContactName, _A2T(ActualAccount->Name),SIZEOF(NewMailPopUp.lptzContactName)); + wsprintf(NewMailPopUp.lptzText,TranslateT("%d new mail message(s), %d total"),MN->Real.PopUpNC+MN->Virtual.PopUpNC,MN->Real.PopUpTC+MN->Virtual.PopUpTC); + PUAddPopUpT(&NewMailPopUp); + } + + //destroy tray icon if no new mail + if ((MN->Real.SysTrayUC+MN->Virtual.SysTrayUC==0) && (hDlg!=NULL)) + { + nid.hWnd=hDlg; + nid.uID=0; + Shell_NotifyIcon(NIM_DELETE,&nid); + } + + //and remove the event + if ((nflags & YAMN_ACC_CONT) && (!(nflags & YAMN_ACC_CONTNOEVENT)) && (MN->Real.UnSeen + MN->Virtual.UnSeen==0)) { + CallService(MS_CLIST_REMOVEEVENT,(WPARAM)ActualAccount->hContact,(LPARAM)ActualAccount->hContact); + } + + if ((MN->Real.BrowserUC+MN->Virtual.BrowserUC==0) && (hDlg!=NULL)) + { + if (!IsWindowVisible(hDlg) && !(nflags & YAMN_ACC_MSG)) + PostMessage(hDlg,WM_DESTROY,(WPARAM)0,(LPARAM)0); //destroy window if no new mail and window is not visible + if (nnflags & YAMN_ACC_MSG) //if no new mail and msg should be executed + { + SetForegroundWindow(hDlg); + ShowWindow(hDlg,SW_SHOWNORMAL); + } + } + else + if (hDlg!=NULL) //else insert icon and set window if new mails + { + SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_SCROLL,(WPARAM)0,(LPARAM)0x7ffffff); + + if ((nflags & YAMN_ACC_ICO) && (MN->Real.SysTrayUC+MN->Virtual.SysTrayUC)) + { + char* src; + TCHAR *dest; + int i; + + for (src=ActualAccount->Name,dest=nid.szTip,i=0;(*src!=(TCHAR)0) && (i+1Real.AppNC+MN->Virtual.AppNC!=0) + { + if (nflags & YAMN_ACC_APP) + { + PROCESS_INFORMATION pi; + STARTUPINFOW si; + ZeroMemory(&si,sizeof(si)); + si.cb=sizeof(si); + + if (ActualAccount->NewMailN.App!=NULL) + { + WCHAR *Command; + if (ActualAccount->NewMailN.AppParam!=NULL) + Command=new WCHAR[wcslen(ActualAccount->NewMailN.App)+wcslen(ActualAccount->NewMailN.AppParam)+6]; + else + Command=new WCHAR[wcslen(ActualAccount->NewMailN.App)+6]; + + if (Command!=NULL) + { + lstrcpyW(Command,L"\""); + lstrcatW(Command,ActualAccount->NewMailN.App); + lstrcatW(Command,L"\" "); + if (ActualAccount->NewMailN.AppParam!=NULL) + lstrcatW(Command,ActualAccount->NewMailN.AppParam); + CreateProcessW(NULL,Command,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); + delete[] Command; + } + } + } + } + + if (MN->Real.SoundNC+MN->Virtual.SoundNC!=0) + if (nflags & YAMN_ACC_SND) + CallService(MS_SKIN_PLAYSOUND,0,(LPARAM)YAMN_NEWMAILSOUND); + + if ((nnflags & YAMN_ACC_POP) && (MN->Real.PopUpRun+MN->Virtual.PopUpRun==0)) + { + POPUPDATAT NoNewMailPopUp; + + NoNewMailPopUp.lchContact=(ActualAccount->hContact != NULL) ? ActualAccount->hContact : ActualAccount; + NoNewMailPopUp.lchIcon=g_LoadIconEx(1); + NoNewMailPopUp.colorBack=ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC ? ActualAccount->NoNewMailN.PopUpB : GetSysColor(COLOR_BTNFACE); + NoNewMailPopUp.colorText=ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC ? ActualAccount->NoNewMailN.PopUpT : GetSysColor(COLOR_WINDOWTEXT); + NoNewMailPopUp.iSeconds=ActualAccount->NoNewMailN.PopUpTime; + + NoNewMailPopUp.PluginWindowProc=NoNewMailPopUpProc; + NoNewMailPopUp.PluginData=(void *)0; //it's not new mail popup + + lstrcpyn(NoNewMailPopUp.lptzContactName,_A2T(ActualAccount->Name),SIZEOF(NoNewMailPopUp.lptzContactName)); + if (MN->Real.PopUpSL2NC+MN->Virtual.PopUpSL2NC) + wsprintf(NoNewMailPopUp.lptzText,TranslateT("No new mail message, %d spam(s)"),MN->Real.PopUpSL2NC+MN->Virtual.PopUpSL2NC); + else + lstrcpyn(NoNewMailPopUp.lptzText,TranslateT("No new mail message"),SIZEOF(NoNewMailPopUp.lptzText)); + PUAddPopUpT(&NoNewMailPopUp); + } + + if ((nflags & YAMN_ACC_CONT) && (MN->Real.PopUpRun+MN->Virtual.PopUpRun==0)) + { + if (ActualAccount->hContact != NULL) + { + if (MN->Real.PopUpTC+MN->Virtual.PopUpTC) + { + char tmp[255]; + sprintf(tmp,Translate("%d new mail message(s), %d total"),MN->Real.PopUpNC+MN->Virtual.PopUpNC,MN->Real.PopUpTC+MN->Virtual.PopUpTC); + DBWriteContactSettingString(ActualAccount->hContact, "CList", "StatusMsg", tmp); + } + else + DBWriteContactSettingString(ActualAccount->hContact, "CList", "StatusMsg", Translate("No new mail message")); + + if (nflags & YAMN_ACC_CONTNICK) + { + DBWriteContactSettingString(ActualAccount->hContact, YAMN_DBMODULE, "Nick", ActualAccount->Name); + } + } + } + return; +} + +DWORD WINAPI ShowEmailThread(LPVOID Param); +LRESULT CALLBACK NewMailPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) +{ + INT_PTR PluginParam=0; + switch(msg) + { + case WM_COMMAND: + //if clicked and it's new mail popup window + if ((HIWORD(wParam)==STN_CLICKED) && (-1!=(PluginParam=CallService(MS_POPUP_GETPLUGINDATA,(WPARAM)hWnd,(LPARAM)&PluginParam)))) + { + HANDLE hContact = 0; + HACCOUNT Account; + if (PluginParam){ + PYAMN_MAILSHOWPARAM MailParam = new YAMN_MAILSHOWPARAM; + memcpy(MailParam,(PINT_PTR)PluginParam,sizeof(YAMN_MAILSHOWPARAM)); + hContact = MailParam->account->hContact; + Account = MailParam->account; + if (NULL!=(MailParam->ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) { + HANDLE NewThread; + if (NULL!=(NewThread=CreateThread(NULL,0,ShowEmailThread,(LPVOID)MailParam,0,NULL))) + { + CloseHandle(NewThread); + } + CloseHandle(MailParam->ThreadRunningEV); + } + //delete MailParam; + } else { + DBVARIANT dbv; + + hContact=(HANDLE)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); + + if (!DBGetContactSetting((HANDLE) hContact,YAMN_DBMODULE,"Id",&dbv)) + { + Account=(HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)dbv.pszVal); + DBFreeVariant(&dbv); + } + else + Account = (HACCOUNT) hContact; //???? + + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0==WaitToReadFcn(Account->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter\n"); + #endif + switch(msg) + { + case WM_COMMAND: + { + YAMN_MAILBROWSERPARAM Param={(HANDLE)0,Account, + (Account->NewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG, + (Account->NoNewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG}; + + RunMailBrowserSvc((WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); + } + break; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(Account->AccountAccessSO); + } + #ifdef DEBUG_SYNCHRO + else + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter failed\n"); + #endif + } + if ((Account->NewMailN.Flags & YAMN_ACC_CONT) && !(Account->NewMailN.Flags & YAMN_ACC_CONTNOEVENT)) { + CallService(MS_CLIST_REMOVEEVENT,(WPARAM)hContact,(LPARAM)hContact); + } + } + // fall through + case WM_CONTEXTMENU: + SendMessageW(hWnd,UM_DESTROYPOPUP,0,0); + break; + case UM_FREEPLUGINDATA:{ + PYAMN_MAILSHOWPARAM mpd = (PYAMN_MAILSHOWPARAM)PUGetPluginData(hWnd); + HANDLE hContact = 0; + if ((mpd) && (INT_PTR)mpd!=-1)free(mpd); + return FALSE; + } + case UM_INITPOPUP: + //This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups. + WindowList_Add(YAMNVar.MessageWnds,hWnd,NULL); + break; + case UM_DESTROYPOPUP: + WindowList_Remove(YAMNVar.MessageWnds,hWnd); + break; + case WM_YAMN_STOPACCOUNT: + { + HACCOUNT ActualAccount; + HANDLE hContact; + DBVARIANT dbv; + + hContact=(HANDLE)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); + + if (!DBGetContactSetting((HANDLE) hContact,YAMN_DBMODULE,"Id",&dbv)) + { + ActualAccount=(HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)dbv.pszVal); + DBFreeVariant(&dbv); + } + else + ActualAccount = (HACCOUNT) hContact; + + if ((HACCOUNT)wParam!=ActualAccount) + break; + DestroyWindow(hWnd); + return 0; + } + case WM_NOTIFY: + default: + break; + } + return DefWindowProc(hWnd,msg,wParam,lParam); +} + +LRESULT CALLBACK NoNewMailPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch(msg) + { + case WM_COMMAND: + if ((HIWORD(wParam)==STN_CLICKED) && (msg==WM_COMMAND)) + { + HACCOUNT ActualAccount; + HANDLE hContact; + DBVARIANT dbv; + + hContact=(HANDLE)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); + + if (!DBGetContactSetting((HANDLE) hContact,YAMN_DBMODULE,"Id",&dbv)) + { + ActualAccount=(HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)dbv.pszVal); + DBFreeVariant(&dbv); + } + else + ActualAccount = (HACCOUNT) hContact; + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0==WaitToReadFcn(ActualAccount->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter\n"); + #endif + switch(msg) + { + case WM_COMMAND: + { + YAMN_MAILBROWSERPARAM Param={(HANDLE)0,ActualAccount,ActualAccount->NewMailN.Flags,ActualAccount->NoNewMailN.Flags,0}; + + 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; + + RunMailBrowserSvc((WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); + } + break; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + } + #ifdef DEBUG_SYNCHRO + else + DebugLog(SynchroFile,"PopUpProc:LEFTCLICK:ActualAccountSO-read enter failed\n"); + #endif + SendMessageW(hWnd,UM_DESTROYPOPUP,0,0); + } + break; + + case WM_CONTEXTMENU: + SendMessageW(hWnd,UM_DESTROYPOPUP,0,0); + break; + + case UM_FREEPLUGINDATA: + //Here we'd free our own data, if we had it. + return FALSE; + case UM_INITPOPUP: + //This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups. + WindowList_Add(YAMNVar.MessageWnds,hWnd,NULL); + break; + case UM_DESTROYPOPUP: + WindowList_Remove(YAMNVar.MessageWnds,hWnd); + break; + case WM_YAMN_STOPACCOUNT: + { + HACCOUNT ActualAccount; + HANDLE hContact; + DBVARIANT dbv; + + hContact=(HANDLE)CallService(MS_POPUP_GETCONTACT,(WPARAM)hWnd,(LPARAM)0); + + if (!DBGetContactSetting((HANDLE) hContact,YAMN_DBMODULE,"Id",&dbv)) + { + ActualAccount=(HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)dbv.pszVal); + DBFreeVariant(&dbv); + } + else + ActualAccount = (HACCOUNT) hContact; + + if ((HACCOUNT)wParam!=ActualAccount) + break; + + DestroyWindow(hWnd); + return 0; + } + case WM_NOTIFY: +/* switch(((LPNMHDR)lParam)->code) + { + case NM_CLICK: + { + } + } + break; +*/ default: + break; + } + return DefWindowProc(hWnd,msg,wParam,lParam); +} + +#ifdef __GNUC__ +//number of 100 ns periods between FILETIME 0 (1601/01/01 00:00:00.0000000) and TIMESTAMP 0 (1970/01/01 00:00:00) +#define NUM100NANOSEC 116444736000000000ULL +//The biggest time Get[Date|Time]Format can handle (Fri, 31 Dec 30827 23:59:59.9999999) +#define MAXFILETIME 0x7FFF35F4F06C7FFFULL +#else +#define NUM100NANOSEC 116444736000000000 +#define MAXFILETIME 0x7FFF35F4F06C7FFF +#endif + +ULONGLONG MimeDateToFileTime(char *datein) +{ + char *day=0, *month=0, *year=0, *time=0, *shift=0; + SYSTEMTIME st; + ULONGLONG res=0; + int wShiftSeconds = CallService(MS_DB_TIME_TIMESTAMPTOLOCAL,0,0); + GetLocalTime(&st); + //datein = "Xxx, 1 Jan 2060 5:29:1 +0530 XXX"; + //datein = "Xxx, 1 Jan 2060 05:29:10 "; + //datein = " ManySpaces 1.5 Jan 2060 05::"; + //datein = "Xxx, 35 February 20 :29:10 "; + //datein = "01.12.2007 (22:38:17)"; // + if (datein){ + char tmp [64]; + while ( datein[0]==' ') datein++; // eat leading spaces + strncpy(tmp,datein,63); tmp [63]=0; + if (atoi(tmp)) { // Parseable integer on DayOfWeek field? Buggy mime date. + day = tmp; + } else { + int i = 0; + while (tmp[i]==' ')i++; if (day = strchr(&tmp[i],' ')){day[0]=0; day++;} + } + if (day) {while ( day[0]==' ') day++;if (month= strchr(day, ' ')){month[0]=0; month++;}} + if (month) {while (month[0]==' ')month++;if (year = strchr(month,' ')) { year[0]=0; year++;}} + if (year) {while ( year[0]==' ') year++;if (time = strchr(year, ' ')) { time[0]=0; time++;}} + if (time) {while ( time[0]==' ') time++;if (shift= strchr(time, ' ')){shift[0]=0; shift++;shift[5]=0;}} + + if (year){ + st.wYear = atoi(year); + if (strlen(year)<4) if (st.wYear<70)st.wYear += 2000; else st.wYear += 1900; + }; + if (month) for (int i=0;i<12;i++) if (strncmp(month,s_MonthNames[i],3)==0) {st.wMonth = i + 1; break;} + if (day) st.wDay = atoi(day); + if (time) { + char *h, *m, *s; + h = time; + if (m = strchr(h,':')) { + m[0]=0; m++; + if (s = strchr(m,':')){s[0] = 0; s++;} + } else s=0; + st.wHour = atoi(h); + st.wMinute = m?atoi(m):0; + st.wSecond = s?atoi(s):0; + } else {st.wHour=st.wMinute=st.wSecond=0;} + + if (shift){ + if (strlen(shift)<4) { + //has only hour + wShiftSeconds = (atoi(shift))*3600; + } else { + char *smin = shift + strlen(shift)-2; + int ismin = atoi(smin); + smin[0] = 0; + int ishour = atoi(shift); + wShiftSeconds = (ishour*60+(ishour<0?-1:1)*ismin)*60; + } + } + } // if (datein) + FILETIME ft; + if (SystemTimeToFileTime(&st,&ft)) { + res = ((ULONGLONG)ft.dwHighDateTime<<32)|((ULONGLONG)ft.dwLowDateTime); + LONGLONG w100nano = Int32x32To64((DWORD)wShiftSeconds,10000000); + res -= w100nano; + }else{ + res=0; + } + return res; +} + +void FileTimeToLocalizedDateTime(LONGLONG filetime, WCHAR *dateout, int lendateout){ + int localeID = CallService(MS_LANGPACK_GETLOCALE,0,0); + //int localeID = MAKELCID(LANG_URDU, SORT_DEFAULT); + if (localeID==CALLSERVICE_NOTFOUND) localeID=LOCALE_USER_DEFAULT; + if (filetime>MAXFILETIME) filetime = MAXFILETIME; + else if (filetime<=0) { + wcsncpy(dateout,TranslateW(L"Invalid"),lendateout); + return; + } + SYSTEMTIME st; + WORD wTodayYear, wTodayMonth, wTodayDay; + FILETIME ft; + BOOL willShowDate = !(optDateTime&SHOWDATENOTODAY); + if (!willShowDate){ + GetLocalTime(&st); + wTodayYear = st.wYear; + wTodayMonth = st.wMonth; + wTodayDay = st.wDay; + } + ft.dwLowDateTime = (DWORD)filetime; + ft.dwHighDateTime = (DWORD)(filetime >> 32); + FILETIME localft; + if (!FileTimeToLocalFileTime(&ft,&localft)) { + // this should never happen + wcsncpy(dateout,L"Incorrect FileTime",lendateout); + } else { + if (!FileTimeToSystemTime(&localft,&st)) { + // this should never happen + wcsncpy(dateout,L"Incorrect LocalFileTime",lendateout); + } else { + dateout[lendateout-1]=0; + int templen = 0; + if (!willShowDate) willShowDate = (wTodayYear!=st.wYear)||(wTodayMonth!=st.wMonth)||(wTodayDay!=st.wDay); + if (willShowDate){ + templen = GetDateFormatW(localeID,(optDateTime&SHOWDATELONG)?DATE_LONGDATE:DATE_SHORTDATE,&st,NULL,dateout,lendateout-2); + dateout[templen-1] = ' '; + } + if (templen<(lendateout-1)) { + GetTimeFormatW(localeID,(optDateTime&SHOWDATENOSECONDS)?TIME_NOSECONDS:0,&st,NULL,&dateout[templen],lendateout-templen-1); + } + } + } +} + +void MimeDateToLocalizedDateTime(char *datein, WCHAR *dateout, int lendateout) +{ + ULONGLONG ft = MimeDateToFileTime(datein); + FileTimeToLocalizedDateTime(ft,dateout,lendateout); +} + +int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2,LPARAM lParamSort ) { + if (lParam1 == NULL || lParam2 == NULL) + return 0; + + int nResult = 0; + char *str1; + char *str2; + HYAMNMAIL email1 = (HYAMNMAIL)lParam1; + HYAMNMAIL email2 = (HYAMNMAIL)lParam2; + struct CShortHeader Header1; + struct CShortHeader Header2; + ZeroMemory(&Header1,sizeof(Header1)); + ZeroMemory(&Header2,sizeof(Header2)); + + try { + ExtractShortHeader(email1->MailData->TranslatedHeader,&Header1); + ExtractShortHeader(email2->MailData->TranslatedHeader,&Header2); + + switch((int)lParamSort) + { + case 0: //From + if (Header1.FromNick == NULL) + str1 = Header1.From; + else str1 = Header1.FromNick; + + if (Header2.FromNick == NULL) + str2 = Header2.From; + else str2 = Header2.FromNick; + + nResult = strcmp(str1, str2); + + if (bFrom) nResult = -nResult; + break; + case 1: //Subject + if (Header1.Subject == NULL) + str1 = " "; + else str1 = Header1.Subject; + + if (Header2.Subject == NULL) + str2 = " "; + else str2 = Header2.Subject; + + nResult = strcmp(str1, str2); + + if (bSub) nResult = -nResult; + break; + case 2: //Size + if (email1->MailData->Size == email2->MailData->Size) nResult = 0; + if (email1->MailData->Size > email2->MailData->Size) nResult = 1; + if (email1->MailData->Size < email2->MailData->Size) nResult = -1; + + if (bSize) nResult = -nResult; + break; + + case 3: //Date + { + ULONGLONG ts1 = 0, ts2 = 0; + ts1 = MimeDateToFileTime(Header1.Date); + ts2 = MimeDateToFileTime(Header2.Date); + if (ts1 > ts2) nResult = 1; + else if (ts1 < ts2) nResult = -1; + else nResult = 0; + } + if (bDate) nResult = -nResult; + break; + + default: + if (Header1.Subject == NULL) str1 = " "; + else str1 = Header1.Subject; + + if (Header2.Subject == NULL) str2 = " "; + else str2 = Header2.Subject; + + nResult = strcmp(str1, str2); + break; + } + //MessageBox(NULL,str1,str2,0); + } + catch( ... ) + { + } + + //free mem + DeleteShortHeaderContent(&Header1); + DeleteShortHeaderContent(&Header2); + return nResult; + +} + +HCURSOR hCurSplitNS, hCurSplitWE; +static WNDPROC OldSplitterProc; +#define DM_SPLITTERMOVED (WM_USER+15) +static LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_NCHITTEST: + return HTCLIENT; + case WM_SETCURSOR: + { + SetCursor(hCurSplitNS); + return TRUE; + } + case WM_LBUTTONDOWN: + SetCapture(hwnd); + return 0; + case WM_MOUSEMOVE: + if (GetCapture() == hwnd) { + RECT rc; + GetClientRect(hwnd, &rc); + SendMessage(GetParent(hwnd), DM_SPLITTERMOVED, (short) HIWORD(GetMessagePos()) + rc.bottom / 2, (LPARAM) hwnd); + } + return 0; + case WM_LBUTTONUP: + ReleaseCapture(); + return 0; + } + return CallWindowProc(OldSplitterProc, hwnd, msg, wParam, lParam); +} + + +void ConvertCodedStringToUnicode(char *stream,WCHAR **storeto,DWORD cp,int mode); +int ConvertStringToUnicode(char *stream,unsigned int cp,WCHAR **out); +INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch(msg) + { + case WM_INITDIALOG: + { +// HIMAGELIST hIcons; + PYAMN_MAILSHOWPARAM MailParam = (PYAMN_MAILSHOWPARAM)lParam; + WCHAR *iHeaderW=NULL; + WCHAR *iValueW=NULL; + int StrLen; + HWND hListView = GetDlgItem(hDlg,IDC_LISTHEADERS); + OldSplitterProc = (WNDPROC) SetWindowLongPtr(GetDlgItem(hDlg, IDC_SPLITTER), GWLP_WNDPROC, (LONG_PTR) SplitterSubclassProc); + SetWindowLongPtr(hDlg,DWLP_USER,(LONG_PTR)MailParam); + SendMessageW(hDlg,WM_SETICON,(WPARAM)ICON_BIG,(LPARAM)g_LoadIconEx(2, true)); + SendMessageW(hDlg,WM_SETICON,(WPARAM)ICON_SMALL,(LPARAM)g_LoadIconEx(2)); + + ListView_SetUnicodeFormat(hListView,TRUE); + ListView_SetExtendedListViewStyle(hListView,LVS_EX_FULLROWSELECT); + + StrLen=MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,Translate("Header"),-1,NULL,0); + iHeaderW=new WCHAR[StrLen+1]; + MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,Translate("Header"),-1,iHeaderW,StrLen); + + StrLen=MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,Translate("Value"),-1,NULL,0); + iValueW=new WCHAR[StrLen+1]; + MultiByteToWideChar(CP_ACP,MB_USEGLYPHCHARS,Translate("Value"),-1,iValueW,StrLen); + + LVCOLUMNW lvc0={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,130,iHeaderW,0,0}; + LVCOLUMNW lvc1={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,400,iValueW,0,0}; + SendMessageW(hListView,LVM_INSERTCOLUMNW,(WPARAM)0,(LPARAM)&lvc0); + SendMessageW(hListView,LVM_INSERTCOLUMNW,(WPARAM)1,(LPARAM)&lvc1); + if (NULL!=iHeaderW) + delete[] iHeaderW; + if (NULL!=iValueW) + delete[] iValueW; + + //WindowList_Add(YAMNVar.MessageWnds,hDlg,NULL); + //WindowList_Add(YAMNVar.NewMailAccountWnd,hDlg,ActualAccount); + SendMessage(hDlg,WM_YAMN_CHANGECONTENT,0,(LPARAM)MailParam); + MoveWindow(hDlg,HeadPosX,HeadPosY,HeadSizeX,HeadSizeY,0); + ShowWindow(hDlg,SW_SHOWNORMAL); + break; + } + case WM_YAMN_CHANGECONTENT: + { + PYAMN_MAILSHOWPARAM MailParam = (PYAMN_MAILSHOWPARAM) + (lParam?lParam:GetWindowLongPtr(hDlg,DWLP_USER)); + HWND hListView = GetDlgItem(hDlg,IDC_LISTHEADERS); + HWND hEdit = GetDlgItem(hDlg,IDC_EDITBODY); + //do not redraw + SendMessage(hListView, WM_SETREDRAW, 0, 0); + ListView_DeleteAllItems(hListView); + struct CMimeItem *Header; + LVITEMW item; + item.mask=LVIF_TEXT | LVIF_PARAM; + WCHAR *From=0,*Subj=0; + char *contentType=0, *transEncoding=0, *body=0; //should not be delete[]-ed + for (Header=MailParam->mail->MailData->TranslatedHeader;Header!=NULL;Header=Header->Next) + { + WCHAR *str1 = 0; + WCHAR *str2 = 0; + if (!body) if (!_stricmp(Header->name,"Body")) {body = Header->value; continue;} + if (!contentType) if (!_stricmp(Header->name,"Content-Type")) contentType = Header->value; + if (!transEncoding) if (!_stricmp(Header->name,"Content-Transfer-Encoding")) transEncoding = Header->value; + //ConvertCodedStringToUnicode(Header->name,&str1,MailParam->mail->MailData->CP,1); + { + int streamsize = MultiByteToWideChar(20127,0,Header->name,-1,NULL,0); + str1 = new WCHAR[streamsize+1]; + MultiByteToWideChar(20127,0,Header->name,-1,str1,streamsize);//US-ASCII + } + ConvertCodedStringToUnicode(Header->value,&str2,MailParam->mail->MailData->CP,1); + if (!str2) { str2 = (WCHAR *)malloc(2); str2[0] = 0; }// the header value may be NULL + if (!From) if (!_stricmp(Header->name,"From")) { + From =new WCHAR[wcslen(str2)+1]; + wcscpy(From,str2); + } + if (!Subj) if (!_stricmp(Header->name,"Subject")) { + Subj =new WCHAR[wcslen(str2)+1]; + wcscpy(Subj,str2); + } + //if (!hasBody) if (!strcmp(Header->name,"Body")) hasBody = true; + int count = 0; WCHAR **split=0; + if (str2){ + int ofs = 0; + while (str2[ofs]) { + if ((str2[ofs]==0x266A)||(str2[ofs]==0x25D9)||(str2[ofs]==0x25CB)|| + (str2[ofs]==0x09)||(str2[ofs]==0x0A)||(str2[ofs]==0x0D))count++; + ofs++; + } + split=new WCHAR*[count+1]; + count=0; ofs=0; + split[0]=str2; + while (str2[ofs]) { + if ((str2[ofs]==0x266A)||(str2[ofs]==0x25D9)||(str2[ofs]==0x25CB)|| + (str2[ofs]==0x09)||(str2[ofs]==0x0A)||(str2[ofs]==0x0D)) { + if (str2[ofs-1]) { + count++; + } + split[count]=(WCHAR *)(str2+ofs+1); + str2[ofs]=0; + } + ofs++; + }; + } + if (!_stricmp(Header->name,"From")||!_stricmp(Header->name,"To")||!_stricmp(Header->name,"Date")||!_stricmp(Header->name,"Subject")) + item.iItem = 0; + else + item.iItem = 999; + for (int i=0;i<=count;i++) { + item.iSubItem=0; + if (i==0) + item.pszText=str1; + else { + item.iItem++; + item.pszText=0; + } + item.iItem=SendMessageW(hListView,LVM_INSERTITEMW,(WPARAM)0,(LPARAM)&item); + item.iSubItem=1; + item.pszText=str2?split[i]:0; + SendMessageW(hListView,LVM_SETITEMTEXTW,(WPARAM)item.iItem,(LPARAM)&item); + } + if (split)delete[] split; + + if (str1) free(str1); + if (str2) free(str2); + } + if (body){ + WCHAR *bodyDecoded = 0; + char *localBody=0; + if (contentType) { + if (!_strnicmp(contentType,"text",4)) { + if (transEncoding){ + if (!_stricmp(transEncoding,"base64")) { + int size = (int)strlen(body)*3/4+5; + localBody = new char[size+1]; + DecodeBase64(body,localBody,size); + } else if (!_stricmp(transEncoding,"quoted-printable")) { + int size = (int)strlen(body)+2; + localBody = new char[size+1]; + DecodeQuotedPrintable(body,localBody,size,FALSE); + } + } + } else if (!_strnicmp(contentType,"multipart/",10)) { + char *bondary=NULL; + if (NULL!=(bondary=ExtractFromContentType(contentType,"boundary="))) + { + bodyDecoded = ParseMultipartBody(body,bondary); + delete[] bondary; + } + } + } + if (!bodyDecoded)ConvertStringToUnicode(localBody?localBody:body,MailParam->mail->MailData->CP,&bodyDecoded); + SendMessageW(hEdit,WM_SETTEXT,(WPARAM)0,(LPARAM)bodyDecoded); + delete[] bodyDecoded; + if (localBody) delete[] localBody; + SetFocus(hEdit); + } + if (!(MailParam->mail->Flags & YAMN_MSG_BODYRECEIVED)) { + MailParam->mail->Flags |= YAMN_MSG_BODYREQUESTED; + CallService(MS_YAMN_ACCOUNTCHECK,(WPARAM)MailParam->account,0); + } else { + if (MailParam->mail->Flags & YAMN_MSG_UNSEEN){ + MailParam->mail->Flags&=~YAMN_MSG_UNSEEN; //mark the message as seen + HWND hMailBrowser; + if (hMailBrowser=WindowList_Find(YAMNVar.NewMailAccountWnd,MailParam->account)) { + struct CChangeContent Params={MailParam->account->NewMailN.Flags|YAMN_ACC_MSGP,MailParam->account->NoNewMailN.Flags|YAMN_ACC_MSGP}; + SendMessageW(hMailBrowser,WM_YAMN_CHANGECONTENT,(WPARAM)MailParam->account,(LPARAM)&Params); + } else { + UpdateMails(NULL,MailParam->account,MailParam->account->NewMailN.Flags,MailParam->account->NoNewMailN.Flags); + } + } + } + ShowWindow(GetDlgItem(hDlg, IDC_SPLITTER),(MailParam->mail->Flags & YAMN_MSG_BODYRECEIVED)?SW_SHOW:SW_HIDE); + ShowWindow(hEdit,(MailParam->mail->Flags & YAMN_MSG_BODYRECEIVED)?SW_SHOW:SW_HIDE); + WCHAR *title=0; + title = new WCHAR[(From?wcslen(From):0)+(Subj?wcslen(Subj):0)+4]; + if (From&&Subj) wsprintfW(title,L"%s (%s)",Subj,From); + else if (From)wsprintfW(title,L"%s",From); + else if (Subj)wsprintfW(title,L"%s",Subj); + else wsprintfW(title,L"none"); + if (Subj) delete[] Subj; + if (From) delete[] From; + SendMessageW(hDlg,WM_SETTEXT,(WPARAM)0,(LPARAM)title); + delete[] title; + // turn on redrawing + SendMessage(hListView, WM_SETREDRAW, 1, 0); + SendMessage(hDlg, WM_SIZE, 0, HeadSizeY<<16|HeadSizeX); + } break; + case WM_YAMN_STOPACCOUNT: + { + PYAMN_MAILSHOWPARAM MailParam = (PYAMN_MAILSHOWPARAM) + (lParam?lParam:GetWindowLongPtr(hDlg,DWLP_USER)); + + if (NULL==MailParam) + break; + if ((HACCOUNT)wParam!=MailParam->account) + break; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"ShowMessage:STOPACCOUNT:sending destroy msg\n"); + #endif + DestroyWindow(hDlg); + } + return 1; + case WM_CTLCOLORSTATIC: + //here should be check if this is our edittext control. + //but we have only one static control (for now); + SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); + SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT)); + return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);; + case WM_DESTROY: + { + RECT coord; + if (GetWindowRect(hDlg,&coord)) + { + HeadPosX=coord.left; + HeadSizeX=coord.right-coord.left; + HeadPosY=coord.top; + HeadSizeY=coord.bottom-coord.top; + } + + PostQuitMessage(1); + } + break; + case WM_SYSCOMMAND: + { + switch(wParam) + { + case SC_CLOSE: + DestroyWindow(hDlg); + break; + } + } + break; + case WM_MOVE: + HeadPosX=LOWORD(lParam); //((LPRECT)lParam)->right-((LPRECT)lParam)->left; + HeadPosY=HIWORD(lParam); //((LPRECT)lParam)->bottom-((LPRECT)lParam)->top; + return 0; + case DM_SPLITTERMOVED: + { + if ((HWND) lParam == GetDlgItem(hDlg, IDC_SPLITTER)) { + POINT pt; + pt.x = 0; + pt.y = wParam; + ScreenToClient(hDlg, &pt); + HeadSplitPos = (pt.y*1000)/HeadSizeY;//+rc.bottom-rc.top; + if (HeadSplitPos>=1000) HeadSplitPos = 999; + else if (HeadSplitPos<=0) HeadSplitPos = 1; + else SendMessage(hDlg, WM_SIZE, 0, HeadSizeY<<16|HeadSizeX); + } + return 0; + } + case WM_SIZE: + if (wParam==SIZE_RESTORED) + { + HWND hList = GetDlgItem(hDlg,IDC_LISTHEADERS); + HWND hEdit = GetDlgItem(hDlg,IDC_EDITBODY); + BOOL changeX = LOWORD(lParam)!=HeadSizeX; + BOOL isBodyShown = ((PYAMN_MAILSHOWPARAM)(GetWindowLongPtr(hDlg,DWLP_USER)))->mail->Flags & YAMN_MSG_BODYRECEIVED; + HeadSizeX=LOWORD(lParam); //((LPRECT)lParam)->right-((LPRECT)lParam)->left; + HeadSizeY=HIWORD(lParam); //((LPRECT)lParam)->bottom-((LPRECT)lParam)->top; + int localSplitPos = (HeadSplitPos*HeadSizeY)/1000; + int localSizeX; + RECT coord; + MoveWindow(GetDlgItem(hDlg,IDC_SPLITTER),5,localSplitPos,HeadSizeX-10,2,TRUE); + MoveWindow(hEdit,5,localSplitPos+6,HeadSizeX-10,HeadSizeY-localSplitPos-11,TRUE); //where to put text window while resizing + MoveWindow(hList, 5 ,5 ,HeadSizeX-10 ,(isBodyShown?localSplitPos:HeadSizeY)-10,TRUE); //where to put headers list window while resizing + //if (changeX){ + if (GetClientRect(hList,&coord)) { + localSizeX=coord.right-coord.left; + } else localSizeX=HeadSizeX; + LONG iNameWidth = ListView_GetColumnWidth(hList,0); + ListView_SetColumnWidth(hList,1,(localSizeX<=iNameWidth)?0:(localSizeX-iNameWidth)); + //} + } +// break; + return 0; + case WM_CONTEXTMENU: + { + if ( GetWindowLongPtr(( HWND )wParam, GWLP_ID ) == IDC_LISTHEADERS) { + //MessageBox(0,"LISTHEADERS","Debug",0); + HWND hList = GetDlgItem( hDlg, IDC_LISTHEADERS ); + POINT pt = { (signed short)LOWORD( lParam ), (signed short)HIWORD( lParam ) }; + HTREEITEM hItem = 0; + if (pt.x==-1) pt.x = 0; + if (pt.y==-1) pt.y = 0; + if (int numRows = ListView_GetItemCount(hList)) { + HMENU hMenu = CreatePopupMenu(); + AppendMenu(hMenu, MF_STRING, (UINT_PTR)1, TranslateT("Copy Selected")); + AppendMenu(hMenu, MF_STRING, (UINT_PTR)2, TranslateT("Copy All")); + AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); + AppendMenu(hMenu, MF_STRING, (UINT_PTR)0, TranslateT("Cancel")); + int nReturnCmd = TrackPopupMenu( hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hDlg, NULL ); + DestroyMenu( hMenu ); + if (nReturnCmd>0){ + int courRow=0; + size_t sizeNeeded = 0; + TCHAR headname[64]={0}, headvalue[256]={0}; + for (courRow=0; courRow < numRows; courRow++) { + if ((nReturnCmd==1) && (ListView_GetItemState(hList, courRow, LVIS_SELECTED)==0)) continue; + ListView_GetItemText(hList, courRow, 0, headname, SIZEOF(headname)); + ListView_GetItemText(hList, courRow, 1, headvalue, SIZEOF(headvalue)); + size_t headnamelen = _tcslen(headname); + if (headnamelen) sizeNeeded += 1 + headnamelen; + sizeNeeded += 3 + _tcslen(headvalue); + } + if (sizeNeeded && OpenClipboard(hDlg)) { + EmptyClipboard(); + HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE,(sizeNeeded+1)*sizeof(TCHAR)); + TCHAR *buff = ( TCHAR* )GlobalLock(hData); + int courPos = 0; + for (courRow=0;courRowUsingThreads,MyParam.account); + #endif + SCIncFcn(MyParam.account->UsingThreads); + SetEvent(MyParam.ThreadRunningEV); + if (MyParam.mail->MsgWindow){ + //if (!BringWindowToTop(MyParam.mail->MsgWindow)) { + if (!SetForegroundWindow(MyParam.mail->MsgWindow)) { + SendMessage(MyParam.mail->MsgWindow,WM_DESTROY,0,0); + MyParam.mail->MsgWindow = 0; + goto CREADTEVIEWMESSAGEWINDOW; + }else{ + if (IsIconic(MyParam.mail->MsgWindow)) { + OpenIcon(MyParam.mail->MsgWindow); + } + } + } else { +CREADTEVIEWMESSAGEWINDOW: + MyParam.mail->MsgWindow = CreateDialogParamW(YAMNVar.hInst,MAKEINTRESOURCEW(IDD_DLGSHOWMESSAGE),NULL,DlgProcYAMNShowMessage,(LPARAM)&MyParam); + WindowList_Add(YAMNVar.MessageWnds,MyParam.mail->MsgWindow,NULL); + MSG msg; + while(GetMessage(&msg,NULL,0,0)) { + if (!IsDialogMessage(MyParam.mail->MsgWindow, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } } + WindowList_Remove(YAMNVar.MessageWnds,MyParam.mail->MsgWindow); + MyParam.mail->MsgWindow = NULL; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"ShowMessage:Decrementing \"using threads\" %x (account %x)\n",MyParam.account->UsingThreads,MyParam.account); + #endif + SCDecFcn(MyParam.account->UsingThreads); + delete Param; + return 1; +} + +INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch(msg) + { + case WM_INITDIALOG: + { + HACCOUNT ActualAccount; + struct MailBrowserWinParam *MyParam=(struct MailBrowserWinParam *)lParam; + struct CMailWinUserInfo *mwui; + + ListView_SetUnicodeFormat(GetDlgItem(hDlg,IDC_LISTMAILS),TRUE); + ListView_SetExtendedListViewStyle(GetDlgItem(hDlg,IDC_LISTMAILS),LVS_EX_FULLROWSELECT); + + ActualAccount=MyParam->account; + mwui=new struct CMailWinUserInfo; + mwui->Account=ActualAccount; + mwui->TrayIconState=0; + mwui->UpdateMailsMessagesAccess=FALSE; + mwui->Seen=FALSE; + mwui->RunFirstTime=TRUE; + + SetWindowLongPtr(hDlg,DWLP_USER,(LONG_PTR)mwui); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:INIT:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:INIT:ActualAccountSO-read enter failed\n"); + #endif + DestroyWindow(hDlg); + return FALSE; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:INIT:ActualAccountSO-read enter\n"); + #endif + + SendMessageW(GetDlgItem(hDlg,IDC_BTNAPP),WM_SETTEXT,(WPARAM)0,(LPARAM)TranslateW(L"Run application")); + SendMessageW(GetDlgItem(hDlg,IDC_BTNDEL),WM_SETTEXT,(WPARAM)0,(LPARAM)TranslateW(L"Delete selected")); + SendMessageW(GetDlgItem(hDlg,IDC_BTNCHECKALL),WM_SETTEXT,(WPARAM)0,(LPARAM)TranslateW(L"Select All")); + SendMessageW(GetDlgItem(hDlg,IDC_BTNOK),WM_SETTEXT,(WPARAM)0,(LPARAM)TranslateW(L"OK")); + + LVCOLUMNW lvc0={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,FromWidth,TranslateW(L"From"),0,0}; + LVCOLUMNW lvc1={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,SubjectWidth,TranslateW(L"Subject"),0,0}; + LVCOLUMNW lvc2={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,SizeWidth,TranslateW(L"Size"),0,0}; + LVCOLUMNW lvc3={LVCF_FMT | LVCF_TEXT | LVCF_WIDTH,LVCFMT_LEFT,SizeDate,TranslateW(L"Date"),0,0}; + SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_INSERTCOLUMNW,(WPARAM)0,(LPARAM)&lvc0); + SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_INSERTCOLUMNW,(WPARAM)1,(LPARAM)&lvc1); + SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_INSERTCOLUMNW,(WPARAM)2,(LPARAM)&lvc2); + SendMessageW(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_INSERTCOLUMNW,(WPARAM)3,(LPARAM)&lvc3); + + if ((ActualAccount->NewMailN.App!=NULL) && (wcslen(ActualAccount->NewMailN.App))) + EnableWindow(GetDlgItem(hDlg,IDC_BTNAPP),(WPARAM)TRUE); + else + EnableWindow(GetDlgItem(hDlg,IDC_BTNAPP),(WPARAM)FALSE); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:INIT:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + + WindowList_Add(YAMNVar.MessageWnds,hDlg,NULL); + WindowList_Add(YAMNVar.NewMailAccountWnd,hDlg,ActualAccount); + + { + TCHAR accstatus[512]; + GetStatusFcn(ActualAccount,accstatus); + SetDlgItemText(hDlg,IDC_STSTATUS,accstatus); + } + SetTimer(hDlg,TIMER_FLASHING,500,NULL); + + if (ActualAccount->hContact != NULL) + { + CallService(MS_CLIST_REMOVEEVENT,(WPARAM)ActualAccount->hContact,(LPARAM)"yamn new mail message"); + } + + OldListViewSubclassProc = (WNDPROC) SetWindowLongPtr(GetDlgItem(hDlg, IDC_LISTMAILS), GWLP_WNDPROC, (LONG_PTR) ListViewSubclassProc); + + break; + } + case WM_DESTROY: + { + HACCOUNT ActualAccount; + RECT coord; + LVCOLUMNW ColInfo; + NOTIFYICONDATA nid; + HYAMNMAIL Parser; + struct CMailWinUserInfo *mwui; + + mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER); + if (NULL==(ActualAccount=GetWindowAccount(hDlg))) + break; + ColInfo.mask=LVCF_WIDTH; + if (ListView_GetColumn(GetDlgItem(hDlg,IDC_LISTMAILS),0,&ColInfo)) + FromWidth=ColInfo.cx; + if (ListView_GetColumn(GetDlgItem(hDlg,IDC_LISTMAILS),1,&ColInfo)) + SubjectWidth=ColInfo.cx; + if (ListView_GetColumn(GetDlgItem(hDlg,IDC_LISTMAILS),2,&ColInfo)) + SizeWidth=ColInfo.cx; + if (ListView_GetColumn(GetDlgItem(hDlg,IDC_LISTMAILS),3,&ColInfo)) + SizeDate=ColInfo.cx; + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DESTROY:save window position\n"); + #endif + if (!YAMNVar.Shutdown && GetWindowRect(hDlg,&coord)) //the YAMNVar.Shutdown testing is because MMessagesAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DESTROY:ActualAccountMsgsSO-write wait failed\n"); + #endif + break; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DESTROY:ActualAccountMsgsSO-write enter\n"); + #endif + //delete mails from queue, which are deleted from server (spam level 3 mails e.g.) + for (Parser=(HYAMNMAIL)ActualAccount->Mails;Parser!=NULL;Parser=Parser->Next) + { + if ((Parser->Flags & YAMN_MSG_DELETED) && YAMN_MSG_SPAML(Parser->Flags,YAMN_MSG_SPAML3) && mwui->Seen) //if spaml3 was already deleted and user knows about it + { + DeleteMessageFromQueueFcn((HYAMNMAIL *)&ActualAccount->Mails,Parser,1); + CallService(MS_YAMN_DELETEACCOUNTMAIL,(WPARAM)ActualAccount->Plugin,(LPARAM)Parser); + } + } + + //mark mails as read (remove "new" and "unseen" flags) + if (mwui->Seen) + SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails,YAMN_MSG_DISPLAY,0,YAMN_MSG_NEW | YAMN_MSG_UNSEEN,0); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DESTROY:ActualAccountMsgsSO-write done\n"); + #endif + WriteDoneFcn(ActualAccount->MessagesAccessSO); + + ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); + + delete mwui; + SetWindowLongPtr(hDlg,DWLP_USER,(LONG_PTR)NULL); + + nid.cbSize=sizeof(NOTIFYICONDATA); + nid.hWnd=hDlg; + nid.uID=0; + Shell_NotifyIcon(NIM_DELETE,&nid); + PostQuitMessage(0); + } + break; + case WM_SHOWWINDOW: + { + struct CMailWinUserInfo *mwui; + + if (NULL==(mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER))) + return 0; + mwui->Seen=TRUE; + } + case WM_YAMN_CHANGESTATUS: + { + HACCOUNT ActualAccount; + if (NULL==(ActualAccount=GetWindowAccount(hDlg))) + break; + + if ((HACCOUNT)wParam!=ActualAccount) + break; + + TCHAR accstatus[512]; + GetStatusFcn(ActualAccount,accstatus); + SetDlgItemText(hDlg,IDC_STSTATUS,accstatus); + } + return 1; + case WM_YAMN_CHANGECONTENT: + { + struct CUpdateMails UpdateParams; + BOOL ThisThreadWindow=(GetCurrentThreadId()==GetWindowThreadProcessId(hDlg,NULL)); + + if (NULL==(UpdateParams.Copied=CreateEvent(NULL,FALSE,FALSE,NULL))) + { + DestroyWindow(hDlg); + return 0; + } + UpdateParams.Flags=(struct CChangeContent *)lParam; + UpdateParams.Waiting=!ThisThreadWindow; + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:CHANGECONTENT:posting UPDATEMAILS\n"); + #endif + if (ThisThreadWindow) + { + if (!UpdateMails(hDlg,(HACCOUNT)wParam,UpdateParams.Flags->nflags,UpdateParams.Flags->nnflags)) + DestroyWindow(hDlg); + } + else if (PostMessage(hDlg,WM_YAMN_UPDATEMAILS,wParam,(LPARAM)&UpdateParams)) //this ensures UpdateMails will execute the thread who created the browser window + { + if (!ThisThreadWindow) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:CHANGECONTENT:waiting for event\n"); + #endif + WaitForSingleObject(UpdateParams.Copied,INFINITE); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:CHANGECONTENT:event signaled\n"); + #endif + } + } + + CloseHandle(UpdateParams.Copied); + } + return 1; + case WM_YAMN_UPDATEMAILS: + { + HACCOUNT ActualAccount; + + struct CUpdateMails *um=(struct CUpdateMails *)lParam; + DWORD nflags,nnflags; + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:UPDATEMAILS\n"); + #endif + + if (NULL==(ActualAccount=GetWindowAccount(hDlg))) + return 0; + if ((HACCOUNT)wParam!=ActualAccount) + return 0; + + nflags=um->Flags->nflags; + nnflags=um->Flags->nnflags; + + if (um->Waiting) + SetEvent(um->Copied); + + if (!UpdateMails(hDlg,ActualAccount,nflags,nnflags)) + DestroyWindow(hDlg); + } + return 1; + case WM_YAMN_STOPACCOUNT: + { + HACCOUNT ActualAccount; + + if (NULL==(ActualAccount=GetWindowAccount(hDlg))) + break; + if ((HACCOUNT)wParam!=ActualAccount) + break; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:STOPACCOUNT:sending destroy msg\n"); + #endif + PostQuitMessage(0); + } + return 1; + case WM_YAMN_NOTIFYICON: + { + HACCOUNT ActualAccount; + if (NULL==(ActualAccount=GetWindowAccount(hDlg))) + break; + + switch(lParam) + { + case WM_LBUTTONDBLCLK: + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DBLCLICKICON:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DBLCLICKICON:ActualAccountSO-read wait failed\n"); + #endif + return 0; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DBLCLICKICON:ActualAccountSO-read enter\n"); + #endif + if (ActualAccount->AbilityFlags & YAMN_ACC_BROWSE) + { + ShowWindow(hDlg,SW_SHOWNORMAL); + SetForegroundWindow(hDlg); + } + else + DestroyWindow(hDlg); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DBLCLICKICON:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + break; + } + break; + } + case WM_YAMN_SHOWSELECTED: + { + int iSelect; + iSelect=SendMessage(GetDlgItem(hDlg,IDC_LISTMAILS),LVM_GETNEXTITEM,-1,MAKELPARAM((UINT)LVNI_FOCUSED,0)); // return item selected + + if (iSelect!=-1) + { + LV_ITEMW item; + HYAMNMAIL ActualMail; + + item.iItem=iSelect; + item.iSubItem=0; + item.mask=LVIF_PARAM | LVIF_STATE; + item.stateMask=0xFFFFFFFF; + ListView_GetItem(GetDlgItem(hDlg,IDC_LISTMAILS),&item); + ActualMail=(HYAMNMAIL)item.lParam; + if (NULL!=ActualMail) + { + //ShowEmailThread + PYAMN_MAILSHOWPARAM MailParam = new YAMN_MAILSHOWPARAM; + MailParam->account = GetWindowAccount(hDlg); + MailParam->mail = ActualMail; + if (NULL!=(MailParam->ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) { + HANDLE NewThread; + if (NULL!=(NewThread=CreateThread(NULL,0,ShowEmailThread,MailParam,0,NULL))) + { + //WaitForSingleObject(MailParam->ThreadRunningEV,INFINITE); + CloseHandle(NewThread); + } + CloseHandle(MailParam->ThreadRunningEV); + } + //delete MailParam; + } + } + } break; + case WM_SYSCOMMAND: + { + HACCOUNT ActualAccount; + + if (NULL==(ActualAccount=GetWindowAccount(hDlg))) + break; + switch(wParam) + { + case SC_CLOSE: + DestroyWindow(hDlg); + break; + } + } + break; + + case WM_COMMAND: + { + HACCOUNT ActualAccount; + int Items; + + if (NULL==(ActualAccount=GetWindowAccount(hDlg))) + break; + + switch(LOWORD(wParam)) + { + case IDC_BTNCHECKALL: + ListView_SetItemState(GetDlgItem(hDlg,IDC_LISTMAILS), -1, 0, LVIS_SELECTED); // deselect all items + ListView_SetItemState(GetDlgItem(hDlg,IDC_LISTMAILS),-1, LVIS_SELECTED ,LVIS_SELECTED); + Items = ListView_GetItemCount(GetDlgItem(hDlg,IDC_LISTMAILS)); + ListView_RedrawItems(GetDlgItem(hDlg,IDC_LISTMAILS), 0, Items); + UpdateWindow(GetDlgItem(hDlg,IDC_LISTMAILS)); + SetFocus(GetDlgItem(hDlg,IDC_LISTMAILS)); + break; + + case IDC_BTNOK: + DestroyWindow(hDlg); + break; + + case IDC_BTNAPP: + { + PROCESS_INFORMATION pi; + STARTUPINFOW si; + + ZeroMemory(&si,sizeof(si)); + si.cb=sizeof(si); + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0==WaitToReadFcn(ActualAccount->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read enter\n"); + #endif + if (ActualAccount->NewMailN.App!=NULL) + { + WCHAR *Command; + if (ActualAccount->NewMailN.AppParam!=NULL) + Command=new WCHAR[wcslen(ActualAccount->NewMailN.App)+wcslen(ActualAccount->NewMailN.AppParam)+6]; + else + Command=new WCHAR[wcslen(ActualAccount->NewMailN.App)+6]; + + if (Command!=NULL) + { + lstrcpyW(Command,L"\""); + lstrcatW(Command,ActualAccount->NewMailN.App); + lstrcatW(Command,L"\" "); + if (ActualAccount->NewMailN.AppParam!=NULL) + lstrcatW(Command,ActualAccount->NewMailN.AppParam); + CreateProcessW(NULL,Command,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); + delete[] Command; + } + } + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + } + #ifdef DEBUG_SYNCHRO + else + DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read enter failed\n"); + #endif + if (!(GetKeyState(VK_SHIFT) & 0x8000) && !(GetKeyState(VK_CONTROL) & 0x8000)) + DestroyWindow(hDlg); + + } + break; + case IDC_BTNDEL: + { + LVITEMW item; + HYAMNMAIL FirstMail=NULL,ActualMail; + HANDLE ThreadRunningEV; + DWORD tid,Total=0; + + // we use event to signal, that running thread has all needed stack parameters copied + if (NULL==(ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) + break; + int Items=ListView_GetItemCount(GetDlgItem(hDlg,IDC_LISTMAILS)); + + item.stateMask=0xFFFFFFFF; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write wait\n"); + #endif + if (WAIT_OBJECT_0==WaitToWriteFcn(ActualAccount->MessagesAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write enter\n"); + #endif + for (int i=0;iFlags|=YAMN_MSG_USERDELETE; //set to mail we are going to delete it + Total++; + } + } + + // Enable write-access to mails + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write done\n"); + #endif + WriteDoneFcn(ActualAccount->MessagesAccessSO); + + if (Total) + { + TCHAR DeleteMsg[1024]; + + wsprintf(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,NULL}; + + // Find if there's mail marked to delete, which was deleted before + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write wait\n"); + #endif + if (WAIT_OBJECT_0==WaitToWriteFcn(ActualAccount->MessagesAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write enter\n"); + #endif + for (ActualMail=(HYAMNMAIL)ActualAccount->Mails;ActualMail!=NULL;ActualMail=ActualMail->Next) + { + if ((ActualMail->Flags & YAMN_MSG_DELETED) && ((ActualMail->Flags & YAMN_MSG_USERDELETE))) //if selected mail was already deleted + { + DeleteMessageFromQueueFcn((HYAMNMAIL *)&ActualAccount->Mails,ActualMail,1); + CallService(MS_YAMN_DELETEACCOUNTMAIL,(WPARAM)ActualAccount->Plugin,(LPARAM)ActualMail); //delete it from memory + 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; + + if (NULL!=(NewThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ActualAccount->Plugin->Fcn->DeleteMailsFcnPtr,(LPVOID)&ParamToDeleteMails,0,&tid))) + { + WaitForSingleObject(ThreadRunningEV,INFINITE); + CloseHandle(NewThread); + } + // Enable write-access to mails + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNDEL:ActualAccountMsgsSO-write done\n"); + #endif + WriteDoneFcn(ActualAccount->MessagesAccessSO); + } + } + else + //else mark messages that they are not to be deleted + SetRemoveFlagsInQueueFcn((HYAMNMAIL)ActualAccount->Mails,YAMN_MSG_DISPLAY | YAMN_MSG_USERDELETE,0,YAMN_MSG_USERDELETE,0); + } + } + CloseHandle(ThreadRunningEV); + if (DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_CLOSEDELETE, 0)) + DestroyWindow(hDlg); + + } + break; + } + } + break; + case WM_SIZE: + if (wParam==SIZE_RESTORED) + { + LONG x=LOWORD(lParam); //((LPRECT)lParam)->right-((LPRECT)lParam)->left; + LONG y=HIWORD(lParam); //((LPRECT)lParam)->bottom-((LPRECT)lParam)->top; + MoveWindow(GetDlgItem(hDlg,IDC_BTNDEL), 5 ,y-5-25,(x-20)/3,25,TRUE); //where to put DELETE button while resizing + MoveWindow(GetDlgItem(hDlg,IDC_BTNCHECKALL),10+ (x-20)/3,y-5-25,(x-20)/6,25,TRUE); //where to put CHECK ALL button while resizing + MoveWindow(GetDlgItem(hDlg,IDC_BTNAPP), 15+ (x-20)/3 + (x-20)/6,y-5-25,(x-20)/3,25,TRUE); //where to put RUN APP button while resizing + MoveWindow(GetDlgItem(hDlg,IDC_BTNOK), 20+2*(x-20)/3 + (x-20)/6 ,y-5-25,(x-20)/6,25,TRUE); //where to put OK button while resizing + MoveWindow(GetDlgItem(hDlg,IDC_LISTMAILS), 5 ,5 ,x-10 ,y-55,TRUE); //where to put list mail window while resizing + MoveWindow(GetDlgItem(hDlg,IDC_STSTATUS), 5 ,y-5-45 ,x-10 ,15,TRUE); //where to put account status text while resizing + } +// break; + return 0; + case WM_GETMINMAXINFO: + ((LPMINMAXINFO)lParam)->ptMinTrackSize.x=MAILBROWSER_MINXSIZE; + ((LPMINMAXINFO)lParam)->ptMinTrackSize.y=MAILBROWSER_MINYSIZE; + return 0; + case WM_TIMER: + { + NOTIFYICONDATA nid; + struct CMailWinUserInfo *mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER); + + ZeroMemory(&nid,sizeof(nid)); + nid.cbSize=sizeof(NOTIFYICONDATA); + nid.hWnd=hDlg; + nid.uID=0; + nid.uFlags=NIF_ICON; + if (mwui->TrayIconState==0) + nid.hIcon=g_LoadIconEx(0); + else + nid.hIcon=g_LoadIconEx(2); + Shell_NotifyIcon(NIM_MODIFY,&nid); + mwui->TrayIconState=!mwui->TrayIconState; +// UpdateWindow(hDlg); + } + break; + case WM_NOTIFY: + switch(((LPNMHDR)lParam)->idFrom) + { + + case IDC_LISTMAILS: + { + + switch(((LPNMHDR)lParam)->code) + { + case NM_DBLCLK: + SendMessage(hDlg,WM_YAMN_SHOWSELECTED,0,0); + break; + case LVN_COLUMNCLICK: + HACCOUNT ActualAccount; + if (NULL!=(ActualAccount=GetWindowAccount(hDlg))) { + NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lParam; + if (WAIT_OBJECT_0==WaitToReadFcn(ActualAccount->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:COLUMNCLICK:ActualAccountSO-read enter\n"); + #endif + switch((int)pNMListView->iSubItem) + { + case 0: + bFrom = !bFrom; + break; + case 1: + bSub = !bSub; + break; + case 2: + bSize = !bSize; + break; + case 3: + bDate = !bDate; + break; + default: + break; + } + ListView_SortItems(pNMListView->hdr.hwndFrom,ListViewCompareProc,pNMListView->iSubItem); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:BTNAPP:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + } } + break; + + case NM_CUSTOMDRAW: + { + HACCOUNT ActualAccount; + LPNMLVCUSTOMDRAW cd=(LPNMLVCUSTOMDRAW)lParam; + LONG_PTR PaintCode; + + if (NULL==(ActualAccount=GetWindowAccount(hDlg))) + break; + + switch(cd->nmcd.dwDrawStage) + { + case CDDS_PREPAINT: + PaintCode=CDRF_NOTIFYITEMDRAW; + break; + case CDDS_ITEMPREPAINT: + PaintCode=CDRF_NOTIFYSUBITEMDRAW; + break; + case CDDS_ITEMPREPAINT | CDDS_SUBITEM: + { +// COLORREF crText, crBkgnd; +// crText= RGB(128,128,255); + HYAMNMAIL ActualMail; + BOOL umma; + + { + struct CMailWinUserInfo *mwui; + mwui=(struct CMailWinUserInfo *)GetWindowLongPtr(hDlg,DWLP_USER); + umma= mwui->UpdateMailsMessagesAccess; + } + ActualMail=(HYAMNMAIL)cd->nmcd.lItemlParam; + if (!ActualMail) + ActualMail=(HYAMNMAIL)readItemLParam(cd->nmcd.hdr.hwndFrom,cd->nmcd.dwItemSpec); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DRAWITEM:ActualAccountMsgsSO-read wait\n"); + #endif + if (!umma) + if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->MessagesAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DRAWITEM:ActualAccountMsgsSO-read wait failed\n"); + #endif + return 0; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DRAWITEM:ActualAccountMsgsSO-read enter\n"); + #endif + switch(ActualMail->Flags & YAMN_MSG_SPAMMASK) + { + case YAMN_MSG_SPAML1: + case YAMN_MSG_SPAML2: + cd->clrText=RGB(150,150,150); + break; + case YAMN_MSG_SPAML3: + cd->clrText=RGB(200,200,200); + cd->clrTextBk=RGB(160,160,160); + break; + case 0: + if (cd->nmcd.dwItemSpec & 1) + cd->clrTextBk=RGB(230,230,230); + break; + default: + break; + } + if (ActualMail->Flags & YAMN_MSG_UNSEEN) + cd->clrTextBk=RGB(220,235,250); + PaintCode=CDRF_DODEFAULT; + + if (!umma) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:DRAWITEM:ActualAccountMsgsSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->MessagesAccessSO); + } + + break; + } + } + SetWindowLongPtr(hDlg,DWLP_MSGRESULT,PaintCode); + return 1; + } + } + } + } + break; + case WM_CONTEXTMENU: + { + if ( GetWindowLongPtr(( HWND )wParam, GWLP_ID ) == IDC_LISTMAILS) { + //MessageBox(0,"LISTHEADERS","Debug",0); + HWND hList = GetDlgItem( hDlg, IDC_LISTMAILS ); + POINT pt = { (signed short)LOWORD( lParam ), (signed short)HIWORD( lParam ) }; + HTREEITEM hItem = 0; + if (pt.x==-1) pt.x = 0; + if (pt.y==-1) pt.y = 0; + if (int numRows = ListView_GetItemCount(hList)) { + HMENU hMenu = CreatePopupMenu(); + AppendMenu(hMenu, MF_STRING, (UINT_PTR)1, TranslateT("Copy Selected")); + AppendMenu(hMenu, MF_STRING, (UINT_PTR)2, TranslateT("Copy All")); + AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); + AppendMenu(hMenu, MF_STRING, (UINT_PTR)0, TranslateT("Cancel")); + int nReturnCmd = TrackPopupMenu( hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hDlg, NULL ); + DestroyMenu( hMenu ); + if (nReturnCmd>0){ + int courRow=0; + size_t sizeNeeded = 0; + TCHAR from[128]={0}, subject[256]={0}, size[16]={0}, date[64]={0}; + for (courRow=0;courRowmessage == WM_KEYDOWN + && lpmsg->wParam == VK_RETURN) + return DLGC_WANTALLKEYS; + } + break; + } + case WM_KEYDOWN: + { + + BOOL isCtrl = GetKeyState(VK_CONTROL) & 0x8000; + BOOL isShift = GetKeyState(VK_SHIFT) & 0x8000; + BOOL isAlt = GetKeyState(VK_MENU) & 0x8000; + + switch (wParam) + { + case 'A': // ctrl-a + if (!isAlt && !isShift && isCtrl) SendMessage(hwndParent,WM_COMMAND,IDC_BTNCHECKALL,0); + break; + case VK_RETURN: + case VK_SPACE: + if (!isAlt && !isShift && !isCtrl) SendMessage(hwndParent,WM_YAMN_SHOWSELECTED,0,0); + break; + case VK_DELETE: + SendMessage(hwndParent,WM_COMMAND,IDC_BTNDEL,0); + break; + } + + break; + + } + } + return CallWindowProc(OldListViewSubclassProc, hDlg, msg, wParam, lParam); +} + +DWORD WINAPI MailBrowser(LPVOID Param) +{ + MSG msg; + + HWND hMailBrowser; + BOOL WndFound=FALSE; + HACCOUNT ActualAccount; + struct MailBrowserWinParam MyParam; + + MyParam=*(struct MailBrowserWinParam *)Param; + ActualAccount=MyParam.account; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:Incrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); + #endif + SCIncFcn(ActualAccount->UsingThreads); + +// we will not use params in stack anymore + SetEvent(MyParam.ThreadRunningEV); + + __try + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:ActualAccountSO-read wait failed\n"); + #endif + return 0; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:ActualAccountSO-read enter\n"); + #endif + if (!(ActualAccount->AbilityFlags & YAMN_ACC_BROWSE)) + { + MyParam.nflags=MyParam.nflags & ~YAMN_ACC_MSG; + MyParam.nnflags=MyParam.nnflags & ~YAMN_ACC_MSG; + } + if (!(ActualAccount->AbilityFlags & YAMN_ACC_POPUP)) + MyParam.nflags=MyParam.nflags & ~YAMN_ACC_POP; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + + if (NULL!=(hMailBrowser=WindowList_Find(YAMNVar.NewMailAccountWnd,ActualAccount))) + WndFound=TRUE; + if ((hMailBrowser==NULL) && ((MyParam.nflags & YAMN_ACC_MSG) || (MyParam.nflags & YAMN_ACC_ICO) || (MyParam.nnflags & YAMN_ACC_MSG))) + { + hMailBrowser=CreateDialogParamW(YAMNVar.hInst,MAKEINTRESOURCEW(IDD_DLGVIEWMESSAGES),NULL,DlgProcYAMNMailBrowser,(LPARAM)&MyParam); + SendMessageW(hMailBrowser,WM_SETICON,(WPARAM)ICON_BIG,(LPARAM)g_LoadIconEx(2,true)); + SendMessageW(hMailBrowser,WM_SETICON,(WPARAM)ICON_SMALL,(LPARAM)g_LoadIconEx(2)); + MoveWindow(hMailBrowser,PosX,PosY,SizeX,SizeY,TRUE); + } + + if (hMailBrowser!=NULL) + { + struct CChangeContent Params={MyParam.nflags,MyParam.nnflags}; //if this thread created window, just post message to update mails + + SendMessageW(hMailBrowser,WM_YAMN_CHANGECONTENT,(WPARAM)ActualAccount,(LPARAM)&Params); //we ensure this will do the thread who created the browser window + } + else + UpdateMails(NULL,ActualAccount,MyParam.nflags,MyParam.nnflags); //update mails without displaying or refreshing any window + + if ((hMailBrowser!=NULL) && !WndFound) //we process message loop only for thread that created window + { + while(GetMessage(&msg,NULL,0,0)) + { + if (!IsDialogMessage(hMailBrowser, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + + if ((!WndFound) && (ActualAccount->Plugin->Fcn!=NULL) && (ActualAccount->Plugin->Fcn->WriteAccountsFcnPtr!=NULL) && ActualAccount->AbleToWork) + ActualAccount->Plugin->Fcn->WriteAccountsFcnPtr(); + } + __finally + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"MailBrowser:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); + #endif + SCDecFcn(ActualAccount->UsingThreads); + } + return 1; +} + +INT_PTR RunMailBrowserSvc(WPARAM wParam,LPARAM lParam) +{ + DWORD tid; + //an event for successfull copy parameters to which point a pointer in stack for new thread + HANDLE ThreadRunningEV; + PYAMN_MAILBROWSERPARAM Param=(PYAMN_MAILBROWSERPARAM)wParam; + + if ((DWORD)lParam!=YAMN_MAILBROWSERVERSION) + return 0; + + if (NULL!=(ThreadRunningEV=CreateEvent(NULL,FALSE,FALSE,NULL))) + { + HANDLE NewThread; + + Param->ThreadRunningEV=ThreadRunningEV; + if (NULL!=(NewThread=CreateThread(NULL,0,MailBrowser,Param,0,&tid))) + { + WaitForSingleObject(ThreadRunningEV,INFINITE); + CloseHandle(NewThread); + } + CloseHandle(ThreadRunningEV); + return 1; + } + return 0; +} diff --git a/protocols/YAMN/src/debug.cpp b/protocols/YAMN/src/debug.cpp new file mode 100644 index 0000000000..9b9793a965 --- /dev/null +++ b/protocols/YAMN/src/debug.cpp @@ -0,0 +1,139 @@ +/* + * YAMN plugin main file + * Miranda homepage: http://miranda-icq.sourceforge.net/ + * + * Debug functions used in DEBUG release (you need to global #define DEBUG to get debug version) + * + * (c) majvan 2002-2004 + */ + +#include "yamn.h" +#include "debug.h" +#ifdef YAMN_DEBUG +#include "version.h" + +#if defined (WIN9X) + #define YAMN_VER "YAMN " YAMN_VERSION_C " (Win9x)" +#elif defined(WIN2IN1) + #define YAMN_VER "YAMN " YAMN_VERSION_C " (2in1)" +#else + #define YAMN_VER "YAMN " YAMN_VERSION_C " (WinNT)" +#endif + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +TCHAR DebugUserDirectory[MAX_PATH] = _T("."); +LPCRITICAL_SECTION FileAccessCS; + +#ifdef DEBUG_SYNCHRO +TCHAR DebugSynchroFileName2[]=_T("%s\\yamn-debug.synchro.log"); +HANDLE SynchroFile; +#endif + +#ifdef DEBUG_COMM +TCHAR DebugCommFileName2[]=_T("%s\\yamn-debug.comm.log"); +HANDLE CommFile; +#endif + +#ifdef DEBUG_DECODE +TCHAR DebugDecodeFileName2[]=_T("%s\\yamn-debug.decode.log"); +HANDLE DecodeFile; +#endif + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +void InitDebug() +{ +#if defined (DEBUG_SYNCHRO) || defined (DEBUG_COMM) || defined (DEBUG_DECODE) + TCHAR DebugFileName[MAX_PATH]; +#endif + if (FileAccessCS==NULL) + { + FileAccessCS=new CRITICAL_SECTION; + InitializeCriticalSection(FileAccessCS); + } + +#ifdef DEBUG_SYNCHRO + _stprintf(DebugFileName,DebugSynchroFileName2,DebugUserDirectory); + + SynchroFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); + DebugLog(SynchroFile,"Synchro debug file created by %s\n",YAMN_VER); +#endif + +#ifdef DEBUG_COMM + _stprintf(DebugFileName,DebugCommFileName2,DebugUserDirectory); + + CommFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); + DebugLog(CommFile,"Communication debug file created by %s\n",YAMN_VER); +#endif + +#ifdef DEBUG_DECODE + _stprintf(DebugFileName,DebugDecodeFileName2,DebugUserDirectory); + + DecodeFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL); + DebugLog(DecodeFile,"Decoding kernel debug file created by %s\n",YAMN_VER); +#endif +} + +void UnInitDebug() +{ +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"File is being closed normally."); + CloseHandle(SynchroFile); +#endif +#ifdef DEBUG_COMM + DebugLog(CommFile,"File is being closed normally."); + CloseHandle(CommFile); +#endif +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"File is being closed normally."); + CloseHandle(DecodeFile); +#endif +} + + +void DebugLog(HANDLE File,const char *fmt,...) +{ + char *str; + char tids[32]; + va_list vararg; + int strsize; + DWORD Written; + + va_start(vararg,fmt); + str=(char *)malloc(strsize=65536); + mir_snprintf(tids, SIZEOF(tids), "[%x]",GetCurrentThreadId()); + while(_vsnprintf(str,strsize,fmt,vararg)==-1) + str=(char *)realloc(str,strsize+=65536); + va_end(vararg); + EnterCriticalSection(FileAccessCS); + WriteFile(File,tids,(DWORD)strlen(tids),&Written,NULL); + WriteFile(File,str,(DWORD)strlen(str),&Written,NULL); + LeaveCriticalSection(FileAccessCS); + free(str); +} + +void DebugLogW(HANDLE File,const WCHAR *fmt,...) +{ + WCHAR *str; + char tids[32]; + va_list vararg; + int strsize; + DWORD Written; + + va_start(vararg,fmt); + str=(WCHAR *)malloc((strsize=65536)*sizeof(WCHAR)); + mir_snprintf(tids, SIZEOF(tids), "[%x]",GetCurrentThreadId()); + while(_vsnwprintf(str,strsize,fmt,vararg)==-1) + str=(WCHAR *)realloc(str,(strsize+=65536)*sizeof(WCHAR)); + va_end(vararg); + EnterCriticalSection(FileAccessCS); + WriteFile(File,tids,(DWORD)strlen(tids),&Written,NULL); + WriteFile(File,str,(DWORD)wcslen(str)*sizeof(WCHAR),&Written,NULL); + LeaveCriticalSection(FileAccessCS); + free(str); +} + +#endif //ifdef DEBUG \ No newline at end of file diff --git a/protocols/YAMN/src/debug.h b/protocols/YAMN/src/debug.h new file mode 100644 index 0000000000..3bde9ddc81 --- /dev/null +++ b/protocols/YAMN/src/debug.h @@ -0,0 +1,67 @@ +#ifndef __DEBUG_H +#define __DEBUG_H + +// #define YAMN_DEBUG + +//#define YAMN_VER_BETA +//#define YAMN_VER_BETA_CRASHONLY + +#ifdef YAMN_DEBUG + +//#pragma comment(lib, "th32.lib") + +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x0501 // WinXP only +#endif +#define VC_EXTRALEAN +#include +#include +#include +#include + +//#define DEBUG_SYNCHRO //debug synchro to a file +//#define DEBUG_COMM //debug communiation to a file +//#define DEBUG_DECODE //debug header decoding to a file +//#define DEBUG_DECODECODEPAGE //add info about codepage used in conversion +//#define DEBUG_DECODEBASE64 //add info about base64 result +//#define DEBUG_DECODEQUOTED //add info about quoted printable result +//#define DEBUG_FILEREAD //debug file reading to message boxes +//#define DEBUG_FILEREADMESSAGES //debug file reading messages to message boxes + +void DebugLog(HANDLE,const char *fmt,...); +void DebugLogW(HANDLE File,const WCHAR *fmt,...); + +#ifdef DEBUG_SYNCHRO +// Used for synchronization debug +extern HANDLE SynchroFile; +#endif + +#ifdef DEBUG_COMM +// Used for communication debug +extern HANDLE CommFile; +#endif + +#ifdef DEBUG_DECODE +// Used for decoding debug +extern HANDLE DecodeFile; +#endif + +#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) +DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo,char *DebugString); + +DWORD ReadStringFromMemoryW(char **Parser,TCHAR *End,char **StoreTo,TCHAR *DebugString); + +#else +DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo); + +DWORD ReadStringFromMemoryW(WCHAR **Parser,WCHAR *End,WCHAR **StoreTo); + +#endif + +//#ifdef DEBUG_ACCOUNTS +//int GetAccounts(); +//void WriteAccounts(); +//#endif + +#endif //YAMN_DEBUG +#endif //_DEBUG_H diff --git a/protocols/YAMN/src/filterplugin.cpp b/protocols/YAMN/src/filterplugin.cpp new file mode 100644 index 0000000000..8f61003293 --- /dev/null +++ b/protocols/YAMN/src/filterplugin.cpp @@ -0,0 +1,204 @@ +/* + * YAMN plugin export functions for filtering + * + * (c) majvan 2002-2004 + */ + +#include "yamn.h" + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +PYAMN_FILTERPLUGINQUEUE FirstFilterPlugin=NULL; + +INT_PTR RegisterFilterPluginSvc(WPARAM,LPARAM); + +//Removes plugin from queue and deletes its structures +INT_PTR UnregisterFilterPlugin(HYAMNFILTERPLUGIN Plugin); + +INT_PTR UnregisterFilterPluginSvc(WPARAM wParam,LPARAM lParam); + +//Removes all filter plugins +INT_PTR UnregisterFilterPlugins(); + +INT_PTR FilterMailSvc(WPARAM,LPARAM); + +//Sets imported functions for an plugin and therefore it starts plugin to be registered and running +// Plugin- plugin, which wants to set its functions +// Importance- importance of plugin (see m_filterplugin.h) +// YAMNFilterFcn- pointer to imported functions +// YAMNfilterFcnVer- version of YAMN_FILTERIMPORTFCN, use YAMN_FILTERIMPORTFCNVERSION +// returns nonzero if success +int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin,DWORD Importance,PYAMN_FILTERIMPORTFCN YAMNFilterFcn,DWORD YAMNFilterFcnVer); + +struct CExportedFunctions FilterPluginExportedFcn[]= +{ + {YAMN_SETFILTERPLUGINFCNIMPORTID,(void *)SetFilterPluginFcnImportFcn}, +}; + +struct CExportedServices FilterPluginExportedSvc[]= +{ + {MS_YAMN_REGISTERFILTERPLUGIN,RegisterFilterPluginSvc}, + {MS_YAMN_UNREGISTERFILTERPLUGIN,UnregisterFilterPluginSvc}, +}; + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +INT_PTR RegisterFilterPluginSvc(WPARAM wParam,LPARAM lParam) +{ + PYAMN_FILTERREGISTRATION Registration=(PYAMN_FILTERREGISTRATION)wParam; + HYAMNFILTERPLUGIN Plugin; + + if (lParam!=YAMN_FILTERREGISTRATIONVERSION) + return 0; + if ((Registration->Name==NULL) || (Registration->Ver==NULL)) + return NULL; + if (NULL==(Plugin=new YAMN_FILTERPLUGIN)) + return NULL; + + Plugin->PluginInfo=Registration; + + Plugin->FilterFcn=NULL; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"::: YAMN- new filter registered: %0x (%s) :::\n",Plugin,Registration->Name); +#endif + return (INT_PTR)Plugin; +} + +INT_PTR UnregisterFilterPlugin(HYAMNFILTERPLUGIN Plugin) +{ + PYAMN_FILTERPLUGINQUEUE Parser,Found; + + if (FirstFilterPlugin->Plugin==Plugin) + { + Found=FirstFilterPlugin; + FirstFilterPlugin=FirstFilterPlugin->Next; + } + else + { + for (Parser=FirstFilterPlugin;(Parser->Next!=NULL) && (Plugin!=Parser->Next->Plugin);Parser=Parser->Next); + if (Parser->Next!=NULL) + { + Found=Parser->Next; + Parser->Next=Parser->Next->Next; + } + else + Found=NULL; + } + if (Found!=NULL) + { + if (Plugin->FilterFcn->UnLoadFcn!=NULL) + Plugin->FilterFcn->UnLoadFcn((void *)0); + + delete Found->Plugin; + delete Found; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"::: YAMN- filter %0x unregistered :::\n",Plugin); +#endif + } + else + return 0; + return 1; +} + +INT_PTR UnregisterFilterPluginSvc(WPARAM wParam,LPARAM lParam) +{ + HYAMNFILTERPLUGIN Plugin=(HYAMNFILTERPLUGIN)wParam; + + EnterCriticalSection(&PluginRegCS); + UnregisterFilterPlugin(Plugin); + LeaveCriticalSection(&PluginRegCS); + return 1; +} + +INT_PTR UnregisterFilterPlugins() +{ + EnterCriticalSection(&PluginRegCS); +//We remove protocols from the protocol list + while(FirstFilterPlugin!=NULL) + UnregisterFilterPlugin(FirstFilterPlugin->Plugin); + LeaveCriticalSection(&PluginRegCS); + return 1; +} + +int WINAPI SetFilterPluginFcnImportFcn(HYAMNFILTERPLUGIN Plugin,DWORD Importance,PYAMN_FILTERIMPORTFCN YAMNFilterFcn,DWORD YAMNFilterFcnVer) +{ + PYAMN_FILTERPLUGINQUEUE Parser,Previous; + + if (YAMNFilterFcnVer!=YAMN_FILTERIMPORTFCNVERSION) + return 0; + if (YAMNFilterFcn==NULL) + return 0; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"::: YAMN- filter %0x import succeed :::\n",Plugin); +#endif + Plugin->Importance=Importance; + Plugin->FilterFcn=YAMNFilterFcn; + + EnterCriticalSection(&PluginRegCS); +//We add protocol to the protocol list + for (Previous=NULL,Parser=FirstFilterPlugin;Parser!=NULL && Parser->Next!=NULL && Parser->Plugin->Importance<=Importance;Previous=Parser,Parser=Parser->Next); + if (Previous==NULL) //insert to the beginnig of queue + { + FirstFilterPlugin=new YAMN_FILTERPLUGINQUEUE; + FirstFilterPlugin->Plugin=Plugin; + FirstFilterPlugin->Next=Parser; + } + else + { + Previous->Next=new YAMN_FILTERPLUGINQUEUE; + Previous=Previous->Next; //leave previous, go to actual plugin + Previous->Plugin=Plugin; + Previous->Next=Parser; //and in actual plugin set, that next plugin is the one we insert in front of + } + + LeaveCriticalSection(&PluginRegCS); + return 1; +} + +INT_PTR FilterMailSvc(WPARAM wParam,LPARAM lParam) +{ + HACCOUNT Account=(HACCOUNT)wParam; + HYAMNMAIL Mail=(HYAMNMAIL)lParam; + PYAMN_FILTERPLUGINQUEUE ActualPlugin; + + EnterCriticalSection(&PluginRegCS); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write wait\n"); +#endif + WaitToWriteFcn(Account->MessagesAccessSO); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write enter\n"); +#endif + for (ActualPlugin=FirstFilterPlugin;ActualPlugin!=NULL;ActualPlugin=ActualPlugin->Next) + { + if (ActualPlugin->Plugin->FilterFcn->FilterMailFcnPtr!=NULL) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tFiltering Mail, running plugin %0x to filter mail\n",ActualPlugin->Plugin); +#endif + ActualPlugin->Plugin->FilterFcn->FilterMailFcnPtr(Account,YAMN_ACCOUNTVERSION,Mail,YAMN_MAILVERSION); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tFiltering Mail done\n"); +#endif + } + } + Mail->Flags|=YAMN_MSG_FILTERED; + +//Set mail flags according to spamlevel settings + if ((Mail->Flags & YAMN_MSG_SPAMMASK) > YAMN_MSG_SPAML1) + Mail->Flags=Mail->Flags & ~(YAMN_MSG_BROWSER | YAMN_MSG_POPUP | YAMN_MSG_SYSTRAY | YAMN_MSG_SOUND | YAMN_MSG_APP | YAMN_MSG_NEVENT); + if (YAMN_MSG_SPAML(Mail->Flags,YAMN_MSG_SPAML3) || YAMN_MSG_SPAML(Mail->Flags,YAMN_MSG_SPAML4)) + Mail->Flags=Mail->Flags | (YAMN_MSG_AUTODELETE | YAMN_MSG_DELETEOK); //set message to delete + if (YAMN_MSG_SPAML(Mail->Flags,YAMN_MSG_SPAML3)) + Mail->Flags=Mail->Flags & ~(YAMN_MSG_MEMDELETE); //set message not to delete it immidiatelly from memory +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"FilterMail:ActualAccountMsgsSO-write done\n"); +#endif + WriteDoneFcn(Account->MessagesAccessSO); + LeaveCriticalSection(&PluginRegCS); + return 1; +} diff --git a/protocols/YAMN/src/mails/decode.cpp b/protocols/YAMN/src/mails/decode.cpp new file mode 100644 index 0000000000..867ed7ff25 --- /dev/null +++ b/protocols/YAMN/src/mails/decode.cpp @@ -0,0 +1,558 @@ +/* + * This code implements decoding encoded MIME header in style + * =?iso-8859-2?Q? "User using email in central Europe characters such as =E9" ?= + * + * (c) majvan 2002-2004 + */ +#include "../yamn.h" +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +struct _tcptable CodePageNamesAll[]= +{ + { "ANSI", "",TRUE,CP_ACP}, + { "WINDOWS-1", "250",0,1250}, + { "WINDOWS-1", "251",0,1251}, + { "WINDOWS-1", "252",0,1252}, + { "WINDOWS-1", "253",0,1253}, + { "WINDOWS-1", "254",0,1254}, + { "WINDOWS-1", "255",0,1255}, + { "WINDOWS-1", "256",0,1256}, + { "WINDOWS-1", "257",0,1257}, + { "WINDOWS-1", "258",0,1258}, + { "CP1", "250",0,1250}, + { "CP1", "251",0,1251}, + { "CP1", "252",0,1252}, + { "CP1", "253",0,1253}, + { "CP1", "254",0,1254}, + { "CP1", "255",0,1255}, + { "CP1", "256",0,1256}, + { "CP1", "257",0,1257}, + { "CP1", "258",0,1258}, + { "ANSI-1", "250",0,1250}, + { "ANSI-1", "251",0,1251}, + { "ANSI-1", "252",0,1252}, + { "ANSI-1", "253",0,1253}, + { "ANSI-1", "254",0,1254}, + { "ANSI-1", "255",0,1255}, + { "ANSI-1", "256",0,1256}, + { "ANSI-1", "257",0,1257}, + { "ANSI-1", "258",0,1258}, + { "KOI8", "-R",0,20866}, + { "KOI8", "",0,20866}, + { "KOI8", "-U",0,21866}, + { "KOI8", "-RU",0,21866}, + { "US-", "ASCII",0,20127}, + { "CP", "367",0,20127}, + { "ASCII", "",0,20127}, + { "ASCII", "7",0,20127}, + { "ISO-8859", "-1",0,28591}, + { "ISO-8859", "-2",0,28592}, + { "ISO-8859", "-3",0,28593}, + { "ISO-8859", "-4",0,28594}, + { "ISO-8859", "-5",0,28595}, + { "ISO-8859", "-6",0,28596}, + { "ISO-8859", "-7",0,28597}, + { "ISO-8859", "-8",0,28598}, + { "ISO-8859", "-9",0,28599}, + { "ISO-8859", "-15",0,28605}, + { "ISO_8859", "-1",0,28591}, + { "ISO_8859", "-2",0,28592}, + { "ISO_8859", "-3",0,28593}, + { "ISO_8859", "-4",0,28594}, + { "ISO_8859", "-5",0,28595}, + { "ISO_8859", "-6",0,28596}, + { "ISO_8859", "-7",0,28597}, + { "ISO_8859", "-8",0,28598}, + { "ISO_8859", "-9",0,28599}, + { "ISO_8859", "-15",0,28605}, + { "ISO-", "10646-USC2",0,1200}, + { "ISO-2022", "/2-JP",0,50220}, + { "ISO-2022", "-JP",0,50221}, + { "ISO-2022", "/JIS-JP",0,50222}, + { "ISO-2022", "-KR",0,50225}, + { "ISO-2022", "-CH(SP)",0,50227}, + { "ISO-2022", "-CH(TR)",0,50229}, + { "UTF-", "7",0,65000}, + { "UTF-", "8",0,65001}, + { "ARAB-", "TRANSPARENT",0,710}, + { "ASMO-", "TRANSPARENT",0,720}, + { "ASMO-", "449",0,709}, + { "ASMO-", "708",0,708}, + { "BIG5", "",0,950}, + { "EUC-", "CH(SP)",0,51936}, + { "EUC-", "CH(TR)",0,51950}, + { "EUC-", "JP",0,51932}, + { "EUC-", "KR",0,51949}, + { "GB-", "2312",0,20936}, + { "GB", "2312",0,20936}, + { "HZGB-", "2312",0,52936}, + { "IBM-", "037",0,37}, + { "IBM-", "290",0,290}, + { "IBM-", "437",0,437}, + { "IBM-", "500",0,500}, + { "IBM-", "775",0,775}, + { "IBM-", "850",0,850}, + { "IBM-", "852",0,852}, + { "IBM-", "855",0,855}, + { "IBM-", "857",0,857}, + { "IBM-", "860",0,860}, + { "IBM-", "861",0,861}, + { "IBM-", "862",0,862}, + { "IBM-", "863",0,863}, + { "IBM-", "864",0,864}, + { "IBM-", "865",0,865}, + { "IBM-", "866",0,866}, + { "IBM-", "869",0,869}, + { "IBM-", "870",0,870}, + { "IBM-", "875",0,875}, + { "IBM-", "1026",0,1026}, + { "IBM-", "273",0,20273}, + { "IBM-", "277",0,20277}, + { "IBM-", "278",0,20278}, + { "IBM-", "280",0,20280}, + { "IBM-", "284",0,20284}, + { "IBM-", "285",0,20285}, + { "IBM-", "290",0,20290}, + { "IBM-", "297",0,20297}, + { "IBM-", "420",0,20420}, + { "IBM-", "423",0,20423}, + { "IBM-", "871",0,20871}, + { "IBM-", "880",0,20880}, + { "IBM-", "905",0,20905}, + { "IBM-", "THAI",0,20838}, + { "ISCII-", "DEVANAGARI",0,57002}, + { "ISCII-", "BENGALI",0,57003}, + { "ISCII-", "TAMIL",0,57004}, + { "ISCII-", "TELUGU",0,57005}, + { "ISCII-", "ASSAMESE",0,57006}, + { "ISCII-", "ORIYA",0,57007}, + { "ISCII-", "KANNADA",0,57008}, + { "ISCII-", "MALAYALAM",0,57009}, + { "ISCII-", "GUJARATI",0,57010}, + { "ISCII-", "PUNJABI",0,57011}, + { "KOR-", "JOHAB",0,1361}, + { "KSC-", "5601",0,1361}, + { "MAC-", "ROMAN",0,10000}, + { "MAC-", "JP",0,10001}, + { "MAC-", "CH(SP)(BIG5)",0,10002}, + { "MAC-", "KR",0,10003}, + { "MAC-", "AR",0,10004}, + { "MAC-", "HW",0,10005}, + { "MAC-", "GR",0,10006}, + { "MAC-", "CY",0,10007}, + { "MAC-", "CH(SP)(GB2312)",0,10008}, + { "MAC-", "ROMANIA",0,10010}, + { "MAC-", "UA",0,10017}, + { "MAC-", "TH",0,10021}, + { "MAC-", "LAT2",0,10029}, + { "MAC-", "ICE",0,10079}, + { "MAC-", "TR",0,10081}, + { "MAC-", "CR",0,10082} +}; + +int CPLENALL = (sizeof(CodePageNamesAll)/sizeof(CodePageNamesAll[0])); +struct _tcptable *CodePageNamesSupp; +int CPLENSUPP = 1; + +//Gets codepage ID from string representing charset such as "iso-8859-1" +// input- the string +// size- max length of input string +int GetCharsetFromString(char *input,size_t size); + +//HexValue to DecValue ('a' to 10) +// HexValue- hexa value ('a') +// DecValue- poiner where to store dec value +// returns 0 if not success +int FromHexa(char HexValue,char *DecValue); + +//Decodes a char from Base64 +// Base64Value- input char in Base64 +// DecValue- pointer where to store the result +// returns 0 if not success +int FromBase64(char Base64Value,char *DecValue); + +//Decodes string in quoted printable +// Src- input string +// Dst- where to store output string +// DstLen- how max long should be output string +// isQ- if is "Q-encoding" modification. should be TRUE in headers +// always returns 1 +int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ); + +//Decodes string in base64 +// Src- input string +// Dst- where to store output string +// DstLen- how max long should be output string +// returns 0 if string was not properly decoded +int DecodeBase64(char *Src,char *Dst,int DstLen); + +//Converts string to unicode from string with specified codepage +// stream- input string +// cp- codepage of input string +// out- pointer to new allocated memory that contains unicode string +int ConvertStringToUnicode(char *stream,unsigned int cp,WCHAR **out); + +//Converts string from MIME header to unicode +// stream- input string +// cp- codepage of input string +// storeto- pointer to memory that contains unicode string +// mode- MIME_PLAIN or MIME_MAIL (MIME_MAIL deletes '"' from start and end of string) +void ConvertCodedStringToUnicode(char *stream,WCHAR **storeto,DWORD cp,int mode); + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +int GetCharsetFromString(char *input,size_t size) +//"ISO-8859-1" to ID from table +{ + char *pin=input; + char *pout,*parser; + + if ((size<1) || (parser=pout=new char[size+1])==NULL) + return -1; + while((*pin!=0) && (pin-input< (INT_PTR)size)) + { + if ((*pin>='a') && (*pin<='z')) + *parser++=*(pin++)-('a'-'A'); // make it capital + //else if (*pin=='\"') // this is already done in ExtractFromContentType + // *pin++; //skip the quotes if any + else + *parser++=*pin++; + } + + *parser=(char)0; + +#ifdef DEBUG_DECODECODEPAGE + DebugLog(DecodeFile,"%s",pout); +#endif + for (int i=0;i='0' && HexValue<='9') + { + *DecValue=HexValue-'0'; + return 1; + } + if (HexValue>='A' && HexValue<='F') + { + *DecValue=HexValue-'A'+10; + return 1; + } + if (HexValue>='a' && HexValue<='f') + { + *DecValue=HexValue-'a'+10; + return 1; + } + return 0; +} + +int FromBase64(char Base64Value,char *DecValue) +{ + if (Base64Value>='A' && Base64Value<='Z') + { + *DecValue=Base64Value-'A'; + return 1; + } + if (Base64Value>='a' && Base64Value<='z') + { + *DecValue=Base64Value-'a'+26; + return 1; + } + if (Base64Value>='0' && Base64Value<='9') + { + *DecValue=Base64Value-'0'+52; + return 1; + } + if (Base64Value=='+') + { + *DecValue=Base64Value-'+'+62; + return 1; + } + if (Base64Value=='/') + { + *DecValue=Base64Value-'/'+63; + return 1; + } + if (Base64Value=='=') + { + *DecValue=0; + return 1; + } + return 0; +} + +int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ) +{ +#ifdef DEBUG_DECODEQUOTED + char *DstTemp=Dst; + DebugLog(DecodeFile,"%s",Src); +#endif + for (int Counter=0;((char)*Src!=0) && DstLen && (Counter++%s",DstTemp); +#endif + return 1; +} + +int DecodeBase64(char *Src,char *Dst,int DstLen) +{ + int Result=0; + char Locator=0,MiniResult[4]; + char *End=Dst+DstLen; + + MiniResult[0]=MiniResult[1]=MiniResult[2]=MiniResult[3]=0; + +#ifdef DEBUG_DECODEBASE64 + char *DstTemp=Dst; + DebugLog(DecodeFile,"\n%s\n\n",Src); +#endif + while(*Src!=0 && DstLen && Dst!=End) + { + if ((*Src==0x0D)||(*Src==0x0A)) { + Src++; + continue; + } + if ((!(Result=FromBase64(*Src,MiniResult+Locator)) && (*Src==0)) || Locator++==3) //end_of_str || end_of_4_bytes + { + Locator=0; //next write to the first byte + *Dst++=(char)((MiniResult[0]<<2) | (MiniResult[1]>>4)); + if (Dst==End) goto end; //DstLen exceeded? + *Dst++=(char)((MiniResult[1]<<4) | (MiniResult[2]>>2)); + if (Dst==End) goto end; //someones don't like goto, but not me + *Dst++=(char)((MiniResult[2]<<6) | MiniResult[3]); + if (!Result && (*Src==0)) goto end; //end of string? + MiniResult[0]=MiniResult[1]=MiniResult[2]=MiniResult[3]=0; //zero 4byte buffer for next loop + } + if (!Result) return 0; //unrecognised character occured + Src++; + } +end: + *Dst=0; +#ifdef DEBUG_DECODEBASE64 + DebugLog(DecodeFile,"\n%s\n",DstTemp); +#endif + return 1; +} + + + +int ConvertStringToUnicode(char *stream,unsigned int cp,WCHAR **out) +{ + CPINFO CPInfo; + WCHAR *temp,*src=*out,*dest; + size_t outlen; + int streamlen,Index; + + //codepages, which require to have set 0 in dwFlags parameter when calling MultiByteToWideChar + DWORD CodePagesZeroFlags[]={50220,50221,50222,50225,50227,50229,52936,54936,57002,57003,57004,57005,57006,57007,57008,57009,57010,57011,65000,65001}; + + if ((cp!=CP_ACP) && (cp!=CP_OEMCP) && (cp!=CP_MACCP) && (cp!=CP_THREAD_ACP) && (cp!=CP_SYMBOL) && (cp!=CP_UTF7) && (cp!=CP_UTF8) && !GetCPInfo(cp,&CPInfo)) + cp=CP_ACP; +#ifdef DEBUG_DECODECODEPAGE + DebugLog(DecodeFile,"%d",cp); +#endif + + for (Index=0;Index tempstoreLength) break; + start++; + } + } + tempstore[outind] = 0; + *storeto = tempstore; +} diff --git a/protocols/YAMN/src/mails/m_decode.h b/protocols/YAMN/src/mails/m_decode.h new file mode 100644 index 0000000000..e6d2b52fae --- /dev/null +++ b/protocols/YAMN/src/mails/m_decode.h @@ -0,0 +1,25 @@ +#ifndef __DECODE_H +#define __DECODE_H + +#include "../debug.h" + +#define DOTLINE(s) ((((s)[-2]=='\r') || ((s)[-2]=='\n')) && ((s)[-1]=='.') && (((s)[0]=='\r') || ((s)[0]=='\n') || ((s)[0]=='\0'))) // be careful, it's different to ESR's pop3.c ;-) +#define ENDLINE(s) (((s)[0]=='\r') || ((s)[0]=='\n')) //endline +#define WS(s) (((s)[0]==' ') || ((s)[0]=='\t')) //whitespace +#define ENDLINEWS(s) ((((s)[0]=='\r') || ((s)[0]=='\n')) && (((((s)[1]=='\r') || ((s)[1]=='\n')) && (((s)[2]==' ') || ((s)[2]=='\t'))) || (((s)[1]==' ') || ((s)[1]=='\t')))) //endline+whitespace: enters(CR or LF and their combinations) followed by space or tab +#define EOS(s) ((s)[0]==0) //end of string (stream) + +#define CODES(s) ((s[0]=='=') && (s[1]=='?')) //start of coded string +#define CODEE(s) ((s[0]=='?') && (s[1]=='=')) //end of coded string +#define CODED(s) (s[0]=='?') //code delimiter + +#define MIME_PLAIN 1 +#define MIME_MAIL 2 + +struct cptable +{ + char *name; + unsigned int ID; +}; + +#endif diff --git a/protocols/YAMN/src/mails/mails.cpp b/protocols/YAMN/src/mails/mails.cpp new file mode 100644 index 0000000000..af0f3d2329 --- /dev/null +++ b/protocols/YAMN/src/mails/mails.cpp @@ -0,0 +1,499 @@ +/* + * This code implements retrieving info from MIME header + * + * (c) majvan 2002-2004 + */ + +#pragma warning( disable : 4290 ) +#include "../yamn.h" + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +// SMALL INTRO +// Mails are queued in a queue (chained list). Pointer to first mail is pointed from Account structure +// member called Mails. +// Mail queue is ended with NULL- pointered mail (NULL handle) + +//Creates new mail for plugin (calling plugin's constructor, when plugin imported to YAMN) +INT_PTR CreateAccountMailSvc(WPARAM wParam,LPARAM lParam); + +//Deletes mail for plugin (calling plugin's destructor, when plugin imported to YAMN) +INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam); + +//Loads mail data from standard storage to memory +INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam); + +//Deletes mail data from memory +INT_PTR UnloadMailDataSvc(WPARAM wParam,LPARAM); + +//Saves mail data from memory to standard storage +INT_PTR SaveMailDataSvc(WPARAM wParam,LPARAM lParam); + +//Appends second MIME mail queue to the first one +//Only finds the end of first queue and its Next memember repoints to second one +void WINAPI AppendQueueFcn(HYAMNMAIL first,HYAMNMAIL second); + +//Synchronizes two accounts +//Function finds, if there were some mails deleted from mailbox and deletes (depends on RemovedOld param) them from OldQueue +//Next finds, if there are new mails. Mails that are still on mailbox are deleted (depends on RemovedNew param) from NewQueue +//After this, OldQueue is pointer to mails that are on mailbox, but not new mails +//and NewQueue contains new mails in account +//New accounts can be then appended to account mails queue, but they have set the New flag +// +//Two mails equals if they have the same ID +// +// hPlugin- handle of plugin going to delete mails +// OldQueue- queue of mails that we found on mailbox last time, after function finishes queue contains all mails except new ones +// RemovedOld- queue of mails where to store removed mails from OldQueue, if NULL deletes mails from OldQueue +// NewQueue- queue of mails that we found on mailbox (all mails), after function finishes queue contains only new mails +// RemovedNew- queue of mails where to store removed mails from NewQueue, if NULL deletes mails from NewQueue +//So function works like: +//1. delete (or move to RemovedOld queue if RemovedOld is not NULL) all mails from OldQueue not found in NewQueue +//2. delete (or move to RemovedNew queue if RemovedNew is not NULL) all mails from NewQueue found in OldQueue +void WINAPI SynchroMessagesFcn(HACCOUNT Account,HYAMNMAIL *OldQueue,HYAMNMAIL *RemovedOld,HYAMNMAIL *NewQueue,HYAMNMAIL *RemovedNew); + +//Deletes messages from mail From to the end +// Account- account who owns mails +// From- first mail in queue, which is going to delete +void WINAPI DeleteMessagesToEndFcn(HACCOUNT Account,HYAMNMAIL From); + +//Removes message from queue, does not delete from memory +// From- queue pointer +// Which- mail to delete +// mode- nonzero if you want to decrement numbers in messages that are bigger than the one in Which mail, 0 if not +void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From,HYAMNMAIL Which,int mode); + +//Finds message in queue that has the same ID number +// From- message queue +// ID- pointer to ID +// returns pointer to found message, NULL if not found +HYAMNMAIL WINAPI FindMessageByIDFcn(HYAMNMAIL From,char *ID); + +//Translate header from text to queue of CMimeItem structures +//This means that new queue will contain all info about headers +// stream- pointer to text containing header (can be ended with zero) +// len- length of stream +// head- function fills this pointer to first header item in queue +void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head); + +//Creates new mail queue, copying only these mails, that have set flag for deleting +// From- message queue, whose mail with given flag are duplicated +// returns new mail queue (or NULL when no mail with flag is in From queue) +//Function does not copy the whole mails, it copies only ID string. And ID is copied as string, so +//you can use this fcn only if you have your ID as pointer to char string ended with zero character +HYAMNMAIL WINAPI CreateNewDeleteQueueFcn(HYAMNMAIL From); + +//Sets/removes flags from specific mails +// From- pointer to first message +// FlagsSet- mail must have set these flags... +// FlagsNotSet- ...and must not have set these flags... +// FlagsToSetRemove- ...to set/remove these flags (see mode) +// mode- nonzero to set, else remove +void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From,DWORD FlagsSet,DWORD FlagsNotSet,DWORD FlagsToSetRemove,int mode); + +struct CExportedFunctions MailExportedFcn[]= +{ + {YAMN_SYNCHROMIMEMSGSID,(void *)SynchroMessagesFcn}, + {YAMN_TRANSLATEHEADERID,(void *)TranslateHeaderFcn}, + {YAMN_APPENDQUEUEID,(void *)AppendQueueFcn}, + {YAMN_DELETEMIMEQUEUEID,(void *)DeleteMessagesToEndFcn}, + {YAMN_DELETEMIMEMESSAGEID,(void *)DeleteMessageFromQueueFcn}, + {YAMN_FINDMIMEMESSAGEID,(void *)FindMessageByIDFcn}, + {YAMN_CREATENEWDELETEQUEUEID,(void *)CreateNewDeleteQueueFcn}, + {YAMN_SETREMOVEQUEUEFLAGSID,(void *)SetRemoveFlagsInQueueFcn}, +}; + +struct CExportedServices MailExportedSvc[]= +{ + {MS_YAMN_CREATEACCOUNTMAIL,CreateAccountMailSvc}, + {MS_YAMN_DELETEACCOUNTMAIL,DeleteAccountMailSvc}, + {MS_YAMN_LOADMAILDATA,LoadMailDataSvc}, + {MS_YAMN_UNLOADMAILDATA,UnloadMailDataSvc}, + {MS_YAMN_SAVEMAILDATA,SaveMailDataSvc}, +}; + + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +INT_PTR CreateAccountMailSvc(WPARAM wParam,LPARAM lParam) +{ + HACCOUNT Account=(HACCOUNT)wParam; + DWORD MailVersion=(DWORD)lParam; + HYAMNMAIL NewMail; + +//test if we are going to initialize members of suitable structure (structures of plugin and YAMN must match) + if (MailVersion!=YAMN_MAILVERSION) + return NULL; + + if (Account->Plugin!=NULL) + { + if (Account->Plugin->MailFcn->NewMailFcnPtr!=NULL) + { +//Let plugin create its own structure, which can be derived from CAccount structure + if (NULL==(NewMail=Account->Plugin->MailFcn->NewMailFcnPtr(Account,YAMN_MAILVERSION))) + return NULL; + } + else + { +//We suggest plugin uses standard CAccount structure, so we create it + if (NULL==(NewMail=new YAMNMAIL)) +//If not created successfully + return NULL; + NewMail->MailData=NULL; + } +//Init every members of structure, used by YAMN + return (INT_PTR)NewMail; + } + return NULL; +} + +INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam) +{ + HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; + HYAMNMAIL OldMail=(HYAMNMAIL)lParam; + struct CMimeItem *TH; + + if (Plugin->MailFcn!=NULL){ + if (Plugin->MailFcn->DeleteMailFcnPtr!=NULL) { + //Let plugin delete its own CMimeMsgQueue derived structure + Plugin->MailFcn->DeleteMailFcnPtr(OldMail); + return 1; + } + } + if (OldMail->MailData!=NULL) { + if (OldMail->MailData->Body!=NULL) + delete[] OldMail->MailData->Body; + if ((TH=OldMail->MailData->TranslatedHeader)!=NULL) + for (;OldMail->MailData->TranslatedHeader!=NULL;) { + TH=TH->Next; + if (OldMail->MailData->TranslatedHeader->name!=NULL) + delete[] OldMail->MailData->TranslatedHeader->name; + if (OldMail->MailData->TranslatedHeader->value!=NULL) + delete[] OldMail->MailData->TranslatedHeader->value; + delete OldMail->MailData->TranslatedHeader; + OldMail->MailData->TranslatedHeader=TH; + } + delete OldMail->MailData; + } + if (OldMail->ID!=NULL) + delete[] OldMail->ID; + + delete OldMail; //consider mail as standard HYAMNMAIL, not initialized before and use its own destructor + return 1; +} + + +void WINAPI AppendQueueFcn(HYAMNMAIL first,HYAMNMAIL second) +{ + HYAMNMAIL Finder=first; + while(Finder->Next!=NULL) Finder=Finder->Next; + Finder->Next=second; +} + +INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam) +{ + HYAMNMAIL Mail=(HYAMNMAIL)wParam; + DWORD MailVersion=(DWORD)lParam; + + if (MailVersion!=YAMN_MAILDATAVERSION) + return NULL; + +//now we have all data to memory persisting, so no loading is needed + return (INT_PTR)Mail->MailData; +} + +INT_PTR UnloadMailDataSvc(WPARAM wParam,LPARAM) +{ + HYAMNMAIL Mail=(HYAMNMAIL)wParam; + +//now we should delete structure from memory, but it will be made in future YAMN version + return 1; +} + +INT_PTR SaveMailDataSvc(WPARAM wParam,LPARAM lParam) +{ + HYAMNMAIL Mail=(HYAMNMAIL)wParam; + DWORD MailVersion=(DWORD)lParam; + + if (MailVersion!=YAMN_MAILDATAVERSION) + return (INT_PTR)-1; + +//now we have all data to memory persisting, so no saving is needed + return (INT_PTR)0; +} + +void WINAPI SynchroMessagesFcn(HACCOUNT Account,HYAMNMAIL *OldQueue,HYAMNMAIL *RemovedOld,HYAMNMAIL *NewQueue,HYAMNMAIL *RemovedNew) +//deletes messages from new queue, if they are old +//it also deletes messages from old queue, if they are not in mailbox anymore +//"YAMN_MSG_DELETED" messages in old queue remain in old queue (are never removed, although they are not in new queue) +//"YAMN_MSG_DELETED" messages in new queue remain in new queue (are never removed, although they can be in old queue) +{ + HYAMNMAIL Finder,FinderPrev; + HYAMNMAIL Parser,ParserPrev; + HYAMNMAIL RemovedOldParser =NULL; + HYAMNMAIL RemovedNewParser =NULL; + if (RemovedOld!=NULL) *RemovedOld=NULL; + if (RemovedNew!=NULL) *RemovedNew=NULL; + + for (FinderPrev=NULL,Finder=*OldQueue;Finder!=NULL;) + { + if (Finder->Flags & YAMN_MSG_DELETED) //if old queue contains deleted mail + { + FinderPrev=Finder; + Finder=Finder->Next; //get next message in old queue for testing + continue; + } + for (ParserPrev=NULL,Parser=*NewQueue;Parser!=NULL;ParserPrev=Parser,Parser=Parser->Next) + { + if (Parser->Flags & YAMN_MSG_DELETED) + continue; + + if (Parser->ID==NULL) //simply ignore the message, that has not filled its ID + continue; + + if (0==strcmp(Parser->ID,Finder->ID)) //search for equal message in new queue + break; + } + if (Parser!=NULL) //found equal message in new queue + { + if (Parser==*NewQueue) + *NewQueue=(*NewQueue)->Next; + else + ParserPrev->Next=Parser->Next; + Finder->Number=Parser->Number; //rewrite the number of current message in old queue + + if (RemovedNew==NULL) //delete from new queue + DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Parser); + else //or move to RemovedNew + { + if (RemovedNewParser==NULL) //if it is first mail removed from NewQueue + *RemovedNew=Parser; //set RemovedNew queue to point to first message in removed queue + else + RemovedNewParser->Next=Parser; //else don't forget to show to next message in RemovedNew queue + RemovedNewParser=Parser; //follow RemovedNew queue + RemovedNewParser->Next=NULL; + } + FinderPrev=Finder; + Finder=Finder->Next; //get next message in old queue for testing + } + else //a message was already deleted from mailbox + { + if (Finder==*OldQueue) //if we are at the first item in OldQueue + { + *OldQueue=(*OldQueue)->Next; //set OldQueue to next item + if (RemovedOld==NULL) //delete from old queue + DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Finder); + else //or move to RemovedOld + { + if (RemovedOldParser==NULL) //if it is first mail removed from OldQueue + *RemovedOld=Finder; //set RemovedOld queue to point to first message in removed queue + else + RemovedOldParser->Next=Finder; //else don't forget to show to next message in RemovedNew queue + RemovedOldParser=Finder; //follow RemovedOld queue + RemovedOldParser->Next=NULL; + } + Finder=*OldQueue; + } + else + { + FinderPrev->Next=Finder->Next; + if (RemovedOld==NULL) //delete from old queue + DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Finder); + else //or move to RemovedOld + { + if (RemovedOldParser==NULL) //if it is first mail removed from OldQueue + *RemovedOld=Finder; //set RemovedOld queue to point to first message in removed queue + else + RemovedOldParser->Next=Finder; //else don't forget to show to next message in RemovedNew queue + RemovedOldParser=Finder; //follow RemovedOld queue + RemovedOldParser->Next=NULL; + } + Finder=FinderPrev->Next; + } + } + } +} + +void WINAPI DeleteMessagesToEndFcn(HACCOUNT Account,HYAMNMAIL From) +{ + HYAMNMAIL Temp; + while(From!=NULL) + { + Temp=From; + From=From->Next; + DeleteAccountMailSvc((WPARAM)Account->Plugin,(LPARAM)Temp); + } +} + +void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From,HYAMNMAIL Which,int mode=0) +{ + DWORD Number=Which->Number; + HYAMNMAIL Parser; + + if (*From==Which) + { + Parser=Which->Next; + *From=Parser; + } + else + { + for (Parser=*From;Which!=Parser->Next;Parser=Parser->Next) + if (mode && (Parser->Number>Number)) Parser->Number--; + if (mode && (Parser->Number>Number)) Parser->Number--; + Parser->Next=Parser->Next->Next; + Parser=Which->Next; + } + if (mode) + for (;Parser!=NULL;Parser=Parser->Next) + if (Parser->Number>Number) Parser->Number--; +} + +void DeleteMessagesFromQueue(HYAMNMAIL *From,HYAMNMAIL Which,int mode=0) +{ + HYAMNMAIL Parser; + + for (Parser=Which;Parser!=NULL;Parser=Parser->Next) + DeleteMessageFromQueueFcn(From,Parser,mode); +} + +HYAMNMAIL WINAPI FindMessageByIDFcn(HYAMNMAIL From,char *ID) +{ + HYAMNMAIL Browser; + + for (Browser=From;Browser!=NULL;Browser=Browser->Next) + if (0==lstrcmpA(Browser->ID,ID)) + break; + return Browser; +} + +void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head) +{ + try + { + char *finder=stream; + char *prev1,*prev2,*prev3; + struct CMimeItem *Item=NULL; + + while(finder<=(stream+len)) + { + while(ENDLINEWS(finder)) finder++; + + //at the start of line + if (DOTLINE(finder+1)) //at the end of stream + break; + + prev1=finder; + + while(*finder!=':' && !EOS(finder)) finder++; + if (!EOS(finder)) + prev2=finder++; + else + break; + + while(WS(finder) && !EOS(finder)) finder++; + if (!EOS(finder)) + prev3=finder; + else + break; + + do + { + if (ENDLINEWS(finder)) finder+=2; //after endline information continues + while(!ENDLINE(finder) && !EOS(finder)) finder++; + }while(ENDLINEWS(finder)); + + if (Item!=NULL) + { + if (NULL==(Item->Next=new struct CMimeItem)) + break; + Item=Item->Next; + } + else + { + Item = new CMimeItem; + *head = Item; + } + + Item->Next=NULL; + Item->name=new char [prev2-prev1+1]; + lstrcpynA(Item->name,prev1,prev2-prev1+1); + Item->value=new char [finder-prev3+1]; + lstrcpynA(Item->value,prev3,finder-prev3+1); + + if (EOS(finder)) + break; + finder++; + if (ENDLINE(finder)) { + finder++; + if (ENDLINE(finder)) { + // end of headers. message body begins + finder++; + if (ENDLINE(finder))finder++; + prev1 = finder; + while (!DOTLINE(finder+1))finder++; + if (ENDLINE(finder))finder--; + prev2 = finder; + if (prev2>prev1){ // yes, we have body + if (NULL==(Item->Next=new struct CMimeItem)) break; // Cant create new item?! + Item=Item->Next; + Item->Next=NULL;//just in case; + Item->name=new char[5]; strncpy(Item->name,"Body",5); + Item->value=new char [prev2-prev1]; + lstrcpynA(Item->value,prev1,prev2-prev1-1); + } + break; // there is nothing else + } + } + } + } + catch(...) + { + MessageBoxA(NULL,"Translate header error","",0); + } +} + +HYAMNMAIL WINAPI CreateNewDeleteQueueFcn(HYAMNMAIL From) +{ + HYAMNMAIL FirstMail,Browser; + + for (FirstMail=NULL;From!=NULL;From=From->Next) + { + if ((From->Flags & (YAMN_MSG_USERDELETE | YAMN_MSG_AUTODELETE)) && !(From->Flags & YAMN_MSG_DELETED)) + { + if (FirstMail==NULL) + { + FirstMail=Browser=new YAMNMAIL; + if (FirstMail==NULL) + break; + } + else + { + Browser->Next=new YAMNMAIL; + Browser=Browser->Next; + } + Browser->ID=new char[strlen(From->ID)+1]; + strcpy(Browser->ID,From->ID); + Browser->Number=From->Number; + Browser->Flags=From->Flags; + } + } + return FirstMail; +} + +void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From,DWORD FlagsSet,DWORD FlagsNotSet,DWORD FlagsToSetRemove,int mode) +{ + HYAMNMAIL msgq; + + for (msgq=(HYAMNMAIL)From;msgq!=NULL;msgq=msgq->Next) + { + if ((FlagsSet==(msgq->Flags & FlagsSet)) && (0==(msgq->Flags & FlagsNotSet))) + { + if (mode) + msgq->Flags=msgq->Flags | FlagsToSetRemove; + else + msgq->Flags=msgq->Flags & ~FlagsToSetRemove; + } + } +} diff --git a/protocols/YAMN/src/mails/mime.cpp b/protocols/YAMN/src/mails/mime.cpp new file mode 100644 index 0000000000..2a66b80e2b --- /dev/null +++ b/protocols/YAMN/src/mails/mime.cpp @@ -0,0 +1,732 @@ +/* + * This code implements retrieving info from MIME header + * + * (c) majvan 2002-2004 + */ + +#pragma warning( disable : 4290 ) +#include "../yamn.h" + +//- imported --------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +extern SWMRG *AccountBrowserSO; +extern struct WndHandles *MessageWnd; + +extern int GetCharsetFromString(char *input,size_t size); +extern void SendMsgToRecepients(struct WndHandles *FirstWin,UINT msg,WPARAM wParam,LPARAM lParam); +extern void ConvertCodedStringToUnicode(char *stream,WCHAR **storeto,DWORD cp,int mode); +extern DWORD WINAPI MailBrowser(LPVOID Param); +extern DWORD WINAPI NoNewMailProc(LPVOID Param); +extern DWORD WINAPI BadConnection(LPVOID Param); + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +//Copies one string to another +// srcstart- source string +// srcend- address to the end of source string +// dest- pointer that stores new allocated string that contains copy of source string +// mode- MIME_PLAIN or MIME_MAIL (MIME_MAIL deletes '"' characters (or '<' and '>') if they are at start and end of source string +void CopyToHeader(char *srcstart,char *srcend,char **dest,int mode); + +//Extracts email address (finds nick name and mail and then stores them to strings) +// finder- source string +// storeto- pointer that receives address of mail string +// storetonick- pointer that receives address of nickname +void ExtractAddressFromLine(char *finder,char **storeto,char **storetonick); + +//Extracts simple text from string +// finder- source string +// storeto- pointer that receives address of string +void ExtractStringFromLine(char *finder,char **storeto); + +//Extracts some item from content-type string +//Example: ContentType string: "TEXT/PLAIN; charset=US-ASCII", item:"charset=", returns: "US-ASCII" +// ContetType- content-type string +// value- string item +// returns extracted string (or NULL when not found) +char *ExtractFromContentType(char *ContentType,char *value); + +//Extracts info from header text into header members +//Note that this function as well as struct CShortHeadwer can be always changed, because there are many items to extract +//(e.g. the X-Priority and Importance and so on) +// items- translated header (see TranslateHeaderFcn) +// head- header to be filled with values extracted from items +void ExtractShortHeader(struct CMimeItem *items,struct CShortHeader *head); + +//Extracts header to mail using ExtractShortHeader fcn. +// items- translated header (see TranslateHeaderFcn) +// CP- codepage used when no default found +// head- header to be filled with values extracted from items, in unicode (wide char) +void ExtractHeader(struct CMimeItem *items,int &CP,struct CHeader *head); + +//Deletes items in CShortHeader structure +// head- structure whose items are deleted +void DeleteShortHeaderContent(struct CShortHeader *head); + +//Deletes list of YAMN_MIMENAMES structures +// Names- pointer to first item of list +void DeleteNames(PYAMN_MIMENAMES Names); + +//Deletes list of YAMN_MIMESHORTNAMES structures +// Names- pointer to first item of list +void DeleteShortNames(PYAMN_MIMESHORTNAMES Names); + +//Makes a string lowercase +// string- string to be lowercased +void inline ToLower(char *string); + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +void CopyToHeader(char *srcstart,char *srcend,char **dest,int mode) +{ + char *dst; + + if (dest==NULL) + return; + if (srcstart>=srcend) + return; + + if ((mode==MIME_MAIL) && (((*srcstart=='"') && (*(srcend-1)=='"')) || ((*srcstart=='<') && (*(srcend-1)=='>')))) + { + srcstart++; + srcend--; + } + + if (srcstart>=srcend) + return; + + if (NULL!=*dest) + delete[] *dest; + if (NULL==(*dest=new char[srcend-srcstart+1])) + return; + + dst=*dest; + + for (;srcstart' at the end of line + CopyToHeader(finder,finderend+1,storeto,MIME_MAIL); + else //at the end of line, there's '>' + { + char *finder2=finderend; + while((*finder2!='<') && (finder2>finder)) finder2--; //go to matching '<' or to the start + CopyToHeader(finder2,finderend+1,storeto,MIME_MAIL); + if (*finder2=='<') //if we found '<', the rest copy as from nick + { + finder2--; + while(WS(finder2) || ENDLINE(finder2)) finder2--; //parse whitespace + CopyToHeader(finder,finder2+1,storetonick,MIME_MAIL); //and store nickname + } + } + } + else + { + char *finderend=finder+1; + do + { + if (ENDLINEWS(finderend)) //after endline information continues + finderend+=2; + while(!ENDLINE(finderend) && (*finderend!='>') && !EOS(finderend)) finderend++; //seek to the matching < or to the end of line or to the end of string + }while(ENDLINEWS(finderend)); + CopyToHeader(finder,finderend+1,storeto,MIME_MAIL); //go to first '>' or to the end and copy + finder=finderend+1; + while(WS(finder)) finder++; //parse whitespace + if (!ENDLINE(finder) && !EOS(finder)) //if there are chars yet, it's nick + { + finderend=finder+1; + while(!ENDLINE(finderend) && !EOS(finderend)) finderend++; //seek to the end of line or to the end of string + finderend--; + while(WS(finderend)) finderend--; //find the end of line, no whitespace + CopyToHeader(finder,finderend+1,storetonick,MIME_MAIL); + } + } +} + +void ExtractStringFromLine(char *finder,char **storeto) +{ + if (finder==NULL) + { + *storeto=NULL; + return; + } + while(WS(finder)) finder++; + char *finderend=finder; + + do + { + if (ENDLINEWS(finderend)) finderend++; //after endline information continues + while(!ENDLINE(finderend) && !EOS(finderend)) finderend++; + }while(ENDLINEWS(finderend)); + finderend--; + while(WS(finderend)) finderend--; //find the end of line, no whitespace + CopyToHeader(finder,finderend+1,storeto,MIME_PLAIN); +} + +char *ExtractFromContentType(char *ContentType,char *value) +{ + char *lowered = _strdup(ContentType); + ToLower(lowered); + char *finder=strstr(lowered,value); + if (finder==NULL){ + free (lowered); + return NULL; + } + finder = finder-lowered+ContentType; + free (lowered); + + char *temp,*copier; + char *CopiedString; + + temp=finder-1; + while((temp>ContentType) && WS(temp)) temp--; //now we have to find, if the word "Charset=" is located after ';' like "; Charset=" + if (*temp!=';' && !ENDLINE(temp) && temp!=ContentType) + return NULL; + finder=finder+strlen(value); //jump over value string + + while(WS(finder)) finder++; //jump over whitespaces + temp=finder; + while(*temp!=0 && *temp!=';') temp++; //jump to the end of setting (to the next ;) + temp--; + while(WS(temp)) temp--; //remove whitespaces from the end + if (*finder=='\"') { //remove heading and tailing quotes + finder++; + if (*temp=='\"') temp--; + } + if (NULL==(CopiedString=new char[++temp-finder+1])) + return NULL; + for (copier=CopiedString;finder!=temp;*copier++=*finder++); //copy string + *copier=0; //and end it with zero character + + return CopiedString; +} + +void ExtractShortHeader(struct CMimeItem *items,struct CShortHeader *head) +{ + for (;items!=NULL;items=items->Next) + { + //at the start of line + //MessageBox(NULL,items->value,items->name,0); + if (0==_strnicmp(items->name,"From",4)) + { + if (items->value==NULL) + continue; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,""); + #endif + ExtractAddressFromLine(items->value,&head->From,&head->FromNick); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + } + else if (0==_strnicmp(items->name,"Return-Path",11)) + { + if (items->value==NULL) + continue; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,""); + #endif + ExtractAddressFromLine(items->value,&head->ReturnPath,&head->ReturnPathNick); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + } + else if (0==_strnicmp(items->name,"Subject",7)) + { + if (items->value==NULL) + continue; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,""); + #endif + ExtractStringFromLine(items->value,&head->Subject); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + } + else if (0==_strnicmp(items->name,"Body",4)) + { + if (items->value==NULL) + continue; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,""); + #endif + ExtractStringFromLine(items->value,&head->Body); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + } + else if (0==_strnicmp(items->name,"Date",4)) + { + if (items->value==NULL) + continue; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,""); + #endif + ExtractStringFromLine(items->value,&head->Date); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + } + else if (0==_strnicmp(items->name,"Content-Type",12)) + { + if (items->value==NULL) + continue; + + char *ContentType=NULL,*CharSetStr; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,""); + #endif + ExtractStringFromLine(items->value,&ContentType); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + ToLower(ContentType); + if (NULL!=(CharSetStr=ExtractFromContentType(ContentType,"charset="))) + { + head->CP=GetCharsetFromString(CharSetStr,strlen(CharSetStr)); + delete[] CharSetStr; + } + delete[] ContentType; + } + else if (0==_strnicmp(items->name,"Importance",10)) + { + if (items->value==NULL) + continue; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,""); + #endif + if (head->Priority!=-1) + { + if (0==strncmp(items->value,"low",3)) + head->Priority=5; + else if (0==strncmp(items->value,"normal",6)) + head->Priority=3; + else if (0==strncmp(items->value,"high",4)) + head->Priority=1; + } + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + } + else if (0==_strnicmp(items->name,"X-Priority",10)) + { + if (items->value==NULL) + continue; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,""); + #endif + if ((*items->value>='1') && (*items->value<='5')) + head->Priority=*items->value-'0'; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"
\n"); + #endif + } + + } +} + +void ExtractHeader(struct CMimeItem *items,int &CP,struct CHeader *head) +{ + struct CShortHeader ShortHeader; + + ZeroMemory(&ShortHeader,sizeof(struct CShortHeader)); + ShortHeader.Priority=ShortHeader.CP=-1; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + ExtractShortHeader(items,&ShortHeader); + + head->Priority=ShortHeader.Priority==-1 ? 3 : ShortHeader.Priority; + CP=ShortHeader.CP==-1 ? CP : ShortHeader.CP; + #ifdef DEBUG_DECODE + if (NULL!=ShortHeader.From) + DebugLog(DecodeFile,"%s%s%s%s%s%s\n"); + DebugLog(DecodeFile,"\n"); + #endif + + ConvertCodedStringToUnicode(ShortHeader.From,&head->From,CP,MIME_PLAIN); + + #ifdef DEBUG_DECODE + if (NULL!=head->From) + DebugLogW(DecodeFile,L"%s\n",head->From); + #endif + ConvertCodedStringToUnicode(ShortHeader.FromNick,&head->FromNick,CP,MIME_MAIL); + #ifdef DEBUG_DECODE + if (NULL!=head->FromNick) + DebugLogW(DecodeFile,L"%s\n",head->FromNick); + #endif + ConvertCodedStringToUnicode(ShortHeader.ReturnPath,&head->ReturnPath,CP,MIME_PLAIN); + #ifdef DEBUG_DECODE + if (NULL!=head->ReturnPath) + DebugLogW(DecodeFile,L"%s\n",head->ReturnPath); + #endif + ConvertCodedStringToUnicode(ShortHeader.ReturnPathNick,&head->ReturnPathNick,CP,MIME_MAIL); + #ifdef DEBUG_DECODE + if (NULL!=head->ReturnPathNick) + DebugLogW(DecodeFile,L"%s\n",head->ReturnPathNick); + #endif + ConvertCodedStringToUnicode(ShortHeader.Subject,&head->Subject,CP,MIME_PLAIN); + #ifdef DEBUG_DECODE + if (NULL!=head->Subject) + DebugLogW(DecodeFile,L"%s\n",head->Subject); + #endif + ConvertCodedStringToUnicode(ShortHeader.Date,&head->Date,CP,MIME_PLAIN); + #ifdef DEBUG_DECODE + if (NULL!=head->Date) + DebugLogW(DecodeFile,L"%s\n",head->Date); + #endif + + ConvertCodedStringToUnicode(ShortHeader.Body,&head->Body,CP,MIME_PLAIN); + #ifdef DEBUG_DECODE + if (NULL!=head->Body) + DebugLogW(DecodeFile,L"%s\n",head->Body); + #endif + + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + + DeleteShortHeaderContent(&ShortHeader); + +// head->From=L"Frommmm"; +// head->Subject=L"Subject"; + return; +} + +void DeleteShortHeaderContent(struct CShortHeader *head) +{ + if (head->From!=NULL) delete[] head->From; + if (head->FromNick!=NULL) delete[] head->FromNick; + if (head->ReturnPath!=NULL) delete[] head->ReturnPath; + if (head->ReturnPathNick!=NULL) delete[] head->ReturnPathNick; + if (head->Subject!=NULL) delete[] head->Subject; + if (head->Date!=NULL) delete[] head->Date; + if (head->To!=NULL) DeleteShortNames(head->To); + if (head->Cc!=NULL) DeleteShortNames(head->Cc); + if (head->Bcc!=NULL) DeleteShortNames(head->Bcc); + if (head->Body!=NULL) delete[] head->Body; +} + +void DeleteHeaderContent(struct CHeader *head) +{ + if (head->From!=NULL) delete[] head->From; + if (head->FromNick!=NULL) delete[] head->FromNick; + if (head->ReturnPath!=NULL) delete[] head->ReturnPath; + if (head->ReturnPathNick!=NULL) delete[] head->ReturnPathNick; + if (head->Subject!=NULL) delete[] head->Subject; + if (head->Date!=NULL) delete[] head->Date; + if (head->Body!=NULL) delete[] head->Body; + if (head->To!=NULL) DeleteNames(head->To); + if (head->Cc!=NULL) DeleteNames(head->Cc); + if (head->Bcc!=NULL) DeleteNames(head->Bcc); +} + +void DeleteNames(PYAMN_MIMENAMES Names) +{ + PYAMN_MIMENAMES Parser=Names,Old; + for (;Parser!=NULL;Parser=Parser->Next) + { + if (Parser->Value!=NULL) + delete[] Parser->Value; + if (Parser->ValueNick!=NULL) + delete[] Parser->ValueNick; + Old=Parser; + Parser=Parser->Next; + delete Old; + } +} + +void DeleteShortNames(PYAMN_MIMESHORTNAMES Names) +{ + PYAMN_MIMESHORTNAMES Parser=Names,Old; + for (;Parser!=NULL;Parser=Parser->Next) + { + if (Parser->Value!=NULL) + delete[] Parser->Value; + if (Parser->ValueNick!=NULL) + delete[] Parser->ValueNick; + Old=Parser; + Parser=Parser->Next; + delete Old; + } +} + + +void inline ToLower(char *string) +{ + for (;*string!=0;string++) + if (*string>='A' && *string<='Z') *string=*string-'A'+'a'; +} + +#define TE_UNKNOWN +#define TE_QUOTEDPRINTABLE 1 +#define TE_BASE64 2 +struct APartDataType +{ + char *Src;//Input + char *ContType; + int CodePage; + char *TransEnc; + BYTE TransEncType; //TE_something + char *body; + int bodyLen; + WCHAR *wBody; +}; + + +void ParseAPart(APartDataType *data) +{ + size_t len = strlen(data->Src); + try + { + char *finder=data->Src; + char *prev1,*prev2,*prev3; + + while(finder<=(data->Src+len)) + { + while(ENDLINEWS(finder)) finder++; + + //at the start of line + if (finder>data->Src){ + if (*(finder-2)=='\r' || *(finder-2)=='\n') + *(finder-2)=0; + if (*(finder-1)=='\r' || *(finder-1)=='\n') + *(finder-1)=0; + } + prev1=finder; + + while(*finder!=':' && !EOS(finder) && !ENDLINE(finder)) finder++; + if (ENDLINE(finder)||EOS(finder)) { + // no ":" in the line? here the body begins; + data->body = prev1; + break; + } + prev2=finder++; + + while(WS(finder) && !EOS(finder)) finder++; + if (!EOS(finder)) + prev3=finder; + else + break; + + do + { + if (ENDLINEWS(finder)) finder+=2; //after endline information continues + while(!ENDLINE(finder) && !EOS(finder)) finder++; + }while(ENDLINEWS(finder)); + + if (!_strnicmp(prev1,"Content-type",prev2-prev1)) { + data->ContType = prev3; + } else if (!_strnicmp(prev1,"Content-Transfer-Encoding",prev2-prev1)) { + data->TransEnc = prev3; + } + + if (EOS(finder)) + break; + finder++; + if (ENDLINE(finder)) { + finder++; + if (ENDLINE(finder)) { + // end of headers. message body begins + if (finder>data->Src){ + if (*(finder-2)=='\r' || *(finder-2)=='\n') + *(finder-2)=0; + if (*(finder-1)=='\r' || *(finder-1)=='\n') + *(finder-1)=0; + } + finder++; + if (ENDLINE(finder))finder++; + prev1 = finder; + while (!EOS(finder+1))finder++; + if (ENDLINE(finder))finder--; + prev2 = finder; + if (prev2>prev1){ // yes, we have body + data->body = prev1; + } + break; // there is nothing else + } + } + } + } + catch(...) + { + MessageBox(NULL,_T("Translate header error"),_T(""),0); + } + if (data->body) data->bodyLen = (int)strlen(data->body); +} + +//from decode.cpp +int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ); +int DecodeBase64(char *Src,char *Dst,int DstLen); +int ConvertStringToUnicode(char *stream,unsigned int cp,WCHAR **out); + +WCHAR *ParseMultipartBody(char *src, char *bond) +{ + char *srcback = _strdup(src); + size_t sizebond = strlen(bond); + int numparts = 1; + int i; + char *courbond = srcback; + WCHAR *dest; + for (;(courbond=strstr(courbond,bond));numparts++,courbond+=sizebond); + APartDataType *partData = new APartDataType[numparts]; + memset(partData, 0, sizeof(APartDataType)*numparts); + partData[0].Src = courbond = srcback; + for (i=1;(courbond=strstr(courbond,bond));i++,courbond+=sizebond){ + *(courbond-2) = 0; + partData[i].Src = courbond+sizebond; + while (ENDLINE(partData[i].Src)) partData[i].Src++; + } + size_t resultSize=0; + for (i=0;i + +#include "m_hotkeys.h" + +//-------------------------------------------------------------------------------------------------- + +TCHAR ProfileName[MAX_PATH]; +TCHAR UserDirectory[MAX_PATH]; + +TCHAR szMirandaDir[MAX_PATH]; +TCHAR szProfileDir[MAX_PATH]; + +int YAMN_STATUS; + +BOOL UninstallPlugins; + +HANDLE hAccountFolder; + +HINSTANCE *hDllPlugins; +static int iDllPlugins = 0; + + +YAMN_VARIABLES YAMNVar; + +int hLangpack; + +PLUGININFOEX pluginInfo = { + sizeof(PLUGININFOEX), + YAMN_SHORTNAME, + YAMN_VERSION, + "Mail notifier and browser for Miranda NG. Included POP3 protocol.", + "y_b tweety (majvan)", + "francois.mean@skynet.be", + "© (2002-2004 majvan) 2005-2007 tweety y_b Miranda community", + "http://miranda-ng.org/", //"http://www.majvan.host.sk/Projekty/YAMN?fm = soft", + UNICODE_AWARE, + { 0xb047a7e5, 0x27a, 0x4cfc, { 0x8b, 0x18, 0xed, 0xa8, 0x34, 0x5d, 0x27, 0x90 } } // {B047A7E5-027A-4cfc-8B18-EDA8345D2790} +}; + +HANDLE hNewMailHook; +HANDLE NoWriterEV; +HANDLE hTTButton; + +UINT SecTimer; + +HANDLE hMenuItemMain = 0; +HANDLE hMenuItemCont = 0; +HANDLE hMenuItemContApp = 0; + +HMODULE hUxTheme = 0; +BOOL (WINAPI *MyEnableThemeDialogTexture)(HANDLE, DWORD) = 0; + +// function pointers, use typedefs for casting to shut up the compiler when using GetProcAddress() + +typedef BOOL (WINAPI *PITA)(); +typedef HANDLE (WINAPI *POTD)(HWND, LPCWSTR); +typedef UINT (WINAPI *PDTB)(HANDLE, HDC, int, int, RECT *, RECT *); +typedef UINT (WINAPI *PCTD)(HANDLE); +typedef UINT (WINAPI *PDTT)(HANDLE, HDC, int, int, LPCWSTR, int, DWORD, DWORD, RECT *); + +PITA pfnIsThemeActive = 0; +POTD pfnOpenThemeData = 0; +PDTB pfnDrawThemeBackground = 0; +PCTD pfnCloseThemeData = 0; +PDTT pfnDrawThemeText = 0; + +#define FIXED_TAB_SIZE 100 // default value for fixed width tabs + +/* + * visual styles support (XP+) + * returns 0 on failure + */ + +int InitVSApi() +{ + if ((hUxTheme = LoadLibraryA("uxtheme.dll")) == 0) + return 0; + + pfnIsThemeActive = (PITA)GetProcAddress(hUxTheme, "IsThemeActive"); + pfnOpenThemeData = (POTD)GetProcAddress(hUxTheme, "OpenThemeData"); + pfnDrawThemeBackground = (PDTB)GetProcAddress(hUxTheme, "DrawThemeBackground"); + pfnCloseThemeData = (PCTD)GetProcAddress(hUxTheme, "CloseThemeData"); + pfnDrawThemeText = (PDTT)GetProcAddress(hUxTheme, "DrawThemeText"); + + MyEnableThemeDialogTexture = (BOOL (WINAPI *)(HANDLE, DWORD))GetProcAddress(hUxTheme, "EnableThemeDialogTexture"); + if (pfnIsThemeActive != 0 && pfnOpenThemeData != 0 && pfnDrawThemeBackground != 0 && pfnCloseThemeData != 0 && pfnDrawThemeText != 0) + return 1; + + return 0; +} + +/* + * unload uxtheme.dll + */ + +int FreeVSApi() +{ + if (hUxTheme != 0) + FreeLibrary(hUxTheme); + return 0; +} + +//-------------------------------------------------------------------------------------------------- + +static void GetProfileDirectory(TCHAR *szPath, int cbPath) +//This is copied from Miranda's sources. In 0.2.1.0 it is needed, in newer vesions of Miranda use MS_DB_GETPROFILEPATH service +{ + TCHAR tszOldPath[MAX_PATH]; + CallService(MS_DB_GETPROFILEPATHT, SIZEOF(tszOldPath), (LPARAM)tszOldPath); + _tcscat(tszOldPath, _T("\\*.book")); + + TCHAR* ptszNewPath = Utils_ReplaceVarsT( _T("%miranda_userdata%")); + + SHFILEOPSTRUCT file_op = { + NULL, + FO_MOVE, + tszOldPath, + ptszNewPath, + FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_SILENT, + false, + 0, + _T("") }; + SHFileOperation(&file_op); + + _tcsncpy(szPath, ptszNewPath, cbPath); + mir_free(ptszNewPath); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + YAMNVar.hInst = hinstDLL; + return TRUE; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MUUID_YAMN_FORCECHECK, MIID_LAST}; + +///////////////////////////////////////////////////////////////////////////////////////// + +#ifdef YAMN_DEBUG +static char unknownCP[1500] = {0}; +#endif +// The callback function +BOOL CALLBACK EnumSystemCodePagesProc(LPTSTR cpStr) +{ + //Convert code page string to number + UINT cp = _ttoi(cpStr); + if (!IsValidCodePage(cp)) + return TRUE; + + //Get Code Page name + CPINFOEX info; + if (GetCPInfoEx(cp, 0, &info)) { + #ifdef YAMN_DEBUG + BOOLEAN found = FALSE; + #endif + for (int i = 1;i= SIZEOF(iconList)) + return NULL; + return iconList[idx].hIcon; +} + +HICON WINAPI g_LoadIconEx( int idx, bool big ) +{ + if ( idx >= SIZEOF(iconList)) + return NULL; + return ( HICON )CallService(MS_SKIN2_GETICON, big, (LPARAM)iconList[idx].szName); +} + +void WINAPI g_ReleaseIcon( HICON hIcon ) +{ + if ( hIcon ) CallService(MS_SKIN2_RELEASEICON, (WPARAM)hIcon, 0); +} + +static void LoadPlugins() +{ + HANDLE hFind; + WIN32_FIND_DATA fd; + TCHAR szSearchPath[MAX_PATH]; + TCHAR szPluginPath[MAX_PATH]; + lstrcpy(szSearchPath, szMirandaDir); + lstrcat(szSearchPath, _T("\\Plugins\\YAMN\\*.dll")); + typedef INT_PTR (*LOADFILTERFCN)(MIRANDASERVICE GetYAMNFcn); + + hDllPlugins = NULL; + + if (INVALID_HANDLE_VALUE!=(hFind = FindFirstFile(szSearchPath, &fd))) { + do { + //rewritten from Miranda sources... Needed because Win32 API has a bug in FindFirstFile, search is done for *.dlllllll... too + TCHAR *dot = _tcsrchr(fd.cFileName, '.'); + if (dot == NULL ) + continue; + + // we have a dot + int len = (int)lstrlen(fd.cFileName); // find the length of the string + TCHAR* end = fd.cFileName+len; // get a pointer to the NULL + int safe = (end-dot)-1; // figure out how many chars after the dot are "safe", not including NULL + + if ((safe!=3) || (lstrcmpi(dot+1, _T("dll"))!=0)) //not bound, however the "dll" string should mean only 3 chars are compared + continue; + + HINSTANCE hDll; + LOADFILTERFCN LoadFilter; + + lstrcpy(szPluginPath, szMirandaDir); + lstrcat(szPluginPath, _T("\\Plugins\\YAMN\\")); + lstrcat(szPluginPath, fd.cFileName); + if ((hDll = LoadLibrary(szPluginPath)) == NULL) continue; + LoadFilter = (LOADFILTERFCN)GetProcAddress(hDll, "LoadFilter"); + if (NULL == LoadFilter) { + FreeLibrary(hDll); + hDll = NULL; + continue; + } + + if (!(*LoadFilter)(GetFcnPtrSvc)) { + FreeLibrary(hDll); + hDll = NULL; + } + + if (hDll != NULL) { + hDllPlugins = (HINSTANCE *)realloc((void *)hDllPlugins, (iDllPlugins+1)*sizeof(HINSTANCE)); + hDllPlugins[iDllPlugins++] = hDll; + } + } + while(FindNextFile(hFind, &fd)); + + FindClose(hFind); + } +} + +extern "C" int __declspec(dllexport) Load(void) +{ + int i, k; + mir_getLP(&pluginInfo); + + YAMN_STATUS = ID_STATUS_OFFLINE; + + // we get the Miranda Root Path + if (ServiceExists(MS_UTILS_PATHTOABSOLUTET)) + CallService(MS_UTILS_PATHTOABSOLUTET, (WPARAM)_T("."), (LPARAM)szMirandaDir); + else { + GetModuleFileName(GetModuleHandle(NULL), szMirandaDir, MAX_PATH); + TCHAR* str2 = _tcsrchr(szMirandaDir, '\\'); + if (str2!=NULL) *str2 = 0; + } + + // retrieve the current profile name + CallService(MS_DB_GETPROFILENAMET, (WPARAM)SIZEOF(ProfileName), (LPARAM)ProfileName); //not to pass entire array to fcn + TCHAR *fc = _tcsrchr(ProfileName, '.'); + if ( fc != NULL ) *fc = 0; + + // we get the user path where our yamn-account.book.ini is stored from mirandaboot.ini file + GetProfileDirectory(UserDirectory, SIZEOF(UserDirectory)); + + // Enumerate all the code pages available for the System Locale + EnumSystemCodePages(EnumSystemCodePagesProc, CP_INSTALLED); + CodePageNamesSupp = new _tcptable[CPLENSUPP]; + for (i = 0, k = 0; i < CPLENALL; i++) { + if (CodePageNamesAll[i].isValid){ + CodePageNamesSupp[k] = CodePageNamesAll[i]; + k++; + } } + + // Registering YAMN as protocol + PROTOCOLDESCRIPTOR pd = {0}; + pd.cbSize = PROTOCOLDESCRIPTOR_V3_SIZE; + pd.szName = YAMN_DBMODULE; + pd.type = PROTOTYPE_PROTOCOL; + CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd); + + InitializeCriticalSection(&AccountStatusCS); + InitializeCriticalSection(&FileWritingCS); + InitializeCriticalSection(&PluginRegCS); + + if (NULL == (NoWriterEV = CreateEvent(NULL, TRUE, TRUE, NULL))) + return 1; + if (NULL == (WriteToFileEV = CreateEvent(NULL, FALSE, FALSE, NULL))) + return 1; + if (NULL == (ExitEV = CreateEvent(NULL, TRUE, FALSE, NULL))) + return 1; + + PosX = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBPOSX, 0); + PosY = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBPOSY, 0); + SizeX = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBSIZEX, 800); + SizeY = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBSIZEY, 200); + + HeadPosX = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSX, 0); + HeadPosY = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSY, 0); + HeadSizeX = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEX, 690); + HeadSizeY = DBGetContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEY, 300); + HeadSplitPos = DBGetContactSettingWord(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSSPLIT, 250); + + optDateTime = DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_DBTIMEOPTIONS, optDateTime); + + // Create new window queues for broadcast messages + YAMNVar.MessageWnds = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0); + YAMNVar.NewMailAccountWnd = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0); + YAMNVar.Shutdown = FALSE; + + hCurSplitNS = LoadCursor(NULL, IDC_SIZENS); + hCurSplitWE = LoadCursor(NULL, IDC_SIZEWE); + +#ifdef YAMN_DEBUG + InitDebug(); +#endif + + CreateServiceFunctions(); + + SkinAddNewSoundEx(YAMN_NEWMAILSOUND, YAMN_DBMODULE, YAMN_NEWMAILSNDDESC); + SkinAddNewSoundEx(YAMN_CONNECTFAILSOUND, YAMN_DBMODULE, YAMN_CONNECTFAILSNDDESC); + + HookEvents(); + + LoadIcons(); + LoadPlugins(); + InitVSApi(); + + HOTKEYDESC hkd = {0}; + hkd.cbSize = sizeof(hkd); + hkd.pszService = MS_YAMN_FORCECHECK; + hkd.pszSection = YAMN_DBMODULE; + hkd.pszDescription = LPGEN("Check mail"); + hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL, VK_F11); + Hotkey_Register(&hkd); + + //Create thread that will be executed every second + if (!(SecTimer = SetTimer(NULL, 0, 1000, (TIMERPROC)TimerProc))) + return 1; + + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static void UnloadPlugins() +{ + for (int i = iDllPlugins-1;i>=0;i--) { + if (FreeLibrary(hDllPlugins[i])) { + hDllPlugins[i] = NULL; //for safety + iDllPlugins --; + } + } + if (hDllPlugins){ + free((void *)hDllPlugins); + hDllPlugins = NULL; + } +} + +extern "C" int __declspec(dllexport) Unload(void) +{ +#ifdef YAMN_DEBUG + UnInitDebug(); +#endif + DestroyCursor(hCurSplitNS); + DestroyCursor(hCurSplitWE); + + CloseHandle(NoWriterEV); + CloseHandle(WriteToFileEV); + CloseHandle(ExitEV); + + FreeVSApi(); + + DeleteCriticalSection(&AccountStatusCS); + DeleteCriticalSection(&FileWritingCS); + DeleteCriticalSection(&PluginRegCS); + + UnhookEvents(); + DestroyServiceFunctions(); + + UnloadPlugins(); + + delete [] CodePageNamesSupp; + return 0; +} diff --git a/protocols/YAMN/src/main.h b/protocols/YAMN/src/main.h new file mode 100644 index 0000000000..08d9f91fed --- /dev/null +++ b/protocols/YAMN/src/main.h @@ -0,0 +1,51 @@ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __GNUC__ + #define __try + #define __except(x) if (0) /* don't execute handler */ + #define __finally + #define _try __try + #define _except __except + #define _finally __finally +#endif + +#define YAMN_SHORTNAME "YAMN tweety" +#define YAMN_FILENAME "yamn" + + +#include "version.h" +#define YAMN_NEWMAILSNDDESC "YAMN: new mail message" +#define YAMN_CONNECTFAILSNDDESC "YAMN: connect failed" +#define YAMN_CONNECTFAILSOUND "YAMN/Sound/ConnectFail" +#define YAMN_NEWMAILSOUND "YAMN/Sound/NewMail" + +#define YAMN_DBMODULE "YAMN" +#define YAMN_DBPOSX "MailBrowserWinX" +#define YAMN_DBPOSY "MailBrowserWinY" +#define YAMN_DBSIZEX "MailBrowserWinW" +#define YAMN_DBSIZEY "MailBrowserWinH" +#define YAMN_DBMSGPOSX "MailMessageWinX" +#define YAMN_DBMSGPOSY "MailMessageWinY" +#define YAMN_DBMSGSIZEX "MailMessageWinW" +#define YAMN_DBMSGSIZEY "MailMessageWinH" +#define YAMN_DBMSGPOSSPLIT "MailMessageSplitY" +#define YAMN_TTBFCHECK "ForceCheckTTB" +#define YAMN_SHOWMAINMENU "ShowMainMenu" +#define YAMN_CLOSEDELETE "CloseOnDelete" +#define YAMN_SHOWASPROTO "ShowAsProtcol" +#define YAMN_DBTIMEOPTIONS "MailBrowserTimeOpts" + +#define YAMN_DEFAULTHK MAKEWORD(VK_F11,MOD_CONTROL) + +#define SHOWDATELONG 0x01 +#define SHOWDATENOTODAY 0x02 +#define SHOWDATENOSECONDS 0x04 + +extern unsigned char optDateTime; + +// Loading Icon and checking for icolib +void LoadIcons(); + +#endif + diff --git a/protocols/YAMN/src/proto/md5.c b/protocols/YAMN/src/proto/md5.c new file mode 100644 index 0000000000..280fcdeaae --- /dev/null +++ b/protocols/YAMN/src/proto/md5.c @@ -0,0 +1,259 @@ +/* + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * MD5Context structure, pass it to MD5Init, call MD5Update as + * needed on buffers full of bytes, and then call MD5Final, which + * will fill a supplied 16-byte array with the digest. + */ +//#include /* for memcpy() */ +#if defined(_WIN64) + typedef unsigned __int64 size_t; +#else + typedef unsigned int size_t; +#endif +void * __cdecl memcpy(void *, const void *, size_t); +void * __cdecl memset(void *, int, size_t); +#include "md5.h" + +#ifndef HIGHFIRST +#define byteReverse(buf, len) /* Nothing */ +#else +void byteReverse(unsigned char *buf, unsigned longs); + +#ifndef ASM_MD5 +/* + * Note: this code is harmless on little-endian machines. + */ +void byteReverse(unsigned char *buf, unsigned longs) +{ + uint32 t; + do { + t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | + ((unsigned) buf[1] << 8 | buf[0]); + *(uint32 *) buf = t; + buf += 4; + } while (--longs); +} +#endif +#endif + +/* + * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious + * initialization constants. + */ +void MD5Init(struct MD5Context *ctx) +{ + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; + + ctx->bits[0] = 0; + ctx->bits[1] = 0; +} + +/* + * Update context to reflect the concatenation of another buffer full + * of bytes. + */ +void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) +{ + uint32 t; + + /* Update bitcount */ + + t = ctx->bits[0]; + if ((ctx->bits[0] = t + ((uint32) len << 3)) < t) + ctx->bits[1]++; /* Carry from low to high */ + ctx->bits[1] += len >> 29; + + t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ + + /* Handle any leading odd-sized chunks */ + + if (t) { + unsigned char *p = (unsigned char *) ctx->in + t; + + t = 64 - t; + if (len < t) { + memcpy(p, buf, len); + return; + } + memcpy(p, buf, t); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (uint32 *) ctx->in); + buf += t; + len -= t; + } + /* Process data in 64-byte chunks */ + + while (len >= 64) { + memcpy(ctx->in, buf, 64); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (uint32 *) ctx->in); + buf += 64; + len -= 64; + } + + /* Handle any remaining bytes of data. */ + + memcpy(ctx->in, buf, len); +} + +/* + * Final wrapup - pad to 64-byte boundary with the bit pattern + * 1 0* (64-bit count of bits processed, MSB-first) + */ +void MD5Final(unsigned char digest[16], struct MD5Context *ctx) +{ + unsigned count; + unsigned char *p; + + /* Compute number of bytes mod 64 */ + count = (ctx->bits[0] >> 3) & 0x3F; + + /* Set the first char of padding to 0x80. This is safe since there is + always at least one byte free */ + p = ctx->in + count; + *p++ = 0x80; + + /* Bytes of padding needed to make 64 bytes */ + count = 64 - 1 - count; + + /* Pad out to 56 mod 64 */ + if (count < 8) { + /* Two lots of padding: Pad the first block to 64 bytes */ + memset(p, 0, count); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (uint32 *) ctx->in); + + /* Now fill the next block with 56 bytes */ + memset(ctx->in, 0, 56); + } else { + /* Pad block to 56 bytes */ + memset(p, 0, count - 8); + } + byteReverse(ctx->in, 14); + + /* Append length in bits and transform */ + ((uint32 *) ctx->in)[14] = ctx->bits[0]; + ((uint32 *) ctx->in)[15] = ctx->bits[1]; + + MD5Transform(ctx->buf, (uint32 *) ctx->in); + byteReverse((unsigned char *) ctx->buf, 4); + memcpy(digest, ctx->buf, 16); + memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ +} + +#ifndef ASM_MD5 + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. MD5Update blocks + * the data and converts bytes into longwords for this routine. + */ +void MD5Transform(uint32 buf[4], uint32 const in[16]) +{ + register uint32 a, b, c, d; + + a = buf[0]; + b = buf[1]; + c = buf[2]; + d = buf[3]; + + MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; +} + +#endif diff --git a/protocols/YAMN/src/proto/md5.h b/protocols/YAMN/src/proto/md5.h new file mode 100644 index 0000000000..e264f686db --- /dev/null +++ b/protocols/YAMN/src/proto/md5.h @@ -0,0 +1,27 @@ +#ifndef MD5_H +#define MD5_H + +#ifdef __alpha +typedef unsigned int uint32; +#else +typedef unsigned long uint32; +#endif + +struct MD5Context { + uint32 buf[4]; + uint32 bits[2]; + unsigned char in[64]; +}; + +void MD5Init(struct MD5Context *context); +void MD5Update(struct MD5Context *context, unsigned char const *buf, + unsigned len); +void MD5Final(unsigned char digest[16], struct MD5Context *context); +void MD5Transform(uint32 buf[4], uint32 const in[16]); + +/* + * This is needed to make RSAREF happy on some MS-DOS compilers. + */ +typedef struct MD5Context MD5_CTX; + +#endif /* !MD5_H */ diff --git a/protocols/YAMN/src/proto/netclient.h b/protocols/YAMN/src/proto/netclient.h new file mode 100644 index 0000000000..2414dbdef1 --- /dev/null +++ b/protocols/YAMN/src/proto/netclient.h @@ -0,0 +1,22 @@ +#ifndef __CLIENT_H +#define __CLIENT_H + +class CNetClient +{ +public: + CNetClient(): Stopped(FALSE) {} + virtual void Connect(const char* servername,const int port)=0; + virtual void Send(const char *query)=0; + virtual char* Recv(char *buf=NULL,int buflen=65536)=0; + virtual void Disconnect()=0; + virtual BOOL Connected()=0; + virtual void SSLify()=0; + + BOOL Stopped; + int Rcv; + DWORD NetworkError; + DWORD SystemError; + BOOL ifTLSed; +}; + +#endif diff --git a/protocols/YAMN/src/proto/netlib.cpp b/protocols/YAMN/src/proto/netlib.cpp new file mode 100644 index 0000000000..b7c1864ffa --- /dev/null +++ b/protocols/YAMN/src/proto/netlib.cpp @@ -0,0 +1,271 @@ +/* + * This code implements communication based on Miranda netlib library + * + * (c) majvan 2002-2004 + */ + +#include "..\yamn.h" +#include "m_netlib.h" +#include "netlib.h" + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +BOOL SSLLoaded=FALSE; +HANDLE hNetlibUser=NULL; + +extern PVOID TLSCtx; +extern PVOID SSLCtx; + +void __stdcall SSL_DebugLog(const char *fmt, ...) +{ + char str[ 4096 ]; + va_list vararg; + + va_start( vararg, fmt ); + int tBytes = _vsnprintf( str, sizeof(str)-1, fmt, vararg ); + if ( tBytes == 0 ) + return; + + if ( tBytes > 0 ) + str[ tBytes ] = 0; + else + str[ sizeof(str)-1 ] = 0; + + CallService(MS_NETLIB_LOG, (WPARAM)hNetlibUser, (LPARAM)str); + va_end( vararg ); +} + +HANDLE RegisterNLClient(const char *name) +{ + static NETLIBUSER nlu={0}; + char desc[128]; + + sprintf(desc, Translate("%s connection"),name); + +#ifdef DEBUG_COMM + DebugLog(CommFile,""); +#endif + nlu.cbSize = sizeof(nlu); + nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS; + nlu.szDescriptiveName=desc; + nlu.szSettingsModule=(char *)name; + hNetlibUser=(HANDLE)CallService(MS_NETLIB_REGISTERUSER,0,(LPARAM)&nlu); + +#ifdef DEBUG_COMM + if (NULL==hNetlibUser) + DebugLog(CommFile,"\n"); + else + DebugLog(CommFile,"\n"); +#endif + return hNetlibUser; +} + +//Move connection to SSL +void CNLClient::SSLify() throw(DWORD){ +#ifdef DEBUG_COMM + SSL_DebugLog("Staring SSL..."); +#endif + int socket = CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConnection, 0); + if (socket != INVALID_SOCKET) + { +#ifdef DEBUG_COMM + SSL_DebugLog("Staring netlib core SSL"); +#endif + if (CallService(MS_NETLIB_STARTSSL, (WPARAM)hConnection, 0)) + { +#ifdef DEBUG_COMM + SSL_DebugLog("Netlib core SSL started"); +#endif + isTLSed = true; + SSLLoaded = TRUE; + return; + } + } + + //ssl could not be created + throw NetworkError = (DWORD)ESSL_CREATESSL; +} + +//Connects to the server through the sock +//if not success, exception is throwed +void CNLClient::Connect(const char* servername,const int port) throw(DWORD) +{ + NETLIBOPENCONNECTION nloc; + + NetworkError=SystemError=0; + isTLSed = false; + +#ifdef DEBUG_COMM + DebugLog(CommFile,"\n"); +#endif + try + { + nloc.cbSize=sizeof(NETLIBOPENCONNECTION); + nloc.szHost=servername; + nloc.wPort=port; + nloc.flags=0; + if (NULL==(hConnection=(HANDLE)CallService(MS_NETLIB_OPENCONNECTION,(WPARAM)hNetlibUser,(LPARAM)&nloc))) + { + SystemError=WSAGetLastError(); + throw NetworkError=(DWORD)ENL_CONNECT; + } +#ifdef DEBUG_COMM + DebugLog(CommFile,"\n"); +#endif + return; + } + catch(...) + { +#ifdef DEBUG_COMM + DebugLog(CommFile,"\n"); +#endif + throw; + } +} + +//Performs a simple query +// query- command to send +int CNLClient::LocalNetlib_Send(HANDLE hConn,const char *buf,int len,int flags) { + if (isTLSed) + { +#ifdef DEBUG_COMM + SSL_DebugLog("SSL send: %s", buf); +#endif + } + + NETLIBBUFFER nlb={(char*)buf,len,flags}; + return CallService(MS_NETLIB_SEND,(WPARAM)hConn,(LPARAM)&nlb); +} + +void CNLClient::Send(const char *query) throw(DWORD) +{ + unsigned int Sent; + + if (NULL==query) + return; + if (hConnection==NULL) + return; +#ifdef DEBUG_COMM + DebugLog(CommFile,"%s",query); +#endif + try + { + if ((SOCKET_ERROR==(Sent=LocalNetlib_Send(hConnection,query,(int)strlen(query),MSG_DUMPASTEXT))) || Sent!=(unsigned int)strlen(query)) + { + SystemError=WSAGetLastError(); + throw NetworkError=(DWORD)ENL_SEND; + } +#ifdef DEBUG_COMM + DebugLog(CommFile,"\n"); +#endif + } + catch(...) + { +#ifdef DEBUG_COMM + DebugLog(CommFile,"\n"); +#endif + throw; + } +} + +//Reads data from socket +// buf- buffer where to store max. buflen of received characters +// if buf is NULL, creates buffer of buflen size +// buf is NULL by default +//You need free() returned buffer, which can be allocated in this function +//if not success, exception is throwed + +int CNLClient::LocalNetlib_Recv(HANDLE hConn,char *buf,int len,int flags) { + NETLIBBUFFER nlb={buf,len,flags}; + int iReturn = CallService(MS_NETLIB_RECV,(WPARAM)hConn,(LPARAM)&nlb); + if (isTLSed) + { +#ifdef DEBUG_COMM + SSL_DebugLog("SSL recv: %s", buf); +#endif + } + + return iReturn; +} + +char* CNLClient::Recv(char *buf,int buflen) throw(DWORD) +{ +#ifdef DEBUG_COMM + DebugLog(CommFile,""); +#endif + try + { + if (buf==NULL) + buf=(char *)malloc(sizeof(char)*(buflen+1)); + if (buf==NULL) + throw NetworkError=(DWORD)ENL_RECVALLOC; + + if (!isTLSed) + { + NETLIBSELECT nls; + memset(&nls, 0, sizeof(NETLIBSELECT)); + nls.cbSize = sizeof(NETLIBSELECT); + nls.dwTimeout = 60000; + nls.hReadConns[0] = hConnection; + switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM) &nls)) + { + case SOCKET_ERROR: + free(buf); + SystemError=WSAGetLastError(); + throw NetworkError = (DWORD) ENL_RECV; + case 0: // time out! + free(buf); + throw NetworkError = (DWORD) ENL_TIMEOUT; + } + } + + ZeroMemory(buf,buflen); + if (SOCKET_ERROR==(Rcv=LocalNetlib_Recv(hConnection,buf,buflen,MSG_DUMPASTEXT))) + { + free(buf); + SystemError=WSAGetLastError(); + throw NetworkError=(DWORD)ENL_RECV; + } + if (!Rcv) + { + free(buf); + SystemError=WSAGetLastError(); + throw NetworkError=(DWORD)ENL_RECV; + } +#ifdef DEBUG_COMM + *(buf+Rcv)=0; //end the buffer to write it to file + DebugLog(CommFile,"%s",buf); + DebugLog(CommFile,"\n"); +#endif + return(buf); + } + catch(...) + { +#ifdef DEBUG_COMM + DebugLog(CommFile,"\n"); +#endif + throw; + } +} + +//Closes netlib connection +void CNLClient::Disconnect() +{ + Netlib_CloseHandle(hConnection); + hConnection=(HANDLE)NULL; +} + +//Uninitializes netlib library +void UnregisterNLClient() +{ +#ifdef DEBUG_COMM + DebugLog(CommFile,""); +#endif + + Netlib_CloseHandle(hNetlibUser); + hNetlibUser=(HANDLE)NULL; +#ifdef DEBUG_COMM + DebugLog(CommFile,"\n"); +#endif +} diff --git a/protocols/YAMN/src/proto/netlib.h b/protocols/YAMN/src/proto/netlib.h new file mode 100644 index 0000000000..90ad3613a5 --- /dev/null +++ b/protocols/YAMN/src/proto/netlib.h @@ -0,0 +1,55 @@ +#ifndef __NETLIB_H +#define __NETLIB_H + +#include "netclient.h" + +#pragma warning( disable : 4290 ) + +class CNLClient: public CNetClient +{ +public: + CNLClient(): hConnection(NULL) {} + void Connect(const char* servername,const int port) throw(DWORD); + void Send(const char *query) throw(DWORD); + char* Recv(char *buf=NULL,int buflen=65536) throw(DWORD); + void Disconnect(); + void SSLify()throw(DWORD); + + inline BOOL Connected() {return hConnection!=NULL;} + +protected: + HANDLE hConnection; + BOOL isTLSed; + int LocalNetlib_Send(HANDLE hConn,const char *buf,int len,int flags); + int LocalNetlib_Recv(HANDLE hConn,char *buf,int len,int flags); +}; + +void SSL_DebugLog(const char *fmt, ...); + +enum +{ + ENL_WINSOCKINIT=1, //error initializing socket //only wsock + ENL_GETHOSTBYNAME, //DNS error //only wsock + ENL_CREATESOCKET, //error creating socket //only wsock + ENL_CONNECT, //cannot connect to server + ENL_SEND, //cannot send data + ENL_RECV, //cannot receive data + ENL_RECVALLOC, //cannot allocate memory for received data + ENL_TIMEOUT, //timed out during recv +}; + +enum +{ + ESSL_NOTLOADED=1, //OpenSSL is not loaded + ESSL_WINSOCKINIT, //WinSock 2.0 init failed + ESSL_GETHOSTBYNAME, //DNS error + ESSL_CREATESOCKET, //error creating socket + ESSL_SOCKETCONNECT, //error connecting with socket + ESSL_CREATESSL, //error creating SSL session structure + ESSL_SETSOCKET, //error connect socket with SSL session for bidirect I/O space + ESSL_CONNECT, //cannot connect to server + ESSL_SEND, //cannot send data + ESSL_RECV, //cannot receive data + ESSL_RECVALLOC, //cannot allocate memory for received data +}; +#endif diff --git a/protocols/YAMN/src/proto/pop3/pop3.cpp b/protocols/YAMN/src/proto/pop3/pop3.cpp new file mode 100644 index 0000000000..05e85d7156 --- /dev/null +++ b/protocols/YAMN/src/proto/pop3/pop3.cpp @@ -0,0 +1,370 @@ +/* + * This code implements basics of POP3 protocol + * + * (c) majvan 2002-2004 + */ +/* This was made from the libspopc project + * copyright c 2002 Benoit Rouits + * released under the terms of GNU LGPL + * (GNU Lesser General Public Licence). + * libspopc offers simple API for a pop3 client (MTA). + * See RFC 1725 for pop3 specifications. + * more information on http://brouits.free.fr/libspopc/ + */ +/* + * This file is not original and is changed by majvan + * for mail checker purpose. Please see original web page to + * obtain the original. I rewrote it in C++, but good ideas were, + * I think, unchanged. + * + * Note that this file was not designed to work under Unix. It's + * needed to add Unix-specific features. I was interested only in + * Windows for my project. majvan + * + */ + +#pragma warning( disable : 4290 ) + +#include "..\..\yamn.h" +#include "pop3.h" + +extern "C" { +#include "../md5.h" +} + +extern void __stdcall SSL_DebugLog( const char *fmt, ... ); + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +//Connects to the server through the netlib +//if not success, exception is throwed +//returns welcome string returned by server +//sets AckFlag +char *CPop3Client::Connect(const char* servername,const int port,BOOL UseSSL, BOOL NoTLS) +{ + char *temp = 0; + if (Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + if (NetClient!=NULL) + delete NetClient; + SSL=UseSSL; + NetClient=new CNLClient; + +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"Connect:servername: %s port:%d\n",servername,port); +#endif + POP3Error=EPOP3_CONNECT; + NetClient->Connect(servername,port); + POP3Error=0; + + if (SSL) + { + try { NetClient->SSLify(); } + catch (...) + { + NetClient->Disconnect(); + return NULL; + } + } + + temp = RecvRest(NetClient->Recv(),POP3_SEARCHACK); + extern BOOL SSLLoaded; + if (!NoTLS & !(SSL)) { + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + NetClient->Send("STLS\r\n"); + free(temp); + temp=RecvRest(NetClient->Recv(),POP3_SEARCHACK); + if (AckFlag==POP3_FOK){ // Ok, we are going to tls + try { + NetClient->SSLify(); + } catch (...) { + NetClient->Disconnect(); + return NULL; + } +// temp = RecvRest(NetClient->Recv(),POP3_SEARCHACK); + } + } +// SSL_DebugLog("Received: %s",temp); + return temp; +} + +//Receives data to the end of packet +// prev- previous data read (appends to this string next received data) +// mode- mode of packet. +// Packet can end with ack state (+OK or -ERR): set mode to POP3_SEARCHACK +// If packet ends with '.' (end of string), set mode to POP3_SEARCHDOT +// size- received data are stored to memory, but if length of data is more than allocated memory, function allocates +// new memory. New allocated memory has allocated size more bytes +// This value can be selectable: if you think it is better to reallocate by 1kB size, select size to 1024, +// default is 128. You do not need to use this parameter +char* CPop3Client::RecvRest(char* prev,int mode,int size) +{ + int SizeRead=0; + int SizeLeft=size-NetClient->Rcv; + int RcvAll=NetClient->Rcv; + char *LastString,*PrevString=prev; + + AckFlag=0; + + while(((mode==POP3_SEARCHDOT) && !SearchFromEnd(PrevString+RcvAll-1,RcvAll-3,POP3_SEARCHDOT) && !SearchFromStart(PrevString,2,POP3_SEARCHERR)) || //we are looking for dot or -err phrase + ((mode==POP3_SEARCHACK) && (!SearchFromStart(PrevString,RcvAll-3,mode) || !((RcvAll>3) && SearchFromEnd(PrevString+RcvAll-1,1,POP3_SEARCHNL))))) //we are looking for +ok or -err phrase ended with newline + { //if not found + if (NetClient->Stopped) //check if we can work with this POP3 client session + { + if (PrevString!=NULL) + free(PrevString); + throw POP3Error=(DWORD)EPOP3_STOPPED; + } + if (SizeLeft==0) //if block is full + { + SizeRead+=size; + SizeLeft=size; + LastString=NetClient->Recv(NULL,SizeLeft); + PrevString=(char *)realloc(PrevString,sizeof(char)*(SizeRead+size)); + if (PrevString==NULL) + throw POP3Error=(DWORD)EPOP3_RESTALLOC; + memcpy(PrevString+SizeRead,LastString,size); + free(LastString); + } + else + NetClient->Recv(PrevString+RcvAll,SizeLeft); //to Rcv stores received bytes + SizeLeft=SizeLeft-NetClient->Rcv; + RcvAll+=NetClient->Rcv; +// printf("[Read: %s]\n",PrevString); + } + NetClient->Rcv=RcvAll; //at the end, store the number of all bytes, no the number of last received bytes + return PrevString; +} + +// CPop3Client::SearchFromEnd +// returns 1 if substring DOTLINE or ENDLINE found from end in bs bytes +// if you need to add condition for mode, insert it into switch statement +BOOL CPop3Client::SearchFromEnd(char *end,int bs,int mode) +{ + while(bs>=0) + { + switch(mode) + { + case POP3_SEARCHDOT: + if (DOTLINE(end)) + return 1; + break; + case POP3_SEARCHNL: + if (ENDLINE(end)) + return 1; + break; + } + end--; + bs--; + } + return 0; +} + +//Finds for a occurence of some pattern in string +// returns 1 if substring OKLINE, ERRLINE or any of them found from start in bs bytes +//call only this function to retrieve ack status (+OK or -ERR), because it sets flag AckFlag +//if you need to add condition for mode, insert it into switch statement +BOOL CPop3Client::SearchFromStart(char *start,int bs,int mode) +{ + while(bs>=0) + { + switch(mode) + { + case POP3_SEARCHOK: + if (OKLINE(start)) + { + AckFlag=POP3_FOK; + return 1; + } + break; + case POP3_SEARCHERR: + if (ERRLINE(start)) + { + AckFlag=POP3_FERR; + return 1; + } + break; + case POP3_SEARCHACK: + if (ACKLINE(start)) + { + OKLINE(start) ? AckFlag=POP3_FOK : AckFlag=POP3_FERR; + return 1; + } + break; + } + start++; + bs--; + } + return 0; +} + +//Performs "USER" pop query and returns server response +//sets AckFlag +char* CPop3Client::User(char* name) +{ + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + char query[128]; + char *Result; + + sprintf(query,"USER %s\r\n",name); + NetClient->Send(query); + Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); + if (AckFlag==POP3_FERR) + throw POP3Error=(DWORD)EPOP3_BADUSER; + POP3Error=0; + return Result; +} + +//Performs "PASS" pop query and returns server response +//sets AckFlag +char* CPop3Client::Pass(char* pw) +{ + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + char query[128]; + char *Result; + + sprintf(query,"PASS %s\r\n",pw); + NetClient->Send(query); + Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); + if (AckFlag==POP3_FERR) + throw POP3Error=(DWORD)EPOP3_BADPASS; + return Result; +} + +//Performs "APOP" pop query and returns server response +//sets AckFlag +char* CPop3Client::APOP(char* name, char* pw, char* timestamp) +{ + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + char query[512]; + char *Result; + unsigned char digest[16]; + char hexdigest[40]; + + if (timestamp==NULL) + throw POP3Error=(DWORD)EPOP3_APOP; + MD5Context ctx; + MD5Init(&ctx); + MD5Update(&ctx,(const unsigned char *)timestamp,(unsigned int)strlen(timestamp)); + MD5Update(&ctx,(const unsigned char *)pw,(unsigned int)strlen(pw)); + MD5Final(digest,&ctx); + hexdigest[0]='\0'; + for (int i=0; i<16; i++) { + char tmp[4]; + sprintf(tmp, "%02x", digest[i]); + strcat(hexdigest, tmp); + } + sprintf(query,"APOP %s %s\r\n",name, hexdigest); + NetClient->Send(query); + Result=RecvRest(NetClient->Recv(),POP3_SEARCHACK); + if (AckFlag==POP3_FERR) + throw POP3Error=(DWORD)EPOP3_BADUSER; + return Result; +} + +//Performs "QUIT" pop query and returns server response +//sets AckFlag +char* CPop3Client::Quit() +{ + char query[]="QUIT\r\n"; + + NetClient->Send(query); + return RecvRest(NetClient->Recv(),POP3_SEARCHACK); +} + +//Performs "STAT" pop query and returns server response +//sets AckFlag +char* CPop3Client::Stat() +{ + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + char query[]="STAT\r\n"; + + NetClient->Send(query); + return RecvRest(NetClient->Recv(),POP3_SEARCHACK); +} + +//Performs "LIST" pop query and returns server response +//sets AckFlag +char* CPop3Client::List() +{ + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + char query[]="LIST\r\n"; + + NetClient->Send(query); + return RecvRest(NetClient->Recv(),POP3_SEARCHDOT); +} + +//Performs "TOP" pop query and returns server response +//sets AckFlag +char* CPop3Client::Top(int nr, int lines) +{ + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + char query[128]; + + sprintf(query,"TOP %d %d\r\n",nr,lines); + NetClient->Send(query); + return RecvRest(NetClient->Recv(),POP3_SEARCHDOT); +} + +//Performs "UIDL" pop query and returns server response +//sets AckFlag +char* CPop3Client::Uidl(int nr) +{ + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + char query[128]; + + if (nr) + { + sprintf(query,"UIDL %d\r\n",nr); + NetClient->Send(query); + return RecvRest(NetClient->Recv(),POP3_SEARCHACK); + } + sprintf(query,"UIDL\r\n"); + NetClient->Send(query); + return RecvRest(NetClient->Recv(),POP3_SEARCHDOT); +} + +//Performs "DELE" pop query and returns server response +//sets AckFlag +char* CPop3Client::Dele(int nr) +{ + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + char query[128]; + + sprintf(query,"DELE %d\r\n",nr); + NetClient->Send(query); + return RecvRest(NetClient->Recv(),POP3_SEARCHACK); +} +//Performs "RETR" pop query and returns server response +//sets AckFlag +char* CPop3Client::Retr(int nr) +{ + if (NetClient->Stopped) //check if we can work with this POP3 client session + throw POP3Error=(DWORD)EPOP3_STOPPED; + + char query[128]; + + sprintf(query,"RETR %d\r\n",nr); + NetClient->Send(query); + RecvRest(NetClient->Recv(),POP3_SEARCHACK); + return NetClient->Recv(); +} \ No newline at end of file diff --git a/protocols/YAMN/src/proto/pop3/pop3.h b/protocols/YAMN/src/proto/pop3/pop3.h new file mode 100644 index 0000000000..1f7f2ea737 --- /dev/null +++ b/protocols/YAMN/src/proto/pop3/pop3.h @@ -0,0 +1,66 @@ +#ifndef __POP3_H +#define __POP3_H + +#include "../../debug.h" +#include "../netlib.h" //NetLib client + +#define DOTLINE(s) ((((s)[-2]=='\r') || ((s)[-2]=='\n')) && ((s)[-1]=='.') && (((s)[0]=='\r') || ((s)[0]=='\n') || ((s)[0]=='\0'))) // be careful, it's different to ESR's pop3.c ;-) +#define ENDLINE(s) (((s)[0]=='\r') || ((s)[0]=='\n')) //endline +#define OKLINE(s) (((s)[0]=='+') && (((s)[1]=='o') || ((s)[1]=='O')) && (((s)[2]=='k') || ((s)[2]=='K'))) // +OK +#define ERRLINE(s) (((s)[0]=='-') && (((s)[1]=='e') || ((s)[1]=='E')) && (((s)[2]=='r') || ((s)[2]=='R')) && (((s)[3]=='r') || ((s)[3]=='R'))) // -ERR +#define ACKLINE(s) (OKLINE(s) || ERRLINE(s)) + +#define POP3_SEARCHDOT 1 +#define POP3_SEARCHACK 2 +#define POP3_SEARCHOK 3 +#define POP3_SEARCHERR 4 +#define POP3_SEARCHNL 5 + +#define POP3_FOK 1 +#define POP3_FERR 2 + +class CPop3Client +{ +public: + CPop3Client(): NetClient(NULL), Stopped(FALSE) {} + ~CPop3Client() {if (NetClient!=NULL) delete NetClient;} + + char* Connect(const char* servername,const int port=110,BOOL UseSSL=FALSE, BOOL NoTLS=FALSE); + char* RecvRest(char* prev,int mode,int size=65536); + char* User(char* name); + char* Pass(char* pw); + char* APOP(char* name, char* pw, char* timestamp); + char* Quit(); + char* Stat(); + char* List(); + char* Top(int nr, int lines=0); + char* Uidl(int nr=0); + char* Dele(int nr); + char* Retr(int nr); + + unsigned char AckFlag; + BOOL SSL; + BOOL Stopped; + + DWORD POP3Error; + class CNetClient *NetClient; //here the network layout is defined (TCP or SSL+TCP etc.) +private: + BOOL SearchFromEnd(char *end,int bs,int mode); + BOOL SearchFromStart(char *end,int bs,int mode); +}; + +enum +{ + EPOP3_QUEUEALLOC=1, //memory allocation + EPOP3_STOPPED, //stop account + EPOP3_CONNECT, //cannot connect to server + EPOP3_RESTALLOC, //cannot allocate memory for received data + EPOP3_BADUSER, //cannot login because USER command failed + EPOP3_BADPASS, //cannot login because PASS command failed + EPOP3_APOP, //server does not send timestamp for APOP auth + EPOP3_STAT, + EPOP3_LIST, + EPOP3_UIDL, +}; + +#endif diff --git a/protocols/YAMN/src/proto/pop3/pop3comm.cpp b/protocols/YAMN/src/proto/pop3/pop3comm.cpp new file mode 100644 index 0000000000..954f1b5860 --- /dev/null +++ b/protocols/YAMN/src/proto/pop3/pop3comm.cpp @@ -0,0 +1,1563 @@ +/* + * This code implements POP3 server checking for new mail and so on. + * There's function SynchroPOP3 in this file- for checking and synchronising POP3 account + * and DeleteMailsPOP3- for deleting mails from POP3 server + * + * Note this file acts as main file for internal plugin. + * + * (c) majvan 2002-2004 + * 18/08 +*/ + + +#pragma warning( disable : 4290 ) +#include "../../yamn.h" +#include "../../main.h" +#include "pop3.h" +#include "pop3comm.h" //all we need for POP3 account (POP3 account= YAMN account + some more POP3 specified members) +#include //socket thorugh proxy functions + +#define ERRORSTR_MAXLEN 1024 //in wide-chars + +//-------------------------------------------------------------------------------------------------- + +HANDLE hNetLib = NULL; +PSCOUNTER CPOP3Account::AccountWriterSO = NULL; + +//Creates new CPOP3Account structure +HACCOUNT WINAPI CreatePOP3Account(HYAMNPROTOPLUGIN Plugin,DWORD CAccountVersion); + +//Deletes CPOP3Account structure +void WINAPI DeletePOP3Account(HACCOUNT Which); + +//Sets stop flag to account +void WINAPI StopPOP3Account(HACCOUNT Which); + +//Function registers standard functions for YAMN +int RegisterPOP3Plugin(WPARAM,LPARAM); + +//Unloads all variables created on heap (delete[]) +DWORD WINAPI UnLoadPOP3(void *); + +//Function writes POP3 accounts using YAMN exported functions +DWORD WINAPI WritePOP3Accounts(); + +//Function stores plugin's data for account to file +DWORD WINAPI WritePOP3Options(HANDLE,HACCOUNT); + +//Function reads plugin's data for account from file +DWORD WINAPI ReadPOP3Options(HACCOUNT,char **,char *); + +//Creates new mail for an account +HYAMNMAIL WINAPI CreatePOP3Mail(HACCOUNT Account,DWORD CMimeMailVersion); + +//Function does all needed work when connection failed or any error occured +//Creates structure containing error code, closes internet session, runs "bad connect" function +static void PostErrorProc(HPOP3ACCOUNT ActualAccount,void *ParamToBadConnect,DWORD POP3PluginParam,BOOL UseSSL); + +//Checks POP3 account and stores all info to account. It deletes old mails=> synchro +// WhichTemp- pointer to strucure containing needed information +DWORD WINAPI SynchroPOP3(struct CheckParam *WhichTemp); + +//Deletes mails from POP3 server +// WhichTemp- structure containing needed information (queued messages to delete) +//Function deletes from memory queue in WhichTemp structure +DWORD WINAPI DeleteMailsPOP3(struct DeleteParam *WhichTemp); + +//Function makes readable message about error. It sends it back to YAMN, so YAMN then +//can show it to the message window +TCHAR* WINAPI GetErrorString(DWORD Code); + +//Function deletes string allocated in GetErrorString +void WINAPI DeleteErrorString(LPVOID String); + +//Extracts info from result of POP3's STAT command +// stream- source string +// len- length of source string +// mboxsize- adreess to integer, that receives size of mailbox +// mails- adreess to integer, that receives number of mails +void ExtractStat(char *stream,int len,int *mboxsize,int *mails); + +//Extracts mail ID on mailbox +// stream- source string +// len- length of source string +// queue- address of first message, where first ID will be stored +void ExtractUIDL(char *stream,int len,HYAMNMAIL queue); + +//Extracts mail size on mailbox +// stream- source string +// len- length of source string +// queue- address of first message, where size of message #1 will be stored +void ExtractList(char *stream,int len,HYAMNMAIL queue); + +void ExtractMail(char *stream,int len,HYAMNMAIL queue); + +YAMNExportedFcns *pYAMNFcn = NULL; +MailExportedFcns *pYAMNMailFcn = NULL; + +YAMN_PROTOIMPORTFCN POP3ProtocolFunctions = +{ + CreatePOP3Account, + DeletePOP3Account, + StopPOP3Account, + WritePOP3Options, + ReadPOP3Options, + SynchroPOP3, + SynchroPOP3, + SynchroPOP3, + DeleteMailsPOP3, + GetErrorString, + NULL, + DeleteErrorString, + WritePOP3Accounts, + NULL, + UnLoadPOP3, +}; + +YAMN_MAILIMPORTFCN POP3MailFunctions = +{ + CreatePOP3Mail, + NULL, + NULL, + NULL, +}; + +PYAMN_VARIABLES pYAMNVar = NULL; +HYAMNPROTOPLUGIN POP3Plugin = NULL; + +YAMN_PROTOREGISTRATION POP3ProtocolRegistration = +{ + "POP3 protocol (internal)", + YAMN_VERSION_C, + "© 2002-2004 majvan | 2005-2007 tweety, yb", + "Mail notifier and browser for Miranda NG. Included POP3 protocol.", + "francois.mean@skynet.be", + "http://miranda-ng.org/", +}; + +static TCHAR *FileName = NULL; + +HANDLE RegisterNLClient(const char *name); + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +CPOP3Account::CPOP3Account() +{ +//NOTE! This constructor constructs CAccount structure. If your plugin is not internal, +//you will need these constructors. All you need is in Account.cpp. Just copy to your source code +//constructor and destructor of CAccount. + UseInternetFree=CreateEvent(NULL,FALSE,TRUE,NULL); + InternetQueries=new SCOUNTER; + AbilityFlags=YAMN_ACC_BROWSE | YAMN_ACC_POPUP; + + SetAccountStatus((HACCOUNT)this,TranslateT("Disconnected")); +} + +CPOP3Account::~CPOP3Account() +{ + CloseHandle(UseInternetFree); + if (InternetQueries!=NULL) + delete InternetQueries; +} + +HACCOUNT WINAPI CreatePOP3Account(HYAMNPROTOPLUGIN Plugin,DWORD CAccountVersion) +{ +//First, we should check whether CAccountVersion matches. +//But this is internal plugin, so YAMN's CAccount structure and our CAccount structure are +//the same, so we do not need to test version. Otherwise, if CAccount version does not match +//in your plugin, you should return NULL, like this: +// if (CAccountVersion!=YAMN_ACCOUNTVERSION) return NULL; + +//Now it is needed to construct our POP3 account and return its handle + return (HACCOUNT)new struct CPOP3Account(); +} + +void WINAPI DeletePOP3Account(HACCOUNT Which) +{ + delete (HPOP3ACCOUNT)Which; +} + +void WINAPI StopPOP3Account(HACCOUNT Which) +{ + ((HPOP3ACCOUNT)Which)->Client.Stopped=TRUE; + if (((HPOP3ACCOUNT)Which)->Client.NetClient!=NULL) //we should inform also network client. Usefull only when network client implements this feature + ((HPOP3ACCOUNT)Which)->Client.NetClient->Stopped=TRUE; +} + +//This function is like main function for POP3 internal protocol +int RegisterPOP3Plugin(WPARAM,LPARAM) +{ + + //Get YAMN variables we can use + if (NULL==(pYAMNVar=(PYAMN_VARIABLES)CallService(MS_YAMN_GETVARIABLES,(WPARAM)YAMN_VARIABLESVERSION,(LPARAM)0))) + return 0; + + //We have to get pointers to YAMN exported functions: allocate structure and fill it + if (NULL==(pYAMNFcn=new struct YAMNExportedFcns)) + {UnLoadPOP3(0); return 0;} + + //Register new pop3 user in netlib + if (NULL==(hNetLib=RegisterNLClient("YAMN-POP3"))) + {UnLoadPOP3(0); return 0;} + + pYAMNFcn->SetProtocolPluginFcnImportFcn=(YAMN_SETPROTOCOLPLUGINFCNIMPORTFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SETPROTOCOLPLUGINFCNIMPORTID,(LPARAM)0); + pYAMNFcn->WaitToWriteFcn=(YAMN_WAITTOWRITEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_WAITTOWRITEID,(LPARAM)0); + pYAMNFcn->WriteDoneFcn=(YAMN_WRITEDONEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_WRITEDONEID,(LPARAM)0); + pYAMNFcn->WaitToReadFcn=(YAMN_WAITTOREADFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_WAITTOREADID,(LPARAM)0); + pYAMNFcn->ReadDoneFcn=(YAMN_READDONEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_READDONEID,(LPARAM)0); + pYAMNFcn->SCGetNumberFcn=(YAMN_SCMANAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SCGETNUMBERID,(LPARAM)0); + pYAMNFcn->SCIncFcn=(YAMN_SCMANAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SCINCID,(LPARAM)0); + pYAMNFcn->SCDecFcn=(YAMN_SCMANAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SCDECID,(LPARAM)0); + pYAMNFcn->SetStatusFcn=(YAMN_SETSTATUSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SETSTATUSID,(LPARAM)0); + pYAMNFcn->GetStatusFcn=(YAMN_GETSTATUSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_GETSTATUSID,(LPARAM)0); + + if (NULL==(pYAMNMailFcn=new struct MailExportedFcns)) + {UnLoadPOP3(0); return 0;} + + pYAMNMailFcn->SynchroMessagesFcn=(YAMN_SYNCHROMIMEMSGSFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_SYNCHROMIMEMSGSID,(LPARAM)0); + pYAMNMailFcn->TranslateHeaderFcn=(YAMN_TRANSLATEHEADERFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_TRANSLATEHEADERID,(LPARAM)0); + pYAMNMailFcn->AppendQueueFcn=(YAMN_APPENDQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_APPENDQUEUEID,(LPARAM)0); + pYAMNMailFcn->DeleteMessagesToEndFcn=(YAMN_DELETEMIMEQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_DELETEMIMEQUEUEID,(LPARAM)0); + pYAMNMailFcn->DeleteMessageFromQueueFcn=(YAMN_DELETEMIMEMESSAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_DELETEMIMEMESSAGEID,(LPARAM)0); + pYAMNMailFcn->FindMessageByIDFcn=(YAMN_FINDMIMEMESSAGEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_FINDMIMEMESSAGEID,(LPARAM)0); + pYAMNMailFcn->CreateNewDeleteQueueFcn=(YAMN_CREATENEWDELETEQUEUEFCN)CallService(MS_YAMN_GETFCNPTR,(WPARAM)YAMN_CREATENEWDELETEQUEUEID,(LPARAM)0); + + //set static variable + if (CPOP3Account::AccountWriterSO==NULL) { + if (NULL==(CPOP3Account::AccountWriterSO=new SCOUNTER)) + {UnLoadPOP3(0); return 0;} + } + + //First, we register this plugin + //it is quite impossible this function returns zero (failure) as YAMN and internal plugin structre versions are the same + POP3ProtocolRegistration.Name = Translate("POP3 protocol (internal)"); + POP3ProtocolRegistration.Description = Translate("Mail notifier and browser for Miranda NG. Included POP3 protocol."); + if (NULL==(POP3Plugin=(HYAMNPROTOPLUGIN)CallService(MS_YAMN_REGISTERPROTOPLUGIN,(WPARAM)&POP3ProtocolRegistration,(LPARAM)YAMN_PROTOREGISTRATIONVERSION))) + return 0; + + //Next we set our imported functions for YAMN + if (!SetProtocolPluginFcnImport(POP3Plugin,&POP3ProtocolFunctions,YAMN_PROTOIMPORTFCNVERSION,&POP3MailFunctions,YAMN_MAILIMPORTFCNVERSION)) + return 0; + + //Then, we read all mails for accounts. + //You must first register account, before using this function as YAMN must use CreatePOP3Account function to add new accounts + //But if CreatePOP3Account is not implemented (equals to NULL), YAMN creates account as YAMN's standard HACCOUNT + if (FileName) CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName, 0); //shoud not happen (only for secure) + FileName = (TCHAR *)CallService(MS_YAMN_GETFILENAME,(WPARAM)_T("pop3"), 0); + + switch(CallService(MS_YAMN_READACCOUNTS,(WPARAM)POP3Plugin,(LPARAM)FileName)) { + case EACC_FILEVERSION: + MessageBox(NULL,TranslateT("Found new version of account book, not compatible with this version of YAMN."),TranslateT("YAMN (internal POP3) read error"),MB_OK); + CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); + FileName = NULL; + return 0; + case EACC_FILECOMPATIBILITY: + MessageBox(NULL,TranslateT("Error reading account file. Account file corrupted."),TranslateT("YAMN (internal POP3) read error"),MB_OK); + CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); + FileName = NULL; + return 0; + case EACC_ALLOC: + MessageBox(NULL,TranslateT("Memory allocation error while data reading"),TranslateT("YAMN (internal POP3) read error"),MB_OK); + CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); + FileName = NULL; + return 0; + case EACC_SYSTEM: + if (ERROR_FILE_NOT_FOUND!=GetLastError()) + { + TCHAR temp[1024] = {0}; + mir_sntprintf(temp, SIZEOF(temp), _T("%s\n%s"),TranslateT("Reading file error. File already in use?"),FileName); + MessageBox(NULL,temp,TranslateT("YAMN (internal POP3) read error"),MB_OK); + CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); + FileName = NULL; + return 0; + } + break; + } + //HookEvent(ME_OPT_INITIALISE,POP3OptInit); + + HACCOUNT Finder; + HANDLE hContact; + DBVARIANT dbv; + char *szProto; + + for (Finder=POP3Plugin->FirstAccount;Finder!=NULL;Finder=Finder->Next) + { + Finder->hContact = NULL; + hContact = db_find_first(); + while(hContact) + { + szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + if (szProto != NULL && strcmp(szProto, YAMN_DBMODULE)==0) + { + if (!DBGetContactSettingString(hContact,YAMN_DBMODULE,"Id",&dbv)) { + if ( strcmp( dbv.pszVal, Finder->Name) == 0) { + Finder->hContact = hContact; + DBWriteContactSettingWord(Finder->hContact, YAMN_DBMODULE, "Status", ID_STATUS_ONLINE); + DBWriteContactSettingString(Finder->hContact, "CList", "StatusMsg", Translate("No new mail message")); + if ((Finder->Flags & YAMN_ACC_ENA) && (Finder->NewMailN.Flags & YAMN_ACC_CONT)) + DBDeleteContactSetting(Finder->hContact, "CList", "Hidden"); + + if (!(Finder->Flags & YAMN_ACC_ENA) || !(Finder->NewMailN.Flags & YAMN_ACC_CONT)) + DBWriteContactSettingByte(Finder->hContact, "CList", "Hidden", 1); + } + DBFreeVariant(&dbv); + } + } + hContact = db_find_next(hContact); + } + + if (Finder->hContact == NULL && (Finder->Flags & YAMN_ACC_ENA) && (Finder->NewMailN.Flags & YAMN_ACC_CONT)) { + //No account contact found, have to create one + Finder->hContact =(HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0); + CallService(MS_PROTO_ADDTOCONTACT,(WPARAM)Finder->hContact,(LPARAM)YAMN_DBMODULE); + DBWriteContactSettingString(Finder->hContact,YAMN_DBMODULE,"Id",Finder->Name); + DBWriteContactSettingString(Finder->hContact,YAMN_DBMODULE,"Nick",Finder->Name); + DBWriteContactSettingString(Finder->hContact,"Protocol","p",YAMN_DBMODULE); + DBWriteContactSettingWord(Finder->hContact, YAMN_DBMODULE, "Status", YAMN_STATUS); + } + } + + return 0; +} + +DWORD WINAPI UnLoadPOP3(void *) +{ + //pYAMNVar is only a pointr, no need delete or free + if (hNetLib) { + Netlib_CloseHandle(hNetLib); hNetLib = NULL;} + if (CPOP3Account::AccountWriterSO) { + delete CPOP3Account::AccountWriterSO; CPOP3Account::AccountWriterSO = NULL;} + if (pYAMNMailFcn) { + delete pYAMNMailFcn; pYAMNMailFcn = NULL;} + if (pYAMNFcn) { + delete pYAMNFcn; pYAMNFcn = NULL;} + if (FileName) { + CallService(MS_YAMN_DELETEFILENAME,(WPARAM)FileName,(LPARAM)0); FileName = NULL;} + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"UnLoadPOP3:done\n"); + #endif + return 1; +} + +DWORD WINAPI WritePOP3Accounts() +{ + DWORD ReturnValue = CallService(MS_YAMN_WRITEACCOUNTS,(WPARAM)POP3Plugin,(LPARAM)FileName); + if (ReturnValue == EACC_SYSTEM) { + TCHAR temp[1024] = {0}; + mir_sntprintf(temp, SIZEOF(temp), _T("%s\n%s"), TranslateT("Error while copying data to disk occured. File in use?"), FileName ); + MessageBox(NULL, temp, TranslateT("POP3 plugin- write file error"), MB_OK ); + } + + return ReturnValue; +} + +DWORD WINAPI WritePOP3Options(HANDLE File,HACCOUNT Which) +{ + DWORD WrittenBytes; + DWORD Ver=POP3_FILEVERSION; + + if ((!WriteFile(File,(char *)&Ver,sizeof(DWORD),&WrittenBytes,NULL)) || + (!WriteFile(File,(char *)&((HPOP3ACCOUNT)Which)->CP,sizeof(WORD),&WrittenBytes,NULL))) + return EACC_SYSTEM; + return 0; +} + +DWORD WINAPI ReadPOP3Options(HACCOUNT Which,char **Parser,char *End) +{ + DWORD Ver; +#ifdef DEBUG_FILEREAD + TCHAR Debug[256]; +#endif + Ver=*(DWORD *)(*Parser); + (*Parser)+=sizeof(DWORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; + if (Ver!=POP3_FILEVERSION) + return EACC_FILECOMPATIBILITY; + + ((HPOP3ACCOUNT)Which)->CP=*(WORD *)(*Parser); + (*Parser)+=sizeof(WORD); + if (*Parser>=End) + return EACC_FILECOMPATIBILITY; +#ifdef DEBUG_FILEREAD + _stprintf(Debug,_T("CodePage: %d, remaining %d chars"),((HPOP3ACCOUNT)Which)->CP,End-*Parser); + MessageBox(NULL,Debug,_T("debug"),MB_OK); +#endif + return 0; +} + +HYAMNMAIL WINAPI CreatePOP3Mail(HACCOUNT Account,DWORD MailDataVersion) +{ + HYAMNMAIL NewMail; +//First, we should check whether MAILDATA matches. +//But this is internal plugin, so YAMN's MAILDATA structure and our MAILDATA structure are +//the same, so we do not need to test version. Otherwise, if MAILDATA version does not match +//in your plugin, you should return NULL, like this: +// if (MailDataVersion!=YAMN_MAILDATAVERSION) return NULL; + +//Now it is needed to construct our POP3 account and return its handle + if (NULL==(NewMail=new YAMNMAIL)) + return NULL; + + if (NULL==(NewMail->MailData=new MAILDATA)) + { + delete NewMail; + return NULL; + } + NewMail->MailData->CP=((HPOP3ACCOUNT)Account)->CP; + return (HYAMNMAIL)NewMail; +} + +static void SetContactStatus(HACCOUNT account, int status){ + if ((account->hContact) && (account->NewMailN.Flags & YAMN_ACC_CONT)) { + DBWriteContactSettingWord(account->hContact, YAMN_DBMODULE, "Status", status); + } +} + +static void PostErrorProc(HPOP3ACCOUNT ActualAccount,void *ParamToBadConnection,DWORD POP3PluginParam,BOOL UseSSL) +{ + char *DataRX; + +//We create new structure, that we pass to bad connection dialog procedure. This procedure next calls YAMN imported fuction +//from POP3 protocol to determine the description of error. We can describe error from our error code structure, because later, +//when YAMN calls our function, it passes us our error code. This is pointer to structure for POP3 protocol in fact. + PPOP3_ERRORCODE ErrorCode; + +//We store status before we do Quit(), because quit can destroy our errorcode status + if (NULL!=(ErrorCode=new POP3_ERRORCODE)) + { + ErrorCode->SSL=UseSSL; + ErrorCode->AppError=ActualAccount->SystemError; + ErrorCode->POP3Error=ActualAccount->Client.POP3Error; + ErrorCode->NetError=ActualAccount->Client.NetClient->NetworkError; + ErrorCode->SystemError=ActualAccount->Client.NetClient->SystemError; + } + + if (POP3PluginParam==(DWORD)NULL) //if it was normal YAMN call (force check or so on) + { + try + { + DataRX=ActualAccount->Client.Quit(); + if (DataRX!=NULL) + free(DataRX); + } + catch(...) + { + } +//We always close connection if error occured + try + { + ActualAccount->Client.NetClient->Disconnect(); + } + catch(...) + { + } + + SetAccountStatus(ActualAccount,TranslateT("Disconnected")); + +//If we cannot allocate memory, do nothing + if (ErrorCode==NULL) + { + SetEvent(ActualAccount->UseInternetFree); + return; + } + } + else //else it was called from POP3 plugin, probably error when deleting old mail (POP3 synchro calls POP3 delete) + if (ErrorCode==NULL) + return; + + if ((ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG) || (ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO) || (ActualAccount->BadConnectN.Flags & YAMN_ACC_POP)) + { + YAMN_BADCONNECTIONPARAM cp={(HANDLE)0,ActualAccount,(UINT_PTR)ErrorCode,ParamToBadConnection}; + + CallService(MS_YAMN_BADCONNECTION,(WPARAM)&cp,(LPARAM)YAMN_BADCONNECTIONVERSION); + } + if (POP3PluginParam==(DWORD)NULL) //if it was normal YAMN call + SetEvent(ActualAccount->UseInternetFree); +} + +//Checks POP3 account and synchronizes it +DWORD WINAPI SynchroPOP3(struct CheckParam * WhichTemp) +{ + HPOP3ACCOUNT ActualAccount; + CPop3Client *MyClient; + HYAMNMAIL NewMails=NULL,MsgQueuePtr=NULL; + char* DataRX=NULL,*Temp; + int mboxsize,msgs,i; + SYSTEMTIME now; + LPVOID YAMNParam; + DWORD CheckFlags; + BOOL UsingInternet=FALSE; + struct { + char *ServerName; + DWORD ServerPort; + char *ServerLogin; + char *ServerPasswd; + DWORD Flags; + DWORD NFlags; + DWORD NNFlags; + } ActualCopied; + + //First, we should compare our version of CheckParam structure, but here it is not needed, because YAMN and internal plugin + //have the same version. But your plugin should do that in this way: + // if (((struct CheckParam *)WhichTemp)->Ver!=YAMN_CHECKVERSION) + // { + // SetEvent(((struct CheckParam *)WhichTemp)->ThreadRunningEV); //don't forget to unblock YAMN + // return (DWORD)-1; //ok, but we should return value. + // //When our plugin returns e.g. 0xFFFFFFFF (=-1, this is only our plugin value, YAMN does nothing with return value, + // //but only tests if it is nonzero. If yes, it calls GetErrorStringFcn. We know problem occured in YAMN incompatibility + // //and then we can in our GetErrorStringFcn e.g. return string "Uncompatible version of YAMN". + // } + + ActualAccount=(HPOP3ACCOUNT)WhichTemp->AccountParam; //copy address of structure from calling thread to stack of this thread + YAMNParam=WhichTemp->BrowserParam; + CheckFlags=WhichTemp->Flags; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:Incrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); + #endif + SCInc(ActualAccount->UsingThreads); + //Unblock YAMN, signal that we have copied all parameters from YAMN thread stack + if (INVALID_HANDLE_VALUE!=WhichTemp->ThreadRunningEV) + SetEvent(WhichTemp->ThreadRunningEV); + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0!=WaitToRead(ActualAccount)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountSO-read wait failed\n"); + #endif + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); + #endif + SCDec(ActualAccount->UsingThreads); + return 0; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountSO-read enter\n"); + #endif + 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. + ActualCopied.ServerName = _strdup(ActualAccount->Server->Name); + ActualCopied.ServerPort=ActualAccount->Server->Port; + ActualCopied.Flags=ActualAccount->Flags; + ActualCopied.ServerLogin=_strdup(ActualAccount->Server->Login); + ActualCopied.ServerPasswd=_strdup(ActualAccount->Server->Passwd); + ActualCopied.NFlags=ActualAccount->NewMailN.Flags; + ActualCopied.NNFlags=ActualAccount->NoNewMailN.Flags; + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountSO-read done\n"); + #endif + ReadDone(ActualAccount); + + SCInc(ActualAccount->InternetQueries); //increment counter, that there is one more thread waiting for connection + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-wait\n"); + #endif + WaitForSingleObject(ActualAccount->UseInternetFree,INFINITE); //wait until we can use connection + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-enter\n"); + #endif + SCDec(ActualAccount->InternetQueries); + + //OK, we enter the "use internet" section. But after we start communication, we can test if we did not enter the "use internet" section only for the reason, + //that previous thread release the internet section because this account has stop signal (we stop account and there are 2 threads: one communicating, + //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) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:stop signal-InternetFreeEV-done\n"); + #endif + SetEvent(ActualAccount->UseInternetFree); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:stop signal-Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); + #endif + SCDec(ActualAccount->UsingThreads); + return 0; + } + UsingInternet=TRUE; + + GetLocalTime(&now); + ActualAccount->SystemError=0; //now we can use internet for this socket. First, clear errorcode. + try + { + SetContactStatus(ActualAccount,ID_STATUS_OCCUPIED); + #ifdef DEBUG_COMM + DebugLog(CommFile,"<--------Communication-------->\n"); + #endif + // if we are already connected, we have open session (another thread left us open session), so we don't need to login + // note that connected state without logging cannot occur, because if we close session, we always close socket too (we must close socket is the right word :)) + if ((MyClient->NetClient==NULL) || !MyClient->NetClient->Connected()) + { + SetAccountStatus(ActualAccount,TranslateT("Connecting to server")); + + DataRX=MyClient->Connect(ActualCopied.ServerName,ActualCopied.ServerPort,ActualCopied.Flags & YAMN_ACC_SSL23,ActualCopied.Flags & YAMN_ACC_NOTLS); + char *timestamp=NULL; + + if (DataRX!=NULL) + { + if (ActualCopied.Flags & YAMN_ACC_APOP) + { + char *lpos=strchr(DataRX,'<'); + char *rpos=strchr(DataRX,'>'); + if (lpos && rpos && rpos>lpos) { + int sz=(int)(rpos-lpos+2); + timestamp=new char[sz]; + memcpy(timestamp, lpos, sz-1); + timestamp[sz-1]='\0'; + } + } + free(DataRX); + DataRX=NULL; + } + + SetAccountStatus(ActualAccount,TranslateT("Entering POP3 account")); + + if (ActualCopied.Flags & YAMN_ACC_APOP) + { + DataRX=MyClient->APOP(ActualCopied.ServerLogin,ActualCopied.ServerPasswd,timestamp); + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + delete[] timestamp; + } else { + DataRX=MyClient->User(ActualCopied.ServerLogin); + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + DataRX=MyClient->Pass(ActualCopied.ServerPasswd); + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + } + } + SetAccountStatus(ActualAccount,TranslateT("Searching for new mail message")); + + DataRX=MyClient->Stat(); + + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"<--------Account checking-------->\n"); + DebugLog(DecodeFile,"\n"); + #endif + ExtractStat(DataRX,MyClient->NetClient->Rcv,&mboxsize,&msgs); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%d\n",mboxsize); + DebugLog(DecodeFile,"%d\n",msgs); + DebugLog(DecodeFile,"\n"); + #endif + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + for (i=0;iNext=(HYAMNMAIL)CallService(MS_YAMN_CREATEACCOUNTMAIL,(WPARAM)ActualAccount,(LPARAM)YAMN_MAILVERSION); + MsgQueuePtr=MsgQueuePtr->Next; + } + if (MsgQueuePtr==NULL) + { + ActualAccount->SystemError=EPOP3_QUEUEALLOC; + throw (DWORD)ActualAccount->SystemError; + } + } + + if (msgs) + { + DataRX=MyClient->List(); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + ExtractList(DataRX,MyClient->NetClient->Rcv,NewMails); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + DataRX=MyClient->Uidl(); + ExtractUIDL(DataRX,MyClient->NetClient->Rcv,NewMails); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait\n"); + #endif + if (WAIT_OBJECT_0!=MsgsWaitToWrite(ActualAccount)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait failed\n"); + #endif + throw (DWORD)(ActualAccount->SystemError=EACC_STOPPED); + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write enter\n"); + #endif + ActualAccount->LastChecked=now; + for (MsgQueuePtr=(HYAMNMAIL)ActualAccount->Mails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next){ + if (MsgQueuePtr->Flags&YAMN_MSG_BODYREQUESTED){ + HYAMNMAIL NewMsgsPtr=NULL; + for (NewMsgsPtr=(HYAMNMAIL)NewMails;NewMsgsPtr!=NULL;NewMsgsPtr=NewMsgsPtr->Next){ + if (!strcmp(MsgQueuePtr->ID,NewMsgsPtr->ID)) { + TCHAR accstatus[512]; + wsprintf(accstatus,TranslateT("Reading body %s"),NewMsgsPtr->ID); + SetAccountStatus(ActualAccount,accstatus); + DataRX=MyClient->Top(MsgQueuePtr->Number,100); + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + DebugLog(DecodeFile,"
%s
\n",DataRX); + #endif + if (DataRX!=NULL) + { + Temp=DataRX; + while((TempNetClient->Rcv) && (WS(Temp) || ENDLINE(Temp))) Temp++; + + if (OKLINE(DataRX)) + for (Temp=DataRX;(TempNetClient->Rcv) && (!ENDLINE(Temp));Temp++); + while((TempNetClient->Rcv) && ENDLINE(Temp)) Temp++; + } + else + continue; + //delete all the headers of the old mail MsgQueuePtr->MailData->TranslatedHeader + struct CMimeItem *TH = MsgQueuePtr->MailData->TranslatedHeader; + if (TH) for (;MsgQueuePtr->MailData->TranslatedHeader!=NULL;) + { + TH=TH->Next; + if (MsgQueuePtr->MailData->TranslatedHeader->name!=NULL) + delete[] MsgQueuePtr->MailData->TranslatedHeader->name; + if (MsgQueuePtr->MailData->TranslatedHeader->value!=NULL) + delete[] MsgQueuePtr->MailData->TranslatedHeader->value; + delete MsgQueuePtr->MailData->TranslatedHeader; + MsgQueuePtr->MailData->TranslatedHeader=TH; + } + + TranslateHeader(Temp,MyClient->NetClient->Rcv-(Temp-DataRX),&MsgQueuePtr->MailData->TranslatedHeader); + + + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"
\n"); + #endif + MsgQueuePtr->Flags|=YAMN_MSG_BODYRECEIVED; + + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + break; + } + } + } + } + + SynchroMessages(ActualAccount,(HYAMNMAIL *)&ActualAccount->Mails,NULL,(HYAMNMAIL *)&NewMails,NULL); //we get only new mails on server! +// NewMails=NULL; + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write done\n"); + #endif + MsgsWriteDone(ActualAccount); + for (MsgQueuePtr=(HYAMNMAIL)ActualAccount->Mails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next){ + if ((MsgQueuePtr->Flags&YAMN_MSG_BODYREQUESTED) && (MsgQueuePtr->Flags&YAMN_MSG_BODYRECEIVED)) { + MsgQueuePtr->Flags&=~YAMN_MSG_BODYREQUESTED; + if (MsgQueuePtr->MsgWindow){ + SendMessage(MsgQueuePtr->MsgWindow,WM_YAMN_CHANGECONTENT,0,0); + } + } + } + + for (msgs=0,MsgQueuePtr=NewMails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next,msgs++); //get number of new mails + + try + { + TCHAR accstatus[512]; + + for (i=0,MsgQueuePtr=NewMails;MsgQueuePtr!=NULL;i++) + { + BOOL autoretr = (ActualAccount->Flags & YAMN_ACC_BODY)!=0; + DataRX=MyClient->Top(MsgQueuePtr->Number,autoretr?100:0); + wsprintf(accstatus,TranslateT("Reading new mail messages (%d%% done)"),100*i/msgs); + SetAccountStatus(ActualAccount,accstatus); + + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + DebugLog(DecodeFile,"
%s
\n",DataRX); + #endif + if (DataRX!=NULL) + { + Temp=DataRX; + while((TempNetClient->Rcv) && (WS(Temp) || ENDLINE(Temp))) Temp++; + + if (OKLINE(DataRX)) + for (Temp=DataRX;(TempNetClient->Rcv) && (!ENDLINE(Temp));Temp++); + while((TempNetClient->Rcv) && ENDLINE(Temp)) Temp++; + } + else + continue; + + TranslateHeader(Temp,MyClient->NetClient->Rcv-(Temp-DataRX),&MsgQueuePtr->MailData->TranslatedHeader); + + + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"
\n"); + #endif + MsgQueuePtr->Flags|=YAMN_MSG_NORMALNEW; + if (autoretr) MsgQueuePtr->Flags|=YAMN_MSG_BODYRECEIVED; + + //We are going to filter mail. Warning!- we must not be in read access neither write access to mails when calling this service + //This is done, because the "NewMails" queue is not synchronised. It is because it is new queue. Only this thread uses new queue yet, it is not + //connected to account mail queue. + // CallService(MS_YAMN_FILTERMAIL,(WPARAM)ActualAccount,(LPARAM)MsgQueuePtr); + FilterMailSvc((WPARAM)ActualAccount,(LPARAM)MsgQueuePtr); + + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + + //MsgQueuePtr->MailData->Body=MyClient->Retr(MsgQueuePtr->Number); + + MsgQueuePtr=MsgQueuePtr->Next; + + } + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait\n"); + #endif + if (WAIT_OBJECT_0!=MsgsWaitToWrite(ActualAccount)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait failed\n"); + #endif + throw (DWORD)ActualAccount->SystemError==EACC_STOPPED; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write enter\n"); + #endif + if (ActualAccount->Mails==NULL) + ActualAccount->Mails=NewMails; + else + { + ActualAccount->LastMail=ActualAccount->LastChecked; + AppendQueue((HYAMNMAIL)ActualAccount->Mails,NewMails); + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write done\n"); + #endif + MsgsWriteDone(ActualAccount); + + // 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,YAMNParam,(void *)POP3_DELETEFROMCHECK}; + + // Delete mails from server. Here we should not be in write access for account's mails + DeleteMailsPOP3(&ParamToDeleteMails); + } + + // if there is no waiting thread for internet connection close it + // else leave connection open + if (0==SCGetNumber(ActualAccount->InternetQueries)) + { + DataRX=MyClient->Quit(); + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + MyClient->NetClient->Disconnect(); + + SetAccountStatus(ActualAccount,TranslateT("Disconnected")); + } + + UsingInternet=FALSE; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-done\n"); + #endif + SetEvent(ActualAccount->UseInternetFree); + + ActualAccount->LastSChecked=ActualAccount->LastChecked; + ActualAccount->LastSynchronised=ActualAccount->LastChecked; + } + catch(...) + { + throw; //go to the main exception handling + } + + { + YAMN_MAILBROWSERPARAM Param={(HANDLE)0,ActualAccount,ActualCopied.NFlags,ActualCopied.NNFlags,YAMNParam}; + + 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 + CallService(MS_YAMN_MAILBROWSER,(WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); + } + SetContactStatus(ActualAccount,ActualAccount->isCounting?ID_STATUS_ONLINE:ID_STATUS_OFFLINE); + } + #ifdef DEBUG_COMM + catch(DWORD ErrorCode) + #else + catch(DWORD) + #endif + { + if (ActualAccount->Client.POP3Error==EPOP3_STOPPED) + ActualAccount->SystemError=EACC_STOPPED; + #ifdef DEBUG_COMM + DebugLog(CommFile,"ERROR: %x\n",ErrorCode); + #endif + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait\n"); + #endif + if (WAIT_OBJECT_0==MsgsWaitToWrite(ActualAccount)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write enter\n"); + #endif + ActualAccount->LastChecked=now; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write done\n"); + #endif + MsgsWriteDone(ActualAccount); + } + #ifdef DEBUG_SYNCHRO + else + DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write wait failed\n"); + #endif + + DeleteMIMEQueue(ActualAccount,NewMails); + + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + switch(ActualAccount->SystemError) + { + case EACC_QUEUEALLOC: + case EACC_STOPPED: + ActualAccount->Client.NetClient->Disconnect(); + break; + default: + PostErrorProc(ActualAccount,YAMNParam,(DWORD)NULL,MyClient->SSL); //it closes internet connection too + } + + if (UsingInternet) //if our thread still uses internet + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-done\n"); + #endif + SetEvent(ActualAccount->UseInternetFree); + } + SetContactStatus(ActualAccount,ID_STATUS_NA); + } + free(ActualCopied.ServerName); + free(ActualCopied.ServerLogin); + free(ActualCopied.ServerPasswd); + #ifdef DEBUG_COMM + DebugLog(CommFile,"\n"); + #endif +// WriteAccounts(); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); + #endif + SCDec(ActualAccount->UsingThreads); + return 0; +} + +DWORD WINAPI DeleteMailsPOP3(struct DeleteParam *WhichTemp) +{ + HPOP3ACCOUNT ActualAccount; + LPVOID YAMNParam; + UINT_PTR POP3PluginParam; + CPop3Client *MyClient; + HYAMNMAIL DeleteMails,NewMails=NULL,MsgQueuePtr; + char* DataRX=NULL; + int mboxsize,msgs,i; + BOOL UsingInternet=FALSE; + struct { + char *ServerName; + DWORD ServerPort; + char *ServerLogin; + char *ServerPasswd; + DWORD Flags; + DWORD NFlags; + DWORD NNFlags; + } ActualCopied; + + //First, we should compare our version of DeleteParam structure, but here it is not needed, because YAMN and internal plugin + //have the same version. But your plugin should do that in this way: + // if (((struct DeleteParam *)WhichTemp)->Ver!=YAMN_DELETEVERSION) + // { + // SetEvent(((struct DeleteParam *)WhichTemp)->ThreadRunningEV); //don't forget to unblock YAMN + // return (DWORD)-1; //ok, but we should return value. + // //When our plugin returns e.g. 0xFFFFFFFF (this is only our plugin value, YAMN does nothing with return value, + // //but only tests if it is nonzero. If yes, it calls GetErrorStringFcn), we know problem occured in YAMN incompatibility + // //and then we can in our GetErrorStringFcn e.g. return string "Uncompatible version of YAMN". + // } + + ActualAccount=(HPOP3ACCOUNT)((struct DeleteParam *)WhichTemp)->AccountParam; //copy address of structure from calling thread to stack of this thread + YAMNParam=((struct DeleteParam *)WhichTemp)->BrowserParam; + POP3PluginParam=(UINT_PTR)((struct DeleteParam *)WhichTemp)->CustomParam; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:Incrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); +#endif + SCInc(ActualAccount->UsingThreads); + if (INVALID_HANDLE_VALUE!=WhichTemp->ThreadRunningEV) + SetEvent(WhichTemp->ThreadRunningEV); + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read wait\n"); +#endif + if (WAIT_OBJECT_0!=WaitToRead(ActualAccount)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read wait failed\n"); +#endif +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); +#endif + SCDec(ActualAccount->UsingThreads); + return 0; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read enter\n"); +#endif + if (NULL==(DeleteMails=(HYAMNMAIL)CreateNewDeleteQueue((HYAMNMAIL)ActualAccount->Mails))) //if there's no mail for deleting, return + { + if (POP3_DELETEFROMCHECK!=POP3PluginParam) //We do not wait for free internet when calling from SynchroPOP3. It is because UseInternetFree is blocked + { + YAMN_MAILBROWSERPARAM Param={(HANDLE)0,ActualAccount,YAMN_ACC_MSGP,YAMN_ACC_MSGP,YAMNParam}; //Just update the window + + CallService(MS_YAMN_MAILBROWSER,(WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read done\n"); +#endif + ReadDone(ActualAccount); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); +#endif + SCDec(ActualAccount->UsingThreads); + + return NO_MAIL_FOR_DELETE; + } + 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. + ActualCopied.ServerName=_strdup(ActualAccount->Server->Name); + ActualCopied.ServerPort=ActualAccount->Server->Port; + ActualCopied.Flags=ActualAccount->Flags; + ActualCopied.ServerLogin=_strdup(ActualAccount->Server->Login); + ActualCopied.ServerPasswd=_strdup(ActualAccount->Server->Passwd); + ActualCopied.NFlags=ActualAccount->NewMailN.Flags; + ActualCopied.NNFlags=ActualAccount->NoNewMailN.Flags; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountSO-read done\n"); +#endif + ReadDone(ActualAccount); + + SCInc(ActualAccount->InternetQueries); //This is POP3-internal SCOUNTER, we set another thread wait for this account to be connected to inet + if (POP3_DELETEFROMCHECK!=POP3PluginParam) //We do not wait for free internet when calling from SynchroPOP3. It is because UseInternetFree is blocked + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:InternetFreeEV-wait\n"); +#endif + WaitForSingleObject(ActualAccount->UseInternetFree,INFINITE); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:InternetFreeEV-enter\n"); +#endif + } + SCDec(ActualAccount->InternetQueries); + UsingInternet=TRUE; + + try + { + SetContactStatus(ActualAccount,ID_STATUS_OCCUPIED); +#ifdef DEBUG_COMM + DebugLog(CommFile,"<--------Communication-------->\n"); +#endif + if ((MyClient->NetClient==NULL) || !MyClient->NetClient->Connected()) + { + SetAccountStatus(ActualAccount,TranslateT("Connecting to server")); + + DataRX=MyClient->Connect(ActualCopied.ServerName,ActualCopied.ServerPort,ActualCopied.Flags & YAMN_ACC_SSL23,ActualCopied.Flags & YAMN_ACC_NOTLS); + + char *timestamp=NULL; + if (DataRX!=NULL) { + if (ActualAccount->Flags & YAMN_ACC_APOP) { + char *lpos=strchr(DataRX,'<'); + char *rpos=strchr(DataRX,'>'); + if (lpos && rpos && rpos>lpos) { + int sz=(int)(rpos-lpos+2); + timestamp=new char[sz]; + memcpy(timestamp, lpos, sz-1); + timestamp[sz-1]='\0'; + } + } + free(DataRX); + DataRX=NULL; + } + SetAccountStatus(ActualAccount,TranslateT("Entering POP3 account")); + + if (ActualAccount->Flags & YAMN_ACC_APOP) + { + DataRX=MyClient->APOP(ActualCopied.ServerLogin,ActualCopied.ServerPasswd,timestamp); + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + delete[] timestamp; + } else { + DataRX=MyClient->User(ActualCopied.ServerLogin); + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + DataRX=MyClient->Pass(ActualCopied.ServerPasswd); + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + } + } + +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"<--------Deleting requested mails-------->\n"); +#endif + if (POP3_DELETEFROMCHECK!=POP3PluginParam) //We do not need to get mails on server as we have already it from check function + { + SetAccountStatus(ActualAccount,TranslateT("Deleting requested mails")); + + DataRX=MyClient->Stat(); + +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); +#endif + ExtractStat(DataRX,MyClient->NetClient->Rcv,&mboxsize,&msgs); +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%d\n",mboxsize); + DebugLog(DecodeFile,"%d\n",msgs); + DebugLog(DecodeFile,"\n"); +#endif + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + for (i=0;iNext=(HYAMNMAIL)CallService(MS_YAMN_CREATEACCOUNTMAIL,(WPARAM)ActualAccount,(LPARAM)YAMN_MAILVERSION); + MsgQueuePtr=MsgQueuePtr->Next; + } + if (MsgQueuePtr==NULL) + { + ActualAccount->SystemError=EPOP3_QUEUEALLOC; + throw (DWORD)ActualAccount->SystemError; + } + } + + if (msgs) + { +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); +#endif + DataRX=MyClient->Uidl(); + ExtractUIDL(DataRX,MyClient->NetClient->Rcv,NewMails); +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); +#endif + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; +// we get "new mails" on server (NewMails will contain all mails on server not found in DeleteMails) +// but also in DeleteMails we get only those, which are still on server with their responsable numbers + SynchroMessages(ActualAccount,(HYAMNMAIL *)&DeleteMails,NULL,(HYAMNMAIL *)&NewMails,NULL); + } + } + else + SetAccountStatus(ActualAccount,TranslateT("Deleting spam")); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write wait\n"); +#endif + if (WAIT_OBJECT_0!=MsgsWaitToWrite(ActualAccount)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write wait failed\n"); +#endif + throw (DWORD)EACC_STOPPED; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write enter\n"); +#endif + if (msgs || POP3_DELETEFROMCHECK==POP3PluginParam) + { + try + { + HYAMNMAIL Temp; + + for (i=0,MsgQueuePtr=DeleteMails;MsgQueuePtr!=NULL;i++) + { + if (!(MsgQueuePtr->Flags & YAMN_MSG_VIRTUAL)) //of course we can only delete real mails, not virtual + { + DataRX=MyClient->Dele(MsgQueuePtr->Number); + Temp=MsgQueuePtr->Next; + if (POP3_FOK==MyClient->AckFlag) //if server answers that mail was deleted + { + DeleteMIMEMessage((HYAMNMAIL *)&DeleteMails,MsgQueuePtr); + HYAMNMAIL DeletedMail=FindMIMEMessageByID((HYAMNMAIL)ActualAccount->Mails,MsgQueuePtr->ID); + if ((MsgQueuePtr->Flags & YAMN_MSG_MEMDELETE)) //if mail should be deleted from memory (or disk) + { + DeleteMIMEMessage((HYAMNMAIL *)&ActualAccount->Mails,DeletedMail); //remove from queue + CallService(MS_YAMN_DELETEACCOUNTMAIL,(WPARAM)POP3Plugin,(LPARAM)DeletedMail); + } + else //else mark it only as "deleted mail" + { + DeletedMail->Flags |= (YAMN_MSG_VIRTUAL | YAMN_MSG_DELETED); + DeletedMail->Flags &= ~(YAMN_MSG_NEW | YAMN_MSG_USERDELETE | YAMN_MSG_AUTODELETE); //clear "new mail" + } + delete MsgQueuePtr->MailData; + delete[] MsgQueuePtr->ID; + delete MsgQueuePtr; + } + MsgQueuePtr=Temp; + + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + } + else + MsgQueuePtr=MsgQueuePtr->Next; + } + } + catch(...) //if any exception in the code where we have write-access to account occured, don't forget to leave write-access + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write done\n"); +#endif + MsgsWriteDone(ActualAccount); + throw; //and go to the main exception handling + } + + if (NewMails!=NULL) +// in ActualAccount->Mails we have all mails stored before calling this function +// in NewMails we have all mails not found in DeleteMails (in other words: we performed new ID checking and we +// stored all mails found on server, then we deleted the ones we wanted to delete in this function +// and NewMails queue now contains actual state of mails on server). But we will not use NewMails as actual state, because NewMails does not contain header data (subject, from...) +// We perform deleting from ActualAccount->Mails: we remove from original queue (ActualAccount->Mails) all deleted mails + SynchroMessages(ActualAccount,(HYAMNMAIL *)&ActualAccount->Mails,NULL,(HYAMNMAIL *)&NewMails,NULL); +// Now ActualAccount->Mails contains all mails when calling this function except the ones, we wanted to delete (these are in DeleteMails) +// And in NewMails we have new mails (if any) + else if (POP3_DELETEFROMCHECK!=POP3PluginParam) + { + DeleteMIMEQueue(ActualAccount,(HYAMNMAIL)ActualAccount->Mails); + ActualAccount->Mails=NULL; + } + } + else + { + DeleteMIMEQueue(ActualAccount,(HYAMNMAIL)ActualAccount->Mails); + ActualAccount->Mails=NULL; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:ActualAccountMsgsSO-write done\n"); +#endif + MsgsWriteDone(ActualAccount); +#ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); +#endif + +// TODO: now, we have in NewMails new mails. If NewMails is not NULL, we found some new mails, so Checking for new mail should be performed +// now, we do not call CheckPOP3 + +// if there is no waiting thread for internet connection close it +// else leave connection open +// if this functin was called from SynchroPOP3, then do not try to disconnect + if (POP3_DELETEFROMCHECK!=POP3PluginParam) + { + YAMN_MAILBROWSERPARAM Param={(HANDLE)0,ActualAccount,ActualCopied.NFlags,YAMN_ACC_MSGP,YAMNParam}; + + CallService(MS_YAMN_MAILBROWSER,(WPARAM)&Param,(LPARAM)YAMN_MAILBROWSERVERSION); + + if (0==SCGetNumber(ActualAccount->InternetQueries)) + { + DataRX=MyClient->Quit(); + if (DataRX!=NULL) + free(DataRX); + DataRX=NULL; + MyClient->NetClient->Disconnect(); + + SetAccountStatus(ActualAccount,TranslateT("Disconnected")); + } + + UsingInternet=FALSE; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:InternetFreeEV-done\n"); +#endif + SetEvent(ActualAccount->UseInternetFree); + } + SetContactStatus(ActualAccount,ActualAccount->isCounting?ID_STATUS_ONLINE:ID_STATUS_OFFLINE); + } +#ifdef DEBUG_COMM + catch(DWORD ErrorCode) +#else + catch(DWORD) +#endif + { + if (ActualAccount->Client.POP3Error==EPOP3_STOPPED) + ActualAccount->SystemError=EACC_STOPPED; +#ifdef DEBUG_COMM + DebugLog(CommFile,"ERROR %x\n",ErrorCode); +#endif + if (DataRX!=NULL) + free(DataRX); + switch(ActualAccount->SystemError) + { + case EACC_QUEUEALLOC: + case EACC_STOPPED: + ActualAccount->Client.NetClient->Disconnect(); + break; + default: + PostErrorProc(ActualAccount,YAMNParam,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 + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"CheckPOP3:InternetFreeEV-done\n"); +#endif + SetEvent(ActualAccount->UseInternetFree); + } + } + + free(ActualCopied.ServerName); + free(ActualCopied.ServerLogin); + free(ActualCopied.ServerPasswd); + + DeleteMIMEQueue(ActualAccount,NewMails); + DeleteMIMEQueue(ActualAccount,DeleteMails); + +#ifdef DEBUG_COMM + DebugLog(CommFile,"\n"); +#endif +// WriteAccounts(); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"DeleteMailsPOP3:Decrementing \"using threads\" %x (account %x)\n",ActualAccount->UsingThreads,ActualAccount); +#endif + SCDec(ActualAccount->UsingThreads); + return 0; +} + +void ExtractStat(char *stream,int len,int *mboxsize,int *mails) +{ + char *finder=stream; + while(WS(finder) || ENDLINE(finder)) finder++; + if (ACKLINE(finder)) + { + while(!WS(finder)) finder++; + while(WS(finder)) finder++; + } + if (1!=sscanf(finder,"%d",mails)) + throw (DWORD)EPOP3_STAT; + while(!WS(finder)) finder++; + while(WS(finder)) finder++; + if (1!=sscanf(finder,"%d",mboxsize)) + throw (DWORD)EPOP3_STAT; +} +void ExtractMail(char *stream,int len,HYAMNMAIL queue) +{ + char *finder=stream; + char *finderend; + int msgnr,i; + HYAMNMAIL queueptr=queue; + + while(WS(finder) || ENDLINE(finder)) finder++; + while(!ACKLINE(finder)) finder++; + while(!ENDLINE(finder)) finder++; //now we at the end of first ack line + while(finder<=(stream+len)) + { + while(ENDLINE(finder)) finder++; //go to the new line + if (DOTLINE(finder+1)) //at the end of stream + break; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + while(WS(finder)) finder++; //jump whitespace + if (1!=sscanf(finder,"%d",&msgnr)) + throw (DWORD)EPOP3_UIDL; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%d\n",msgnr); + #endif +// for (i=1,queueptr=queue;(queueptr->Next!=NULL) && (iNext,i++); +// if (i!=msgnr) +// throw (DWORD)EPOP3_UIDL; + while(!WS(finder)) finder++; //jump characters + while(WS(finder)) finder++; //jump whitespace + finderend=finder+1; + while(!WS(finderend) && !ENDLINE(finderend)) finderend++; + queueptr->ID=new char[finderend-finder+1]; + for (i=0;finder!=finderend;finder++,i++) + queueptr->MailData->Body[i]=*finder; + queueptr->MailData->Body[i]=0; //ends string + queueptr->Number=msgnr; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%s\n",queueptr->MailData->Body); + DebugLog(DecodeFile,"\n"); + #endif + queueptr=queueptr->Next; + while(!ENDLINE(finder)) finder++; + } +} + +void ExtractUIDL(char *stream,int len,HYAMNMAIL queue) +{ + char *finder=stream; + char *finderend; + int msgnr,i; + HYAMNMAIL queueptr=queue; + + while(WS(finder) || ENDLINE(finder)) finder++; + while(!ACKLINE(finder)) finder++; + while(!ENDLINE(finder)) finder++; //now we at the end of first ack line + while(finder<=(stream+len)) + { + while(ENDLINE(finder)) finder++; //go to the new line + if (DOTLINE(finder+1)) //at the end of stream + break; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n"); + #endif + while(WS(finder)) finder++; //jump whitespace + if (1!=sscanf(finder,"%d",&msgnr)) + throw (DWORD)EPOP3_UIDL; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%d\n",msgnr); + #endif +// for (i=1,queueptr=queue;(queueptr->Next!=NULL) && (iNext,i++); +// if (i!=msgnr) +// throw (DWORD)EPOP3_UIDL; + while(!WS(finder)) finder++; //jump characters + while(WS(finder)) finder++; //jump whitespace + finderend=finder+1; + while(!WS(finderend) && !ENDLINE(finderend)) finderend++; + queueptr->ID=new char[finderend-finder+1]; + for (i=0;finder!=finderend;finder++,i++) + queueptr->ID[i]=*finder; + queueptr->ID[i]=0; //ends string + queueptr->Number=msgnr; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%s\n",queueptr->ID); + DebugLog(DecodeFile,"\n"); + #endif + queueptr=queueptr->Next; + while(!ENDLINE(finder)) finder++; + } +} + +void ExtractList(char *stream,int len,HYAMNMAIL queue) +{ + char *finder=stream; + char *finderend; + int msgnr,i; + HYAMNMAIL queueptr; + + while(WS(finder) || ENDLINE(finder)) finder++; + while(!ACKLINE(finder)) finder++; + while(!ENDLINE(finder)) finder++; //now we at the end of first ack line + while(finder<=(stream+len)) + { + while(ENDLINE(finder)) finder++; //go to the new line + if (DOTLINE(finder+1)) //at the end of stream + break; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"\n",NULL,0); + #endif + while(WS(finder)) finder++; //jump whitespace + if (1!=sscanf(finder,"%d",&msgnr)) //message nr. + throw (DWORD)EPOP3_LIST; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%d\n",msgnr); + #endif + + for (i=1,queueptr=queue;(queueptr->Next!=NULL) && (iNext,i++); + if (i!=msgnr) + throw (DWORD)EPOP3_LIST; + while(!WS(finder)) finder++; //jump characters + while(WS(finder)) finder++; //jump whitespace + finderend=finder+1; + if (1!=sscanf(finder,"%d",&queueptr->MailData->Size)) + throw (DWORD)EPOP3_LIST; + #ifdef DEBUG_DECODE + DebugLog(DecodeFile,"%d\n",queueptr->MailData->Size); + #endif + while(!ENDLINE(finder)) finder++; + } +} + +TCHAR* WINAPI GetErrorString(DWORD Code) +{ + static TCHAR *POP3Errors[]= + { + LPGENT("Memory allocation error."), //memory allocation + LPGENT("Account is about to be stopped."), //stop account + LPGENT("Cannot connect to POP3 server."), + LPGENT("Cannot allocate memory for received data."), + LPGENT("Cannot login to POP3 server."), + LPGENT("Bad user or password."), + LPGENT("Server does not support APOP authorization."), + LPGENT("Error while executing POP3 command."), + LPGENT("Error while executing POP3 command."), + LPGENT("Error while executing POP3 command."), + }; + + static TCHAR *NetlibErrors[]= + { + LPGENT("Cannot connect to server with NetLib."), + LPGENT("Cannot send data."), + LPGENT("Cannot receive data."), + LPGENT("Cannot allocate memory for received data."), + }; + + static TCHAR *SSLErrors[]= + { + LPGENT("OpenSSL not loaded."), + LPGENT("Windows socket 2.0 init failed."), + LPGENT("DNS lookup error."), + LPGENT("Error while creating base socket."), + LPGENT("Error connecting to server with socket."), + LPGENT("Error while creating SSL structure."), + LPGENT("Error connecting socket with SSL."), + LPGENT("Server rejected connection with SSL."), + LPGENT("Cannot write SSL data."), + LPGENT("Cannot read SSL data."), + LPGENT("Cannot allocate memory for received data."), + }; + + TCHAR *ErrorString = new TCHAR[ERRORSTR_MAXLEN]; + POP3_ERRORCODE *ErrorCode=(POP3_ERRORCODE *)(UINT_PTR)Code; + + mir_sntprintf(ErrorString, ERRORSTR_MAXLEN, TranslateT("Error %d-%d-%d-%d:"),ErrorCode->AppError,ErrorCode->POP3Error,ErrorCode->NetError,ErrorCode->SystemError); + if (ErrorCode->POP3Error) + mir_sntprintf(ErrorString, ERRORSTR_MAXLEN, _T("%s\n%s"),ErrorString,TranslateTS(POP3Errors[ErrorCode->POP3Error-1])); + if (ErrorCode->NetError) { + if (ErrorCode->SSL) + mir_sntprintf(ErrorString, ERRORSTR_MAXLEN, _T("%s\n%s"),ErrorString, TranslateTS(SSLErrors[ErrorCode->NetError-1])); + else + mir_sntprintf(ErrorString, ERRORSTR_MAXLEN, _T("%s\n%s"),ErrorString, TranslateTS(NetlibErrors[ErrorCode->NetError-4])); + } + + return ErrorString; +} + +void WINAPI DeleteErrorString(LPVOID String) +{ + delete (char *)String; +} diff --git a/protocols/YAMN/src/proto/pop3/pop3comm.h b/protocols/YAMN/src/proto/pop3/pop3comm.h new file mode 100644 index 0000000000..c7eb01b5a1 --- /dev/null +++ b/protocols/YAMN/src/proto/pop3/pop3comm.h @@ -0,0 +1,97 @@ +#ifndef __POP3COMM_H +#define __POP3COMM_H + +#include +#include "pop3.h" + +#include "m_protoplugin.h" +//We can use synchro.h because this is internal plugin. If you use external plugin, +//and you want to use SO for your plugin, you can use YAMN's SO. +//All you need is to include synchro.h and use YAMN's exported synchronization functions. +#include "m_synchro.h" + +//For mail exported functions defintions +#include "m_mails.h" + +#include "../../debug.h" + +#define POP3_FILEVERSION 1 //Version of aditional information stored in book file + +typedef struct CPOP3Account: public CAccount +{ +// We can use SCOUNTER structure, because this is internal plugin. +// This SO is used to determine if any POP3 account is in "write access" mode + static PSCOUNTER AccountWriterSO; + +// It is usefull to have client structure in account. With this structure we have access to account's socket. +// This is related to InternetQueries and UseInternetFree +// This member should be synchronized with UseInternetFree + class CPop3Client Client; + +// This member is usefull for MIME headers. It is default codepage, if no other codepage found + WORD CP; //access only through AccountAccessSO + +// In this memeber last error code is stored + DWORD SystemError; //access through UseInternetFree + +// We use only counter from this object and it is # of threads waiting to work on internet. +// We use event UseInternet to access critical sections. +// It is usefull in 2 ways: we have mutual exclusion that only one thread works with account on internet. +// Thread, which has done its work with account on internet can close socket, but it is not needed, when any other +// thread wants to work (e.g. we have deleted mails, but when deleting, another thread wants to check new mail, so +// we delete all needed mails and check if there's thread that wants to work. If yes, we do not need to quit session, +// we leave socket open, and leave internet. Another thread then start checking and does not connect, does not send +// user and password... because socket is open- it continues) + PSCOUNTER InternetQueries; + HANDLE UseInternetFree; + + CPOP3Account(); + ~CPOP3Account(); + +} POP3ACCOUNT,*HPOP3ACCOUNT; + +typedef struct POP3LayeredError +{ + BOOL SSL; + DWORD AppError; + DWORD POP3Error; + DWORD NetError; + DWORD SystemError; +} POP3_ERRORCODE,*PPOP3_ERRORCODE; + +struct YAMNExportedFcns +{ + YAMN_SETPROTOCOLPLUGINFCNIMPORTFCN SetProtocolPluginFcnImportFcn; + YAMN_WAITTOWRITEFCN WaitToWriteFcn; + YAMN_WRITEDONEFCN WriteDoneFcn; + YAMN_WAITTOREADFCN WaitToReadFcn; + YAMN_READDONEFCN ReadDoneFcn; + YAMN_SCMANAGEFCN SCGetNumberFcn; + YAMN_SCMANAGEFCN SCIncFcn; + YAMN_SCMANAGEFCN SCDecFcn; + YAMN_SETSTATUSFCN SetStatusFcn; + YAMN_GETSTATUSFCN GetStatusFcn; +}; + +struct MailExportedFcns +{ + YAMN_SYNCHROMIMEMSGSFCN SynchroMessagesFcn; + YAMN_TRANSLATEHEADERFCN TranslateHeaderFcn; + YAMN_APPENDQUEUEFCN AppendQueueFcn; + YAMN_DELETEMIMEQUEUEFCN DeleteMessagesToEndFcn; + YAMN_DELETEMIMEMESSAGEFCN DeleteMessageFromQueueFcn; + YAMN_FINDMIMEMESSAGEFCN FindMessageByIDFcn; + YAMN_CREATENEWDELETEQUEUEFCN CreateNewDeleteQueueFcn; +}; + +enum +{ + EACC_QUEUEALLOC=1, //memory allocation + EACC_STOPPED, //stop account +}; + +#define NO_MAIL_FOR_DELETE 1 + +#define POP3_DELETEFROMCHECK 1 + +#endif diff --git a/protocols/YAMN/src/proto/pop3/pop3opt.cpp b/protocols/YAMN/src/proto/pop3/pop3opt.cpp new file mode 100644 index 0000000000..1a265a0800 --- /dev/null +++ b/protocols/YAMN/src/proto/pop3/pop3opt.cpp @@ -0,0 +1,1556 @@ +/* + * This code implements POP3 options window handling + * + * (c) majvan 2002-2003 +*/ + +#include "../../yamn.h" +#include "../../main.h" +#include "pop3comm.h" +#include "pop3opt.h" + +//-------------------------------------------------------------------------------------------------- + +static BOOL Check0,Check1,Check2,Check3,Check4,Check5,Check6,Check7,Check8,Check9; +static char DlgInput[MAX_PATH]; + +void CheckMenuItems(); + +//-------------------------------------------------------------------------------------------------- + +INT_PTR CALLBACK DlgProcYAMNOpt(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch(msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hDlg); + CheckDlgButton(hDlg,IDC_CHECKTTB,DBGetContactSettingByte(NULL,YAMN_DBMODULE,YAMN_TTBFCHECK,1) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_LONGDATE,(optDateTime&SHOWDATELONG) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_SMARTDATE,(optDateTime&SHOWDATENOTODAY) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_NOSECONDS,(optDateTime&SHOWDATENOSECONDS) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_MAINMENU,DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWMAINMENU, 1)); + CheckDlgButton(hDlg,IDC_YAMNASPROTO,DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWASPROTO, 1)); + CheckDlgButton(hDlg,IDC_CLOSEONDELETE,DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_CLOSEDELETE, 0)); + break; + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_YAMNASPROTO: + case IDC_MAINMENU: + case IDC_CHECKTTB: + case IDC_CLOSEONDELETE: + case IDC_LONGDATE: + case IDC_SMARTDATE: + case IDC_NOSECONDS: + SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); + break; + } + break; + + case WM_NOTIFY: + switch(((LPNMHDR)lParam)->idFrom) { + case 0: + switch(((LPNMHDR)lParam)->code) { + case PSN_APPLY: + DBWriteContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWASPROTO, IsDlgButtonChecked(hDlg,IDC_YAMNASPROTO)); + DBWriteContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWMAINMENU, IsDlgButtonChecked(hDlg,IDC_MAINMENU)); + DBWriteContactSettingByte(NULL, YAMN_DBMODULE, YAMN_CLOSEDELETE, IsDlgButtonChecked(hDlg,IDC_CLOSEONDELETE)); + DBWriteContactSettingByte(NULL, YAMN_DBMODULE, YAMN_TTBFCHECK, IsDlgButtonChecked(hDlg,IDC_CHECKTTB)); + + AddTopToolbarIcon(0, 0); + CheckMenuItems(); + + optDateTime = 0; + if (IsDlgButtonChecked(hDlg,IDC_LONGDATE))optDateTime |= SHOWDATELONG; + if (IsDlgButtonChecked(hDlg,IDC_SMARTDATE))optDateTime |= SHOWDATENOTODAY; + if (IsDlgButtonChecked(hDlg,IDC_NOSECONDS))optDateTime |= SHOWDATENOSECONDS; + DBWriteContactSettingByte(NULL,YAMN_DBMODULE,YAMN_DBTIMEOPTIONS,optDateTime); + } + } + break; + } + + return FALSE; +} + +INT_PTR CALLBACK DlgProcPluginOpt(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch(msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hDlg); + break; + + case WM_COMMAND: + { + WORD wNotifyCode = HIWORD(wParam); + switch(LOWORD(wParam)) + { + case IDC_COMBOPLUGINS: + if (wNotifyCode==CBN_SELCHANGE) + { + HWND hCombo=GetDlgItem(hDlg,IDC_COMBOPLUGINS); + PYAMN_PROTOPLUGINQUEUE PParser; + PYAMN_FILTERPLUGINQUEUE FParser; + int index,id; + + if (CB_ERR==(index=SendMessage(hCombo,CB_GETCURSEL,0,0))) + break; + id=SendMessage(hCombo,CB_GETITEMDATA,(WPARAM)index,(LPARAM)0); + EnterCriticalSection(&PluginRegCS); + for (PParser=FirstProtoPlugin;PParser!=NULL;PParser=PParser->Next) + if (id==(INT_PTR)PParser->Plugin) + { + SetDlgItemTextA(hDlg,IDC_STVER,PParser->Plugin->PluginInfo->Ver); + SetDlgItemTextA(hDlg,IDC_STDESC,PParser->Plugin->PluginInfo->Description == NULL ? "" : PParser->Plugin->PluginInfo->Description); + SetDlgItemTextA(hDlg,IDC_STCOPY,PParser->Plugin->PluginInfo->Copyright == NULL ? "" : PParser->Plugin->PluginInfo->Copyright); + SetDlgItemTextA(hDlg,IDC_STMAIL,PParser->Plugin->PluginInfo->Email == NULL ? "" : PParser->Plugin->PluginInfo->Email); + SetDlgItemTextA(hDlg,IDC_STWWW,PParser->Plugin->PluginInfo->WWW == NULL ? "" : PParser->Plugin->PluginInfo->WWW); + break; + } + for (FParser=FirstFilterPlugin;FParser!=NULL;FParser=FParser->Next) + if (id==(INT_PTR)FParser->Plugin) + { + SetDlgItemTextA(hDlg,IDC_STVER,FParser->Plugin->PluginInfo->Ver); + SetDlgItemTextA(hDlg,IDC_STDESC,FParser->Plugin->PluginInfo->Description == NULL ? "" : FParser->Plugin->PluginInfo->Description); + SetDlgItemTextA(hDlg,IDC_STCOPY,FParser->Plugin->PluginInfo->Copyright == NULL ? "" : FParser->Plugin->PluginInfo->Copyright); + SetDlgItemTextA(hDlg,IDC_STMAIL,FParser->Plugin->PluginInfo->Email == NULL ? "" : FParser->Plugin->PluginInfo->Email); + SetDlgItemTextA(hDlg,IDC_STWWW,FParser->Plugin->PluginInfo->WWW == NULL ? "" : FParser->Plugin->PluginInfo->WWW); + break; + } + LeaveCriticalSection(&PluginRegCS); + } + break; + case IDC_STWWW: + { + char str[1024]; + GetDlgItemTextA(hDlg,IDC_STWWW,str,SIZEOF(str)); + CallService(MS_UTILS_OPENURL,1,(LPARAM)str); + break; + } + + } + break; + } + case WM_SHOWWINDOW: + if (TRUE==(BOOL)wParam) { + PYAMN_PROTOPLUGINQUEUE PParser; + PYAMN_FILTERPLUGINQUEUE FParser; + int index; + + EnterCriticalSection(&PluginRegCS); + for (PParser = FirstProtoPlugin; PParser != NULL; PParser = PParser->Next) { + index = SendDlgItemMessageA(hDlg,IDC_COMBOPLUGINS,CB_ADDSTRING,0,(LPARAM)PParser->Plugin->PluginInfo->Name); + index = SendDlgItemMessage(hDlg,IDC_COMBOPLUGINS,CB_SETITEMDATA,(WPARAM)index,(LPARAM)PParser->Plugin); + } + for (FParser = FirstFilterPlugin; FParser != NULL; FParser = FParser->Next) { + index = SendDlgItemMessageA(hDlg,IDC_COMBOPLUGINS,CB_ADDSTRING,0,(LPARAM)FParser->Plugin->PluginInfo->Name); + index = SendDlgItemMessage(hDlg,IDC_COMBOPLUGINS,CB_SETITEMDATA,(WPARAM)index,(LPARAM)FParser->Plugin); + } + + LeaveCriticalSection(&PluginRegCS); + SendDlgItemMessage(hDlg,IDC_COMBOPLUGINS,CB_SETCURSEL,(WPARAM)0,(LPARAM)0); + SendMessage(hDlg,WM_COMMAND,MAKELONG(IDC_COMBOPLUGINS,CBN_SELCHANGE),(LPARAM)NULL); + break; + } + else { //delete all items in combobox + int cbn=SendDlgItemMessage(hDlg,IDC_COMBOPLUGINS,CB_GETCOUNT,(WPARAM)0,(LPARAM)0); + for (int i=0;iStatusFlags & YAMN_ACC_ST0 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST1,ActualAccount->StatusFlags & YAMN_ACC_ST1 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST2,ActualAccount->StatusFlags & YAMN_ACC_ST2 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST3,ActualAccount->StatusFlags & YAMN_ACC_ST3 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST4,ActualAccount->StatusFlags & YAMN_ACC_ST4 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST5,ActualAccount->StatusFlags & YAMN_ACC_ST5 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST6,ActualAccount->StatusFlags & YAMN_ACC_ST6 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST7,ActualAccount->StatusFlags & YAMN_ACC_ST7 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST8,ActualAccount->StatusFlags & YAMN_ACC_ST8 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST9,ActualAccount->StatusFlags & YAMN_ACC_ST9 ? BST_CHECKED : BST_UNCHECKED); + ReadDone(ActualAccount); + } + else + { + CheckDlgButton(hDlg,IDC_CHECKST0,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST1,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST2,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST3,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST4,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST5,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST6,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST7,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST8,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST9,BST_CHECKED); + } + return TRUE; +} +BOOL DlgShowAccountPopup(HWND hDlg,WPARAM wParam,LPARAM lParam) +{ + HPOP3ACCOUNT ActualAccount=(HPOP3ACCOUNT)lParam; + + if ((DWORD)wParam==M_SHOWACTUAL) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read wait\n"); + #endif + WaitToRead(ActualAccount); //we do not need to check if account is deleted. It is not deleted, because only thread that can delete account is this thread + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read enter\n"); + #endif + SetDlgItemInt(hDlg,IDC_EDITPOPS,ActualAccount->NewMailN.PopUpTime,FALSE); + SetDlgItemInt(hDlg,IDC_EDITNPOPS,ActualAccount->NoNewMailN.PopUpTime,FALSE); + SetDlgItemInt(hDlg,IDC_EDITFPOPS,ActualAccount->BadConnectN.PopUpTime,FALSE); + + + CheckDlgButton(hDlg,IDC_CHECKPOP,ActualAccount->NewMailN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKCOL,ActualAccount->NewMailN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKNPOP,ActualAccount->NoNewMailN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKNCOL,ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFPOP,ActualAccount->BadConnectN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFCOL,ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_RADIOPOPN,ActualAccount->Flags & YAMN_ACC_POPN ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_RADIOPOP1,ActualAccount->Flags & YAMN_ACC_POPN ? BST_UNCHECKED : BST_CHECKED); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read done\n"); + #endif + ReadDone(ActualAccount); + } + else //default + { + + SetDlgItemInt(hDlg,IDC_EDITPOPS,0,FALSE); + SetDlgItemInt(hDlg,IDC_EDITNPOPS,0,FALSE); + SetDlgItemInt(hDlg,IDC_EDITFPOPS,0,FALSE); + CheckDlgButton(hDlg,IDC_CHECKPOP,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKCOL,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKNPOP,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKNCOL,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKFPOP,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKFCOL,BST_CHECKED); + CheckDlgButton(hDlg,IDC_RADIOPOPN,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_RADIOPOP1,BST_CHECKED); + } + return TRUE; +} +BOOL DlgShowAccount(HWND hDlg,WPARAM wParam,LPARAM lParam) +{ + HPOP3ACCOUNT ActualAccount=(HPOP3ACCOUNT)lParam; + int i; + + if ((DWORD)wParam==M_SHOWACTUAL) + { + TCHAR accstatus[256]; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read wait\n"); + #endif + WaitToRead(ActualAccount); //we do not need to check if account is deleted. It is not deleted, because only thread that can delete account is this thread + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read enter\n"); + #endif + DlgSetItemText(hDlg, IDC_EDITSERVER, ActualAccount->Server->Name); + DlgSetItemText(hDlg, IDC_EDITNAME, ActualAccount->Name); + DlgSetItemText(hDlg, IDC_EDITLOGIN, ActualAccount->Server->Login); + DlgSetItemText(hDlg, IDC_EDITPASS, ActualAccount->Server->Passwd); + DlgSetItemTextW(hDlg, IDC_EDITAPP, ActualAccount->NewMailN.App); + DlgSetItemTextW(hDlg, IDC_EDITAPPPARAM, ActualAccount->NewMailN.AppParam); + SetDlgItemInt(hDlg,IDC_EDITPORT,ActualAccount->Server->Port,FALSE); + SetDlgItemInt(hDlg,IDC_EDITINTERVAL,ActualAccount->Interval/60,FALSE); + SetDlgItemInt(hDlg,IDC_EDITPOPS,ActualAccount->NewMailN.PopUpTime,FALSE); + SetDlgItemInt(hDlg,IDC_EDITNPOPS,ActualAccount->NoNewMailN.PopUpTime,FALSE); + SetDlgItemInt(hDlg,IDC_EDITFPOPS,ActualAccount->BadConnectN.PopUpTime,FALSE); + for (i=0;i<=CPLENSUPP;i++) + if ((iCP)) + { + SendMessage(GetDlgItem(hDlg,IDC_COMBOCP),CB_SETCURSEL,(WPARAM)i,(LPARAM)0); + break; + } + if (i==CPLENSUPP) + SendMessage(GetDlgItem(hDlg,IDC_COMBOCP),CB_SETCURSEL,(WPARAM)CPDEFINDEX,(LPARAM)0); + + CheckDlgButton(hDlg,IDC_CHECK,ActualAccount->Flags & YAMN_ACC_ENA ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKSND,ActualAccount->NewMailN.Flags & YAMN_ACC_SND ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKMSG,ActualAccount->NewMailN.Flags & YAMN_ACC_MSG ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKICO,ActualAccount->NewMailN.Flags & YAMN_ACC_ICO ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKPOP,ActualAccount->NewMailN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKCOL,ActualAccount->NewMailN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKAPP,ActualAccount->NewMailN.Flags & YAMN_ACC_APP ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKKBN,ActualAccount->NewMailN.Flags & YAMN_ACC_KBN ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKNPOP,ActualAccount->NoNewMailN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKNCOL,ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKNMSGP,ActualAccount->NoNewMailN.Flags & YAMN_ACC_MSGP ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFSND,ActualAccount->BadConnectN.Flags & YAMN_ACC_SND ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFMSG,ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFICO,ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFPOP,ActualAccount->BadConnectN.Flags & YAMN_ACC_POP ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFCOL,ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_RADIOPOPN,ActualAccount->Flags & YAMN_ACC_POPN ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_RADIOPOP1,ActualAccount->Flags & YAMN_ACC_POPN ? BST_UNCHECKED : BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKSSL,ActualAccount->Flags & YAMN_ACC_SSL23 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKNOTLS,ActualAccount->Flags & YAMN_ACC_NOTLS ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKAPOP,ActualAccount->Flags & YAMN_ACC_APOP ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_AUTOBODY,ActualAccount->Flags & YAMN_ACC_BODY ? BST_CHECKED : BST_UNCHECKED); + /*CheckDlgButton(hDlg,IDC_CHECKST0,ActualAccount->StatusFlags & YAMN_ACC_ST0 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST1,ActualAccount->StatusFlags & YAMN_ACC_ST1 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST2,ActualAccount->StatusFlags & YAMN_ACC_ST2 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST3,ActualAccount->StatusFlags & YAMN_ACC_ST3 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST4,ActualAccount->StatusFlags & YAMN_ACC_ST4 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST5,ActualAccount->StatusFlags & YAMN_ACC_ST5 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST6,ActualAccount->StatusFlags & YAMN_ACC_ST6 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST7,ActualAccount->StatusFlags & YAMN_ACC_ST7 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST8,ActualAccount->StatusFlags & YAMN_ACC_ST8 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST9,ActualAccount->StatusFlags & YAMN_ACC_ST9 ? BST_CHECKED : BST_UNCHECKED);*/ + Check0=ActualAccount->StatusFlags & YAMN_ACC_ST0; + Check1=ActualAccount->StatusFlags & YAMN_ACC_ST1; + Check2=ActualAccount->StatusFlags & YAMN_ACC_ST2; + Check3=ActualAccount->StatusFlags & YAMN_ACC_ST3; + Check4=ActualAccount->StatusFlags & YAMN_ACC_ST4; + Check5=ActualAccount->StatusFlags & YAMN_ACC_ST5; + Check6=ActualAccount->StatusFlags & YAMN_ACC_ST6; + Check7=ActualAccount->StatusFlags & YAMN_ACC_ST7; + Check8=ActualAccount->StatusFlags & YAMN_ACC_ST8; + Check9=ActualAccount->StatusFlags & YAMN_ACC_ST9; + CheckDlgButton(hDlg,IDC_CHECKSTART,ActualAccount->StatusFlags & YAMN_ACC_STARTS ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFORCE,ActualAccount->StatusFlags & YAMN_ACC_FORCE ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKCONTACT,ActualAccount->NewMailN.Flags & YAMN_ACC_CONT ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKCONTACTNICK,ActualAccount->NewMailN.Flags & YAMN_ACC_CONTNICK ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKCONTACTNOEVENT,ActualAccount->NewMailN.Flags & YAMN_ACC_CONTNOEVENT ? BST_CHECKED : BST_UNCHECKED); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:SHOWACCOUNT:ActualAccountSO-read done\n"); +#endif + GetAccountStatus(ActualAccount,accstatus); + SetDlgItemText(hDlg,IDC_STSTATUS,accstatus); + ReadDone(ActualAccount); + } + else //default + { + DlgSetItemText(hDlg,(WPARAM)IDC_EDITSERVER,(LPARAM)NULL); + DlgSetItemText(hDlg,(WPARAM)IDC_EDITNAME,(LPARAM)NULL); + DlgSetItemText(hDlg,(WPARAM)IDC_EDITLOGIN,(LPARAM)NULL); + DlgSetItemText(hDlg,(WPARAM)IDC_EDITPASS,(LPARAM)NULL); + DlgSetItemText(hDlg,(WPARAM)IDC_EDITAPP,(LPARAM)NULL); + DlgSetItemText(hDlg,(WPARAM)IDC_EDITAPPPARAM,(LPARAM)NULL); + DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); + SetDlgItemInt(hDlg,IDC_EDITPORT,110,FALSE); + SetDlgItemInt(hDlg,IDC_EDITINTERVAL,30,FALSE); + SetDlgItemInt(hDlg,IDC_EDITPOPS,0,FALSE); + SetDlgItemInt(hDlg,IDC_EDITNPOPS,0,FALSE); + SetDlgItemInt(hDlg,IDC_EDITFPOPS,0,FALSE); + SendMessage(GetDlgItem(hDlg,IDC_COMBOCP),CB_SETCURSEL,(WPARAM)CPDEFINDEX,(LPARAM)0); + CheckDlgButton(hDlg,IDC_CHECK,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKSND,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKMSG,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKICO,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKPOP,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKCOL,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKAPP,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKPOP,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKCOL,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKFSND,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFMSG,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFICO,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKFPOP,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKFCOL,BST_CHECKED); + /*CheckDlgButton(hDlg,IDC_CHECKST0,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST1,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST2,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST3,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST4,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST5,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST6,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKST7,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST8,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST9,BST_CHECKED);*/ + CheckDlgButton(hDlg,IDC_CHECKSTART,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKFORCE,BST_CHECKED); + CheckDlgButton(hDlg,IDC_RADIOPOPN,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_RADIOPOP1,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKSSL,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKNOTLS,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKAPOP,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_AUTOBODY,BST_UNCHECKED); + CheckDlgButton(hDlg,IDC_CHECKCONTACT,BST_CHECKED); + + SetDlgItemText(hDlg,IDC_STSTATUS,TranslateT("No account selected")); + } + return TRUE; +} + +BOOL DlgShowAccountColors(HWND hDlg,WPARAM wParam,LPARAM lParam) +{ + HPOP3ACCOUNT ActualAccount=(HPOP3ACCOUNT)lParam; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:SHOWACCOUNTCOLORS:ActualAccountSO-read wait\n"); +#endif + WaitToRead(ActualAccount); //we do not need to check if account is deleted. It is not deleted, because only thread that can delete account is this thread +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:SHOWACCOUNTCOLORS:ActualAccountSO-read enter\n"); +#endif + if (ActualAccount->NewMailN.Flags & YAMN_ACC_POPC) + { + SendDlgItemMessage(hDlg,IDC_CPB,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->NewMailN.PopUpB); + SendDlgItemMessage(hDlg,IDC_CPT,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->NewMailN.PopUpT); + } + else + { + SendDlgItemMessage(hDlg,IDC_CPB,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_BTNFACE)); + SendDlgItemMessage(hDlg,IDC_CPT,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_WINDOWTEXT)); + } + if (ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC) + { + SendDlgItemMessage(hDlg,IDC_CPFB,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->BadConnectN.PopUpB); + SendDlgItemMessage(hDlg,IDC_CPFT,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->BadConnectN.PopUpT); + } + else + { + SendDlgItemMessage(hDlg,IDC_CPFB,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_BTNFACE)); + SendDlgItemMessage(hDlg,IDC_CPFT,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_WINDOWTEXT)); + } + if (ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC) + { + SendDlgItemMessage(hDlg,IDC_CPNB,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->NoNewMailN.PopUpB); + SendDlgItemMessage(hDlg,IDC_CPNT,CPM_SETCOLOUR,0,(LPARAM)ActualAccount->NoNewMailN.PopUpT); + } + else + { + SendDlgItemMessage(hDlg,IDC_CPNB,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_BTNFACE)); + SendDlgItemMessage(hDlg,IDC_CPNT,CPM_SETCOLOUR,0,(LPARAM)GetSysColor(COLOR_WINDOWTEXT)); + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:SHOWACCOUNTCOLORS:ActualAccountSO-read done\n"); +#endif + ReadDone(ActualAccount); //we do not need to check if account is deleted. It is not deleted, because only thread that can delete account is this thread + return TRUE; +} + +BOOL DlgSetItemText(HWND hDlg, WPARAM wParam,const char* str) +{ + if (str == NULL) + SetDlgItemTextA(hDlg, wParam, ""); + else + SetDlgItemTextA(hDlg, wParam, str); + return TRUE; +} + +BOOL DlgSetItemTextW(HWND hDlg,WPARAM wParam,const WCHAR* str) +{ + if (str == NULL) + SetDlgItemTextW(hDlg, wParam, L""); + else + SetDlgItemTextW(hDlg, wParam, str); + return TRUE; +} + +INT_PTR CALLBACK DlgProcPOP3AccStatusOpt(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + static HPOP3ACCOUNT ActualAccount; + switch(msg) + { + case WM_INITDIALOG: + { + ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput); + if (ActualAccount != NULL) + { + DlgShowAccountStatus(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); + DlgEnableAccountStatus(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); + } + else + { + CheckDlgButton(hDlg,IDC_CHECKST0,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST1,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST2,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST3,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST4,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST5,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST6,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST7,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST8,BST_CHECKED); + CheckDlgButton(hDlg,IDC_CHECKST9,BST_CHECKED); + } + TranslateDialogDefault(hDlg); + SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,0); + return TRUE; + break; + } + case WM_COMMAND: + { + + WORD wNotifyCode = HIWORD(wParam); + switch(LOWORD(wParam)) + { + case IDOK: + Check0 = (IsDlgButtonChecked(hDlg,IDC_CHECKST0)==BST_CHECKED); + Check1 = (IsDlgButtonChecked(hDlg,IDC_CHECKST1)==BST_CHECKED); + Check2 = (IsDlgButtonChecked(hDlg,IDC_CHECKST2)==BST_CHECKED); + Check3 = (IsDlgButtonChecked(hDlg,IDC_CHECKST3)==BST_CHECKED); + Check4 = (IsDlgButtonChecked(hDlg,IDC_CHECKST4)==BST_CHECKED); + Check5 = (IsDlgButtonChecked(hDlg,IDC_CHECKST5)==BST_CHECKED); + Check6 = (IsDlgButtonChecked(hDlg,IDC_CHECKST6)==BST_CHECKED); + Check7 = (IsDlgButtonChecked(hDlg,IDC_CHECKST7)==BST_CHECKED); + Check8 = (IsDlgButtonChecked(hDlg,IDC_CHECKST8)==BST_CHECKED); + Check9 = (IsDlgButtonChecked(hDlg,IDC_CHECKST9)==BST_CHECKED); + WindowList_BroadcastAsync(YAMNVar.MessageWnds,WM_YAMN_CHANGESTATUSOPTION,(WPARAM)0,(LPARAM)0); + EndDialog(hDlg,0); + DestroyWindow(hDlg); + break; + + case IDCANCEL: + EndDialog(hDlg,0); + DestroyWindow(hDlg); + break; + + default: + break; + } + } + default: + break; + } + return FALSE; +} + + +INT_PTR CALLBACK DlgProcPOP3AccOpt(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + BOOL Changed=FALSE; + INT_PTR Result; + static BOOL InList=FALSE; + static HPOP3ACCOUNT ActualAccount; + static UCHAR ActualStatus; +// static struct CPOP3Options POP3Options; + + switch(msg) + { + case WM_INITDIALOG: + { + int i; + + EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); + + DlgEnableAccount(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); + DlgShowAccount(hDlg,(WPARAM)M_SHOWDEFAULT,0); + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read wait\n"); + #endif + WaitToReadSO(POP3Plugin->AccountBrowserSO); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read enter\n"); + #endif + + for (ActualAccount=(HPOP3ACCOUNT)POP3Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=(HPOP3ACCOUNT)ActualAccount->Next) + if (ActualAccount->Name != NULL) + SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_ADDSTRING,0,(LPARAM)ActualAccount->Name); + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read done\n"); + #endif + ReadDoneSO(POP3Plugin->AccountBrowserSO); + SendDlgItemMessage(hDlg, IDC_COMBOCP, CB_ADDSTRING, 0, (LPARAM)TranslateT("Default")); + for (i=1; i < CPLENSUPP; i++) { + CPINFOEX info; GetCPInfoEx(CodePageNamesSupp[i].CP,0,&info); + size_t len = lstrlen(info.CodePageName+7); + info.CodePageName[len+6]=0; + SendDlgItemMessage(hDlg,IDC_COMBOCP,CB_ADDSTRING,0,(LPARAM)(info.CodePageName+7)); + } + + SendMessage(GetDlgItem(hDlg,IDC_COMBOCP),CB_SETCURSEL,(WPARAM)CPDEFINDEX,(LPARAM)0); + ActualAccount=NULL; + TranslateDialogDefault(hDlg); + SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,0); + return TRUE; + } + + case WM_SHOWWINDOW: + if ( wParam == FALSE) { + WindowList_Remove(pYAMNVar->MessageWnds,hDlg); + SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,(LPARAM)0); + } + else WindowList_Add(pYAMNVar->MessageWnds,hDlg,NULL); + return TRUE; + + case WM_YAMN_CHANGESTATUS: + if ((HPOP3ACCOUNT)wParam == ActualAccount) { + TCHAR accstatus[256]; + GetAccountStatus(ActualAccount,accstatus); + SetDlgItemText(hDlg,IDC_STSTATUS,accstatus); + return TRUE; + } + break; + + case WM_YAMN_CHANGESTATUSOPTION: + Changed=TRUE; + SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); + return TRUE; + + case WM_YAMN_CHANGETIME: + if ((HPOP3ACCOUNT)wParam == ActualAccount) { + TCHAR Text[256]; + mir_sntprintf(Text,SIZEOF(Text),TranslateT("Time left to next check [s]: %d"),(DWORD)lParam); + SetDlgItemText(hDlg,IDC_STTIMELEFT,Text); + } + return TRUE; + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_COMBOACCOUNT: + switch( HIWORD(wParam)) { + case CBN_EDITCHANGE : + ActualAccount=NULL; + DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); + + if (GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT,DlgInput,sizeof(DlgInput))) + DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)FALSE); + else + DlgEnableAccount(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); + break; + + case CBN_KILLFOCUS: + GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT,DlgInput,sizeof(DlgInput)); + if (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput))) { + DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); + EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); + if (lstrlenA(DlgInput)) + DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); + else + DlgEnableAccount(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); + } + else { + DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); + DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); + EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),TRUE); + } + break; + + case CBN_SELCHANGE: + if (CB_ERR!=(Result=SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,0,0))) + SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_GETLBTEXT,(WPARAM)Result,(LPARAM)DlgInput); + + if ((Result==CB_ERR) || (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput)))) { + DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); + EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); + } + else { + DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); + DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)FALSE); + EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),TRUE); + } + break; + } + break; + + case IDC_COMBOCP: + { + int sel = SendDlgItemMessage(hDlg,IDC_COMBOCP,CB_GETCURSEL,0,0); + CPINFOEX info; GetCPInfoEx(CodePageNamesSupp[sel].CP,0,&info); + DlgSetItemTextT(hDlg, IDC_STSTATUS, info.CodePageName); + } + case IDC_CHECK: + case IDC_CHECKSND: + case IDC_CHECKMSG: + case IDC_CHECKICO: + case IDC_CHECKFSND: + case IDC_CHECKFMSG: + case IDC_CHECKFICO: + case IDC_CHECKST0: + case IDC_CHECKST1: + case IDC_CHECKST2: + case IDC_CHECKST3: + case IDC_CHECKST4: + case IDC_CHECKST5: + case IDC_CHECKST6: + case IDC_CHECKST7: + case IDC_CHECKST8: + case IDC_CHECKST9: + case IDC_CHECKSTART: + case IDC_CHECKFORCE: + case IDC_EDITAPPPARAM: + case IDC_CHECKAPOP: + case IDC_AUTOBODY: + case IDC_CHECKCONTACTNICK: + case IDC_CHECKCONTACTNOEVENT: + case IDC_CHECKNOTLS: + Changed=TRUE; + break; + + case IDC_CHECKCONTACT: + Changed=IsDlgButtonChecked(hDlg,IDC_CHECKCONTACT)==BST_CHECKED; + EnableWindow(GetDlgItem(hDlg,IDC_CHECKCONTACTNICK),Changed); + EnableWindow(GetDlgItem(hDlg,IDC_CHECKCONTACTNOEVENT),Changed); + Changed=TRUE; + break; + + case IDC_CHECKSSL: + { + BOOL SSLC = (IsDlgButtonChecked(hDlg,IDC_CHECKSSL)==BST_CHECKED); + SetDlgItemInt(hDlg,IDC_EDITPORT,SSLC ? 995 : 110,FALSE); + EnableWindow(GetDlgItem(hDlg,IDC_CHECKNOTLS),SSLC?0:1); + } + Changed=TRUE; + break; + + case IDC_CPB: + case IDC_CPT: + case IDC_CPFB: + case IDC_CPFT: + case IDC_CPNB: + case IDC_CPNT: + if (HIWORD(wParam)!=CPN_COLOURCHANGED) + break; + + case IDC_CHECKKBN: + Changed=TRUE; + break; + + case IDC_CHECKAPP: + Changed=TRUE; + EnableWindow(GetDlgItem(hDlg,IDC_BTNAPP),IsDlgButtonChecked(hDlg,IDC_CHECKAPP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_EDITAPP),IsDlgButtonChecked(hDlg,IDC_CHECKAPP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_EDITAPPPARAM),IsDlgButtonChecked(hDlg,IDC_CHECKAPP)==BST_CHECKED); + break; + + case IDC_BTNSTATUS: + DialogBoxParamW(pYAMNVar->hInst,MAKEINTRESOURCEW(IDD_CHOOSESTATUSMODES),hDlg,DlgProcPOP3AccStatusOpt,NULL); + break; + + case IDC_BTNADD: + DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); + DlgShowAccount(hDlg,(WPARAM)M_SHOWDEFAULT,0); + DlgEnableAccount(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); + EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); + DlgSetItemTextT(hDlg, IDC_EDITNAME, TranslateT("New Account")); + { + int index = SendDlgItemMessage(hDlg, IDC_COMBOACCOUNT, CB_ADDSTRING, 0, (LPARAM)TranslateT("New Account")); + if ( index != CB_ERR && index != CB_ERRSPACE ) + SendDlgItemMessage(hDlg, IDC_COMBOACCOUNT, CB_SETCURSEL, index, (LPARAM)TranslateT("New Account")); + } + break; + + case IDC_BTNAPP: + { + TCHAR filter[MAX_PATH]; + mir_sntprintf(filter, SIZEOF(filter), _T("%s (*.exe;*.bat;*.cmd;*.com)%c*.exe;*.bat;*.cmd;*.com%c%s (*.*)%c*.*%c"), + TranslateT("Executables"), 0, 0, TranslateT("All Files"), 0, 0); + + OPENFILENAME OFNStruct = { 0 }; + OFNStruct.lStructSize = sizeof(OPENFILENAME); + OFNStruct.hwndOwner = hDlg; + OFNStruct.lpstrFilter= filter; + OFNStruct.nFilterIndex=1; + OFNStruct.nMaxFile=MAX_PATH; + OFNStruct.lpstrFile=new TCHAR[MAX_PATH]; + OFNStruct.lpstrFile[0]=(TCHAR)0; + OFNStruct.lpstrTitle=TranslateT("Select executable used for notification"); + OFNStruct.Flags=OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR; + if (!GetOpenFileName(&OFNStruct)) + { + if (CommDlgExtendedError()) + MessageBox(hDlg,_T("Dialog box error"),_T("Failed"),MB_OK); + } + else DlgSetItemTextT(hDlg, IDC_EDITAPP, OFNStruct.lpstrFile); + delete[] OFNStruct.lpstrFile; + } + break; + + case IDC_BTNDEFAULT: + DlgShowAccount(hDlg,(WPARAM)M_SHOWDEFAULT,0); + break; + + case IDC_BTNDEL: + GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT,DlgInput,sizeof(DlgInput)); + EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),FALSE); + if ((CB_ERR==(Result=SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,0,0))) + || (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput)))) + return TRUE; + + if (IDOK!=MessageBox(hDlg,TranslateT("Do you really want to delete this account?"),TranslateT("Delete account confirmation"),MB_OKCANCEL | MB_ICONWARNING)) + return TRUE; + + DlgSetItemTextT(hDlg, IDC_STTIMELEFT, TranslateT("Please wait while no account is in use.")); + + if (ActualAccount->hContact != NULL) + CallService(MS_DB_CONTACT_DELETE,(WPARAM)(HANDLE) ActualAccount->hContact, 0); + + CallService(MS_YAMN_DELETEACCOUNT,(WPARAM)POP3Plugin,(LPARAM)ActualAccount); + + //We can consider our account as deleted. + + SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_DELETESTRING,(WPARAM)Result,0); + DlgSetItemText(hDlg,(WPARAM)IDC_COMBOACCOUNT,(LPARAM)NULL); + DlgEnableAccount(hDlg,(WPARAM)FALSE,0); + DlgShowAccount(hDlg,(WPARAM)M_SHOWDEFAULT,0); + break; + + case IDC_BTNRESET: + if (ActualAccount != NULL) + ActualAccount->TimeLeft=ActualAccount->Interval; + return 1; + } + + if (HIWORD(wParam) == EN_CHANGE) + Changed = TRUE; + break; + + case WM_NOTIFY: + if (((LPNMHDR)lParam)->idFrom == 0 && ((LPNMHDR)lParam)->code == PSN_APPLY ) { + char Text[MAX_PATH]; + WCHAR TextW[MAX_PATH]; + BOOL Translated,NewAcc=FALSE,Check,CheckMsg,CheckSnd,CheckIco,CheckApp, CheckAPOP; + BOOL CheckNMsgP,CheckFMsg,CheckFSnd,CheckFIco; + BOOL CheckKBN, CheckContact,CheckContactNick,CheckContactNoEvent; + BOOL CheckSSL, CheckABody, CheckNoTLS; + //BOOL Check0,Check1,Check2,Check3,Check4,Check5,Check6,Check7,Check8,Check9, + BOOL CheckStart,CheckForce; + size_t Length,index; + UINT Port,Interval; + + if ( GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT, Text, sizeof(Text))) { + Check = (IsDlgButtonChecked(hDlg,IDC_CHECK)==BST_CHECKED); + CheckSSL = (IsDlgButtonChecked(hDlg,IDC_CHECKSSL)==BST_CHECKED); + CheckNoTLS = (IsDlgButtonChecked(hDlg,IDC_CHECKNOTLS)==BST_CHECKED); + CheckAPOP = (IsDlgButtonChecked(hDlg,IDC_CHECKAPOP)==BST_CHECKED); + + CheckABody = (IsDlgButtonChecked(hDlg,IDC_AUTOBODY)==BST_CHECKED); + CheckMsg = (IsDlgButtonChecked(hDlg,IDC_CHECKMSG)==BST_CHECKED); + CheckSnd = (IsDlgButtonChecked(hDlg,IDC_CHECKSND)==BST_CHECKED); + CheckIco = (IsDlgButtonChecked(hDlg,IDC_CHECKICO)==BST_CHECKED); + + CheckApp = (IsDlgButtonChecked(hDlg,IDC_CHECKAPP)==BST_CHECKED); + CheckKBN = (IsDlgButtonChecked(hDlg,IDC_CHECKKBN)==BST_CHECKED); + CheckContact = (IsDlgButtonChecked(hDlg,IDC_CHECKCONTACT)==BST_CHECKED); + CheckContactNick = (IsDlgButtonChecked(hDlg,IDC_CHECKCONTACTNICK)==BST_CHECKED); + CheckContactNoEvent = (IsDlgButtonChecked(hDlg,IDC_CHECKCONTACTNOEVENT)==BST_CHECKED); + + CheckFSnd = (IsDlgButtonChecked(hDlg,IDC_CHECKFSND)==BST_CHECKED); + CheckFMsg = (IsDlgButtonChecked(hDlg,IDC_CHECKFMSG)==BST_CHECKED); + CheckFIco = (IsDlgButtonChecked(hDlg,IDC_CHECKFICO)==BST_CHECKED); + + CheckNMsgP = (IsDlgButtonChecked(hDlg,IDC_CHECKNMSGP)==BST_CHECKED); + + Port = GetDlgItemInt(hDlg, IDC_EDITPORT, &Translated, FALSE); + if ( !Translated ) { + MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); + SetFocus(GetDlgItem(hDlg,IDC_EDITPORT)); + break; + } + Interval = GetDlgItemInt(hDlg,IDC_EDITINTERVAL,&Translated,FALSE); + if ( !Translated ) { + MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); + SetFocus(GetDlgItem(hDlg,IDC_EDITINTERVAL)); + break; + } + + GetDlgItemTextA(hDlg, IDC_EDITAPP, Text, sizeof(Text)); + if (CheckApp && !(Length = strlen(Text))) { + MessageBox(hDlg,TranslateT("Please select application to run"),TranslateT("Input error"),MB_OK); + break; + } + + GetDlgItemTextA(hDlg, IDC_COMBOACCOUNT, Text, sizeof(Text)); + if ( !( Length = strlen(Text))) { + GetDlgItemTextA(hDlg,IDC_EDITNAME, Text, sizeof(Text)); + if ( !(Length = strlen( Text ))) + break; + } + + DlgSetItemTextT(hDlg, IDC_STTIMELEFT, TranslateT("Please wait while no account is in use.")); + + if (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)Text))) { + NewAcc=TRUE; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write wait\n"); + #endif + WaitToWriteSO(POP3Plugin->AccountBrowserSO); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write enter\n"); + #endif + if (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_GETNEXTFREEACCOUNT,(WPARAM)POP3Plugin,(LPARAM)YAMN_ACCOUNTVERSION))) { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write done\n"); + #endif + WriteDoneSO(POP3Plugin->AccountBrowserSO); + MessageBox(hDlg,TranslateT("Cannot allocate memory space for new account"),TranslateT("Memory error"),MB_OK); + break; + } + } + else { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write wait\n"); + #endif + //We have to get full access to AccountBrowser, so other iterating thrads cannot get new account until new account is right set + WaitToWriteSO(POP3Plugin->AccountBrowserSO); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write enter\n"); + #endif + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write wait\n"); + #endif + if (WAIT_OBJECT_0!=WaitToWrite(ActualAccount)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write wait failed\n"); + #endif + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:ActualBrowserSO-write done\n"); + #endif + WriteDoneSO(POP3Plugin->AccountBrowserSO); + + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write enter\n"); + #endif + + GetDlgItemTextA(hDlg, IDC_EDITNAME, Text, sizeof(Text)); + if ( !(Length = strlen( Text ))) + break; + if (NULL != ActualAccount->Name) + delete[] ActualAccount->Name; + ActualAccount->Name = new char[ strlen(Text)+1]; + strcpy(ActualAccount->Name,Text); + + GetDlgItemTextA(hDlg,IDC_EDITSERVER,Text,sizeof(Text)); + if (NULL!=ActualAccount->Server->Name) + delete[] ActualAccount->Server->Name; + ActualAccount->Server->Name=new char[ strlen(Text)+1]; + strcpy(ActualAccount->Server->Name,Text); + + GetDlgItemTextA(hDlg,IDC_EDITLOGIN,Text,sizeof(Text)); + if (NULL!=ActualAccount->Server->Login) + delete[] ActualAccount->Server->Login; + ActualAccount->Server->Login=new char[ strlen(Text)+1]; + strcpy(ActualAccount->Server->Login,Text); + + GetDlgItemTextA(hDlg,IDC_EDITPASS,Text,sizeof(Text)); + if (NULL!=ActualAccount->Server->Passwd) + delete[] ActualAccount->Server->Passwd; + ActualAccount->Server->Passwd=new char[ strlen(Text)+1]; + strcpy(ActualAccount->Server->Passwd,Text); + + GetDlgItemTextW(hDlg,IDC_EDITAPP,TextW,SIZEOF(TextW)); + if (NULL!=ActualAccount->NewMailN.App) + delete[] ActualAccount->NewMailN.App; + ActualAccount->NewMailN.App=new WCHAR[wcslen(TextW)+1]; + wcscpy(ActualAccount->NewMailN.App,TextW); + + GetDlgItemTextW(hDlg,IDC_EDITAPPPARAM,TextW,SIZEOF(TextW)); + if (NULL!=ActualAccount->NewMailN.AppParam) + delete[] ActualAccount->NewMailN.AppParam; + ActualAccount->NewMailN.AppParam=new WCHAR[wcslen(TextW)+1]; + wcscpy(ActualAccount->NewMailN.AppParam,TextW); + + ActualAccount->Server->Port=Port; + ActualAccount->Interval=Interval*60; + + if (CB_ERR==(index=SendDlgItemMessage(hDlg,IDC_COMBOCP,CB_GETCURSEL,0,0))) + index = CPDEFINDEX; + ActualAccount->CP = CodePageNamesSupp[index].CP; + + if (NewAcc) + ActualAccount->TimeLeft=Interval*60; + + CheckStart = (IsDlgButtonChecked(hDlg,IDC_CHECKSTART)==BST_CHECKED); + CheckForce = (IsDlgButtonChecked(hDlg,IDC_CHECKFORCE)==BST_CHECKED); + + ActualAccount->Flags= + (Check ? YAMN_ACC_ENA : 0) | + (CheckSSL ? YAMN_ACC_SSL23 : 0) | + (CheckNoTLS ? YAMN_ACC_NOTLS : 0) | + (CheckAPOP ? YAMN_ACC_APOP : 0) | + (CheckABody ? YAMN_ACC_BODY : 0) | + (ActualAccount->Flags & YAMN_ACC_POPN); + + ActualAccount->StatusFlags= + (Check0 ? YAMN_ACC_ST0 : 0) | + (Check1 ? YAMN_ACC_ST1 : 0) | + (Check2 ? YAMN_ACC_ST2 : 0) | + (Check3 ? YAMN_ACC_ST3 : 0) | + (Check4 ? YAMN_ACC_ST4 : 0) | + (Check5 ? YAMN_ACC_ST5 : 0) | + (Check6 ? YAMN_ACC_ST6 : 0) | + (Check7 ? YAMN_ACC_ST7 : 0) | + (Check8 ? YAMN_ACC_ST8 : 0) | + (Check9 ? YAMN_ACC_ST9 : 0) | + (CheckStart ? YAMN_ACC_STARTS : 0) | + (CheckForce ? YAMN_ACC_FORCE : 0); + + ActualAccount->NewMailN.Flags= + (CheckSnd ? YAMN_ACC_SND : 0) | + (CheckMsg ? YAMN_ACC_MSG : 0) | + (CheckIco ? YAMN_ACC_ICO : 0) | + (ActualAccount->NewMailN.Flags & YAMN_ACC_POP) | + (ActualAccount->NewMailN.Flags & YAMN_ACC_POPC) | + (CheckApp ? YAMN_ACC_APP : 0) | + (CheckKBN ? YAMN_ACC_KBN : 0) | + (CheckContact ? YAMN_ACC_CONT : 0) | + (CheckContactNick ? YAMN_ACC_CONTNICK : 0) | + (CheckContactNoEvent ? YAMN_ACC_CONTNOEVENT : 0) | + YAMN_ACC_MSGP; //this is default: when new mail arrives and window was displayed, leave it displayed. + + ActualAccount->NoNewMailN.Flags= + (ActualAccount->NoNewMailN.Flags & YAMN_ACC_POP) | + (ActualAccount->NoNewMailN.Flags & YAMN_ACC_POPC) | + (CheckNMsgP ? YAMN_ACC_MSGP : 0); + + ActualAccount->BadConnectN.Flags= + (CheckFSnd ? YAMN_ACC_SND : 0) | + (CheckFMsg ? YAMN_ACC_MSG : 0) | + (CheckFIco ? YAMN_ACC_ICO : 0) | + (ActualAccount->BadConnectN.Flags & YAMN_ACC_POP) | + (ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC); + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write done\n"); + #endif + WriteDone(ActualAccount); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write done\n"); + #endif + WriteDoneSO(POP3Plugin->AccountBrowserSO); + + EnableWindow(GetDlgItem(hDlg,IDC_BTNDEL),TRUE); + + DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); + + index = SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,(WPARAM)0,(LPARAM)0); + + HPOP3ACCOUNT temp = ActualAccount; + + SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_RESETCONTENT,0,(LPARAM)0); + if (POP3Plugin->FirstAccount!=NULL) + for (ActualAccount=(HPOP3ACCOUNT)POP3Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=(HPOP3ACCOUNT)ActualAccount->Next) + if (ActualAccount->Name!=NULL) + SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_ADDSTRING,0,(LPARAM)ActualAccount->Name); + + ActualAccount = temp; + SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_SETCURSEL,(WPARAM)index,(LPARAM)ActualAccount->Name); + + WritePOP3Accounts(); + RefreshContact(); + return TRUE; + } + } + break; + } + if (Changed) + SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); + return FALSE; +} + +INT_PTR CALLBACK DlgProcPOP3AccPopup(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) +{ + BOOL Changed=FALSE; + static BOOL InList=FALSE; + static HPOP3ACCOUNT ActualAccount; + static UCHAR ActualStatus; +// static struct CPOP3Options POP3Options; + + switch(msg) + { + case WM_INITDIALOG: + { + DlgEnableAccountPopup(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); + DlgShowAccountPopup(hDlg,(WPARAM)M_SHOWDEFAULT,0); + //DlgShowAccountColors(hDlg,0,(LPARAM)ActualAccount); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read wait\n"); + #endif + WaitToReadSO(POP3Plugin->AccountBrowserSO); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read enter\n"); + #endif + if (POP3Plugin->FirstAccount!=NULL) + for (ActualAccount=(HPOP3ACCOUNT)POP3Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=(HPOP3ACCOUNT)ActualAccount->Next) + if (ActualAccount->Name!=NULL) + SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_ADDSTRING,0,(LPARAM)ActualAccount->Name); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:INITDIALOG:AccountBrowserSO-read done\n"); + #endif + ReadDoneSO(POP3Plugin->AccountBrowserSO); + ActualAccount=NULL; + + + TranslateDialogDefault(hDlg); + SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,0); + return TRUE; + } + + case WM_SHOWWINDOW: + if ((BOOL)wParam==FALSE) + { + WindowList_Remove(pYAMNVar->MessageWnds,hDlg); + SendMessage(GetParent(hDlg),PSM_UNCHANGED,(WPARAM)hDlg,(LPARAM)0); + } + else + { + WindowList_Add(pYAMNVar->MessageWnds,hDlg,NULL); + + int index = SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,(WPARAM)0,(LPARAM)0); + HPOP3ACCOUNT temp = ActualAccount; + SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_RESETCONTENT,0,(LPARAM)0); + + if (POP3Plugin->FirstAccount!=NULL) + for (ActualAccount=(HPOP3ACCOUNT)POP3Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=(HPOP3ACCOUNT)ActualAccount->Next) + if (ActualAccount->Name!=NULL) + SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_ADDSTRING,0,(LPARAM)ActualAccount->Name); + + ActualAccount = temp; + + if (ActualAccount != NULL) + { + SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_SETCURSEL,(WPARAM)index,(LPARAM)ActualAccount->Name); + DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); + DlgShowAccountColors(hDlg,0,(LPARAM)ActualAccount); + DlgEnableAccountPopup(hDlg,(WPARAM)TRUE,(LPARAM)FALSE); + } + else + { + DlgShowAccountPopup(hDlg,(WPARAM)M_SHOWDEFAULT,0); + DlgEnableAccountPopup(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); + } + + } + return TRUE; + + case WM_COMMAND: + { + WORD wNotifyCode = HIWORD(wParam); + switch(LOWORD(wParam)) + { + LONG Result; + case IDC_COMBOACCOUNT: + switch(wNotifyCode) + { + + case CBN_KILLFOCUS: + GetDlgItemTextA(hDlg,IDC_COMBOACCOUNT,DlgInput,sizeof(DlgInput)); + if (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput))) + { + DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); + if (lstrlenA(DlgInput)) + DlgEnableAccountPopup(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); + else + DlgEnableAccountPopup(hDlg,(WPARAM)FALSE,(LPARAM)FALSE); + } + else + { + DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); + DlgShowAccountColors(hDlg,0,(LPARAM)ActualAccount); + DlgEnableAccountPopup(hDlg,(WPARAM)TRUE,(LPARAM)TRUE); + } + break; + case CBN_SELCHANGE: + if (CB_ERR!=(Result=SendDlgItemMessage(hDlg,IDC_COMBOACCOUNT,CB_GETCURSEL,0,0))) + SendDlgItemMessageA(hDlg,IDC_COMBOACCOUNT,CB_GETLBTEXT,(WPARAM)Result,(LPARAM)DlgInput); + if ((Result==CB_ERR) || (NULL==(ActualAccount=(HPOP3ACCOUNT)CallService(MS_YAMN_FINDACCOUNTBYNAME,(WPARAM)POP3Plugin,(LPARAM)DlgInput)))) + { + DlgSetItemText(hDlg,(WPARAM)IDC_STTIMELEFT,(LPARAM)NULL); + } + else + { + DlgShowAccount(hDlg,(WPARAM)M_SHOWACTUAL,(LPARAM)ActualAccount); + DlgShowAccountColors(hDlg,0,(LPARAM)ActualAccount); + DlgEnableAccountPopup(hDlg,(WPARAM)TRUE,(LPARAM)FALSE); + } + break; + } + break; + case IDC_COMBOCP: + { + int sel = SendDlgItemMessage(hDlg,IDC_COMBOCP,CB_GETCURSEL,0,0); + CPINFOEX info; GetCPInfoEx(CodePageNamesSupp[sel].CP,0,&info); + DlgSetItemTextT(hDlg, IDC_STSTATUS, info.CodePageName); + } + case IDC_RADIOPOPN: + case IDC_RADIOPOP1: + Changed=TRUE; + break; + case IDC_CPB: + case IDC_CPT: + case IDC_CPFB: + case IDC_CPFT: + case IDC_CPNB: + case IDC_CPNT: + if (HIWORD(wParam)!=CPN_COLOURCHANGED) + break; + case IDC_CHECKCOL: + case IDC_CHECKFCOL: + case IDC_CHECKNCOL: + EnableWindow(GetDlgItem(hDlg,IDC_CPB),(IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED) && wParam); + EnableWindow(GetDlgItem(hDlg,IDC_CPT),(IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED) && wParam); + EnableWindow(GetDlgItem(hDlg,IDC_CPNB),(IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED) && wParam); + EnableWindow(GetDlgItem(hDlg,IDC_CPNT),(IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED) && wParam); + EnableWindow(GetDlgItem(hDlg,IDC_CPFB),(IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED) && wParam); + EnableWindow(GetDlgItem(hDlg,IDC_CPFT),(IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED) && (IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED) && wParam); + Changed=TRUE; + break; + + case IDC_PREVIEW: + { + POPUPDATAT Tester; + POPUPDATAT TesterF; + POPUPDATAT TesterN; + BOOL TesterC = (IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED); + BOOL TesterFC = (IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED); + BOOL TesterNC = (IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED); + + ZeroMemory(&Tester,sizeof(Tester)); + ZeroMemory(&TesterF,sizeof(TesterF)); + ZeroMemory(&TesterF,sizeof(TesterN)); + Tester.lchContact=NULL; + TesterF.lchContact=NULL; + TesterN.lchContact=NULL; + Tester.lchIcon=g_LoadIconEx(2); + TesterF.lchIcon=g_LoadIconEx(3); + TesterN.lchIcon=g_LoadIconEx(1); + + lstrcpyn(Tester.lptzContactName,TranslateT("Account Test"),MAX_CONTACTNAME); + lstrcpyn(TesterF.lptzContactName,TranslateT("Account Test (failed)"),MAX_CONTACTNAME); + lstrcpyn(TesterN.lptzContactName,TranslateT("Account Test"),MAX_CONTACTNAME); + lstrcpyn(Tester.lptzText,TranslateT("You have N new mail messages"),MAX_SECONDLINE); + lstrcpyn(TesterF.lptzText,TranslateT("Connection failed message"),MAX_SECONDLINE); + lstrcpyn(TesterN.lptzText,TranslateT("No new mail message"),MAX_SECONDLINE); + if (TesterC) + { + Tester.colorBack=SendDlgItemMessage(hDlg,IDC_CPB,CPM_GETCOLOUR,0,0); + Tester.colorText=SendDlgItemMessage(hDlg,IDC_CPT,CPM_GETCOLOUR,0,0); + } + else + { + Tester.colorBack=GetSysColor(COLOR_BTNFACE); + Tester.colorText=GetSysColor(COLOR_WINDOWTEXT); + } + if (TesterFC) + { + TesterF.colorBack=SendDlgItemMessage(hDlg,IDC_CPFB,CPM_GETCOLOUR,0,0); + TesterF.colorText=SendDlgItemMessage(hDlg,IDC_CPFT,CPM_GETCOLOUR,0,0); + } + else + { + TesterF.colorBack=GetSysColor(COLOR_BTNFACE); + TesterF.colorText=GetSysColor(COLOR_WINDOWTEXT); + } + if (TesterNC) + { + TesterN.colorBack=SendDlgItemMessage(hDlg,IDC_CPNB,CPM_GETCOLOUR,0,0); + TesterN.colorText=SendDlgItemMessage(hDlg,IDC_CPNT,CPM_GETCOLOUR,0,0); + } + else + { + TesterN.colorBack=GetSysColor(COLOR_BTNFACE); + TesterN.colorText=GetSysColor(COLOR_WINDOWTEXT); + } + Tester.PluginWindowProc=NULL; + TesterF.PluginWindowProc=NULL; + TesterN.PluginWindowProc=NULL; + Tester.PluginData=NULL; + TesterF.PluginData=NULL; + TesterN.PluginData=NULL; + + if (IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED) + PUAddPopUpT(&Tester); + if (IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED) + PUAddPopUpT(&TesterF); + if (IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED) + PUAddPopUpT(&TesterN); + Changed=TRUE; + } + break; + case IDC_CHECKKBN: + Changed=TRUE; + break; + case IDC_CHECKPOP: + Changed=TRUE; + EnableWindow(GetDlgItem(hDlg,IDC_CHECKCOL),IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_CPB),(IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_CPT),(IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_RADIOPOPN),(IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED)); + EnableWindow(GetDlgItem(hDlg,IDC_RADIOPOP1),(IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED)); + EnableWindow(GetDlgItem(hDlg,IDC_EDITPOPS),(IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED)); + break; + case IDC_CHECKFPOP: + Changed=TRUE; + EnableWindow(GetDlgItem(hDlg,IDC_CHECKFCOL),IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_CPFB),(IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_CPFT),(IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_EDITFPOPS),(IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED)); + break; + case IDC_CHECKNPOP: + Changed=TRUE; + EnableWindow(GetDlgItem(hDlg,IDC_CHECKNCOL),IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_CPNB),(IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_CPNT),(IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED) && IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED); + EnableWindow(GetDlgItem(hDlg,IDC_EDITNPOPS),(IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED)); + break; + + } + if (HIWORD(wParam)==EN_CHANGE) + Changed=TRUE; + break; + } + case WM_NOTIFY: + switch(((LPNMHDR)lParam)->idFrom) + { + case 0: + switch(((LPNMHDR)lParam)->code) + { + case PSN_APPLY: + { + TCHAR Text[MAX_PATH]; + BOOL Translated,NewAcc=FALSE,CheckPopup,CheckPopupW; + BOOL CheckNPopup,CheckNPopupW,CheckFPopup,CheckFPopupW; + BOOL CheckPopN; + UINT Time,TimeN,TimeF; + + if (GetDlgItemText(hDlg,IDC_COMBOACCOUNT,Text,sizeof(Text)/sizeof(TCHAR))) + { + CheckPopup = (IsDlgButtonChecked(hDlg,IDC_CHECKPOP)==BST_CHECKED); + CheckPopupW = (IsDlgButtonChecked(hDlg,IDC_CHECKCOL)==BST_CHECKED); + + CheckFPopup = (IsDlgButtonChecked(hDlg,IDC_CHECKFPOP)==BST_CHECKED); + CheckFPopupW = (IsDlgButtonChecked(hDlg,IDC_CHECKFCOL)==BST_CHECKED); + + CheckNPopup = (IsDlgButtonChecked(hDlg,IDC_CHECKNPOP)==BST_CHECKED); + CheckNPopupW = (IsDlgButtonChecked(hDlg,IDC_CHECKNCOL)==BST_CHECKED); + + CheckPopN = (IsDlgButtonChecked(hDlg,IDC_RADIOPOPN)==BST_CHECKED); + + + Time=GetDlgItemInt(hDlg,IDC_EDITPOPS,&Translated,FALSE); + if (!Translated) + { + MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); + SetFocus(GetDlgItem(hDlg,IDC_EDITPOPS)); + break; + } + TimeN=GetDlgItemInt(hDlg,IDC_EDITNPOPS,&Translated,FALSE); + if (!Translated) + { + MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); + SetFocus(GetDlgItem(hDlg,IDC_EDITNPOPS)); + break; + } + TimeF=GetDlgItemInt(hDlg,IDC_EDITFPOPS,&Translated,FALSE); + if (!Translated) + { + MessageBox(hDlg,TranslateT("This is not a valid number value"),TranslateT("Input error"),MB_OK); + SetFocus(GetDlgItem(hDlg,IDC_EDITFPOPS)); + break; + } + + + DlgSetItemTextT(hDlg, IDC_STTIMELEFT, TranslateT("Please wait while no account is in use.")); + + ActualAccount->Flags= + (ActualAccount->Flags & YAMN_ACC_ENA) | + (ActualAccount->Flags & YAMN_ACC_SSL23) | + (ActualAccount->Flags & YAMN_ACC_NOTLS) | + (ActualAccount->Flags & YAMN_ACC_APOP) | + (ActualAccount->Flags & YAMN_ACC_BODY) | + (CheckPopN ? YAMN_ACC_POPN : 0); + + ActualAccount->NewMailN.Flags= + (ActualAccount->NewMailN.Flags & YAMN_ACC_SND) | + (ActualAccount->NewMailN.Flags & YAMN_ACC_MSG) | + (ActualAccount->NewMailN.Flags & YAMN_ACC_ICO) | + (CheckPopup ? YAMN_ACC_POP : 0) | + (CheckPopupW ? YAMN_ACC_POPC : 0) | + (ActualAccount->NewMailN.Flags & YAMN_ACC_APP) | + (ActualAccount->NewMailN.Flags & YAMN_ACC_KBN) | + (ActualAccount->NewMailN.Flags & YAMN_ACC_CONT) | + (ActualAccount->NewMailN.Flags & YAMN_ACC_CONTNICK) | + (ActualAccount->NewMailN.Flags & YAMN_ACC_CONTNOEVENT) | + YAMN_ACC_MSGP; + + ActualAccount->NoNewMailN.Flags= + (CheckNPopup ? YAMN_ACC_POP : 0) | + (CheckNPopupW ? YAMN_ACC_POPC : 0) | + (ActualAccount->NoNewMailN.Flags & YAMN_ACC_MSGP); + + ActualAccount->BadConnectN.Flags= + (ActualAccount->BadConnectN.Flags & YAMN_ACC_SND) | + (ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG) | + (ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO) | + (CheckFPopup ? YAMN_ACC_POP : 0) | + (CheckFPopupW ? YAMN_ACC_POPC : 0); + + ActualAccount->NewMailN.PopUpB=SendDlgItemMessage(hDlg,IDC_CPB,CPM_GETCOLOUR,0,0); + ActualAccount->NewMailN.PopUpT=SendDlgItemMessage(hDlg,IDC_CPT,CPM_GETCOLOUR,0,0); + ActualAccount->NewMailN.PopUpTime=Time; + + ActualAccount->NoNewMailN.PopUpB=SendDlgItemMessage(hDlg,IDC_CPNB,CPM_GETCOLOUR,0,0); + ActualAccount->NoNewMailN.PopUpT=SendDlgItemMessage(hDlg,IDC_CPNT,CPM_GETCOLOUR,0,0); + ActualAccount->NoNewMailN.PopUpTime=TimeN; + + ActualAccount->BadConnectN.PopUpB=SendDlgItemMessage(hDlg,IDC_CPFB,CPM_GETCOLOUR,0,0); + ActualAccount->BadConnectN.PopUpT=SendDlgItemMessage(hDlg,IDC_CPFT,CPM_GETCOLOUR,0,0); + ActualAccount->BadConnectN.PopUpTime=TimeF; + + + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:ActualAccountSO-write done\n"); + #endif + WriteDone(ActualAccount); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Options:APPLY:AccountBrowserSO-write done\n"); + #endif + WriteDoneSO(POP3Plugin->AccountBrowserSO); + +// if (0==WritePOP3Accounts()) +// Beep(500,100); + WritePOP3Accounts(); + RefreshContact(); + return TRUE; + } + } + break; + } + break; + } + break; + } + if (Changed) + SendMessage(GetParent(hDlg),PSM_CHANGED,0,0); + return FALSE; +} + diff --git a/protocols/YAMN/src/proto/pop3/pop3opt.h b/protocols/YAMN/src/proto/pop3/pop3opt.h new file mode 100644 index 0000000000..6a678284fa --- /dev/null +++ b/protocols/YAMN/src/proto/pop3/pop3opt.h @@ -0,0 +1,40 @@ +#ifndef __OPTIONS_H +#define __OPTIONS_H + +#define M_SHOWACTUAL 0 +#define M_SHOWDEFAULT 1 + + +//Enables account in options +BOOL DlgEnableAccount(HWND hDlg,WPARAM wParam,LPARAM lParam); + +//Sets dialog controls to match current account +BOOL DlgShowAccount(HWND hDlg,WPARAM wParam,LPARAM lParam); + +//Sets colors to match colors of actual account +BOOL DlgShowAccountColors(HWND hDlg,WPARAM wParam,LPARAM lParam); + +//Options dialog procedure +INT_PTR CALLBACK DlgProcPOP3AccOpt(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); + +//Options dialog procedure +INT_PTR CALLBACK DlgProcPOP3AccStatusOpt(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); + +//Options dialog procedure +INT_PTR CALLBACK DlgProcYAMNOpt(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); + +//Options dialog procedure +INT_PTR CALLBACK DlgProcPOP3AccPopup(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); + +//Initializes POP3 options for Miranda +int POP3OptInit(WPARAM wParam,LPARAM lParam); + +//Sets dialog item text +BOOL DlgSetItemText(HWND hDlg,WPARAM wParam,const char*); +BOOL DlgSetItemTextW(HWND hDlg,WPARAM wParam,const WCHAR*); + + +#define DlgSetItemTextT DlgSetItemTextW + + +#endif diff --git a/protocols/YAMN/src/protoplugin.cpp b/protocols/YAMN/src/protoplugin.cpp new file mode 100644 index 0000000000..479b54ce67 --- /dev/null +++ b/protocols/YAMN/src/protoplugin.cpp @@ -0,0 +1,197 @@ +/* + * YAMN plugin export functions for protocols + * + * (c) majvan 2002-2004 + */ + +#include "yamn.h" + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +PYAMN_PROTOPLUGINQUEUE FirstProtoPlugin=NULL; + +INT_PTR RegisterProtocolPluginSvc(WPARAM,LPARAM); + +//Removes plugin from queue and deletes registration structures +INT_PTR UnregisterProtocolPlugin(HYAMNPROTOPLUGIN Plugin); + +INT_PTR UnregisterProtocolPluginSvc(WPARAM,LPARAM); + +//Removes plugins from queue and deletes registration structures +INT_PTR UnregisterProtoPlugins(); + +//Sets imported functions for an plugin and therefore it starts plugin to be registered and running +// Plugin- plugin, which wants to set its functions +// YAMNFcn- pointer to imported functions with accounts +// YAMNFcnVer- version of YAMN_PROTOIMPORTFCN, use YAMN_PROTOIMPORTFCNVERSION +// YAMNMailFcn- pointer to imported functions with mails +// YAMNMailFcnVer- version of YAMN_MAILIMPORTFCN, use YAMN_MAILIMPORTFCNVERSION +// returns nonzero if success +int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin,PYAMN_PROTOIMPORTFCN YAMNFcn,DWORD YAMNFcnVer,PYAMN_MAILIMPORTFCN YAMNMailFcn,DWORD YAMNMailFcnVer); + +struct CExportedFunctions ProtoPluginExportedFcn[]= +{ + {YAMN_SETPROTOCOLPLUGINFCNIMPORTID,(void *)SetProtocolPluginFcnImportFcn}, +}; + +struct CExportedServices ProtoPluginExportedSvc[]= +{ + {MS_YAMN_REGISTERPROTOPLUGIN,RegisterProtocolPluginSvc}, + {MS_YAMN_UNREGISTERPROTOPLUGIN,UnregisterProtocolPluginSvc}, + {MS_YAMN_GETFILENAME,GetFileNameSvc}, + {MS_YAMN_DELETEFILENAME,DeleteFileNameSvc}, +}; + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +INT_PTR RegisterProtocolPluginSvc(WPARAM wParam,LPARAM lParam) +{ + PYAMN_PROTOREGISTRATION Registration=(PYAMN_PROTOREGISTRATION)wParam; + HYAMNPROTOPLUGIN Plugin; + + if (lParam!=YAMN_PROTOREGISTRATIONVERSION) + return 0; + if ((Registration->Name==NULL) || (Registration->Ver==NULL)) + return (INT_PTR)NULL; + if (NULL==(Plugin=new YAMN_PROTOPLUGIN)) + return (INT_PTR)NULL; + + Plugin->PluginInfo=Registration; + + Plugin->FirstAccount=NULL; + + Plugin->AccountBrowserSO=new SWMRG; + SWMRGInitialize(Plugin->AccountBrowserSO,NULL); + + Plugin->Fcn=NULL; + Plugin->MailFcn=NULL; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"::: YAMN- new protocol registered: %0x (%s) :::\n",Plugin,Registration->Name); +#endif + return (INT_PTR)Plugin; +} + +int WINAPI SetProtocolPluginFcnImportFcn(HYAMNPROTOPLUGIN Plugin,PYAMN_PROTOIMPORTFCN YAMNFcn,DWORD YAMNFcnVer,PYAMN_MAILIMPORTFCN YAMNMailFcn,DWORD YAMNMailFcnVer) +{ + PYAMN_PROTOPLUGINQUEUE Parser; + + if (YAMNFcnVer!=YAMN_PROTOIMPORTFCNVERSION) + return 0; + if (YAMNMailFcnVer!=YAMN_MAILIMPORTFCNVERSION) + return 0; + if (YAMNFcn==NULL) + return 0; + if (YAMNMailFcn==NULL) + return 0; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"::: YAMN- protocol %0x import succeed :::\n",Plugin); +#endif + Plugin->Fcn=YAMNFcn; + Plugin->MailFcn=YAMNMailFcn; + + EnterCriticalSection(&PluginRegCS); +//We add protocol to the protocol list + for (Parser=FirstProtoPlugin;Parser!=NULL && Parser->Next!=NULL;Parser=Parser->Next); + if (Parser==NULL) + { + FirstProtoPlugin=new YAMN_PROTOPLUGINQUEUE; + Parser=FirstProtoPlugin; + } + else + { + Parser->Next=new YAMN_PROTOPLUGINQUEUE; + Parser=Parser->Next; + } + + Parser->Plugin=Plugin; + Parser->Next=NULL; + + LeaveCriticalSection(&PluginRegCS); + return 1; +} + +INT_PTR UnregisterProtocolPlugin(HYAMNPROTOPLUGIN Plugin) +{ + PYAMN_PROTOPLUGINQUEUE Parser,Found; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"Entering UnregisterProtocolPlugin\n"); +#endif + if (FirstProtoPlugin->Plugin==Plugin) + { + Found=FirstProtoPlugin; + FirstProtoPlugin=FirstProtoPlugin->Next; + } + else + { + for (Parser=FirstProtoPlugin;(Parser->Next!=NULL) && (Plugin!=Parser->Next->Plugin);Parser=Parser->Next); + if (Parser->Next!=NULL) + { + Found=Parser->Next; + Parser->Next=Parser->Next->Next; + } + else + Found=NULL; + } + if (Found!=NULL) + { + StopAccounts(Plugin); + DeleteAccounts(Plugin); + if (Plugin->Fcn->UnLoadFcn!=NULL) + Plugin->Fcn->UnLoadFcn((void *)0); + + delete Found->Plugin->AccountBrowserSO; + delete Found->Plugin; + delete Found; + +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"::: YAMN- protocol %0x unregistered :::\n",Plugin); +#endif + } + else + return 0; + return 1; +} + +INT_PTR UnregisterProtocolPluginSvc(WPARAM wParam,LPARAM lParam) +{ + HYAMNPROTOPLUGIN Plugin=(HYAMNPROTOPLUGIN)wParam; + + EnterCriticalSection(&PluginRegCS); + UnregisterProtocolPlugin(Plugin); + LeaveCriticalSection(&PluginRegCS); + return 1; + +} + +INT_PTR UnregisterProtoPlugins() +{ + EnterCriticalSection(&PluginRegCS); +//We remove protocols from the protocol list + while(FirstProtoPlugin!=NULL) + UnregisterProtocolPlugin(FirstProtoPlugin->Plugin); + LeaveCriticalSection(&PluginRegCS); + return 1; +} + +INT_PTR GetFileNameSvc(WPARAM wParam,LPARAM) +{ + TCHAR *FileName = new TCHAR[MAX_PATH]; + if (FileName == NULL) + return NULL; + + mir_sntprintf(FileName, MAX_PATH, _T("%s\\yamn-accounts.%s.%s.book"), UserDirectory, wParam, ProfileName); + return (INT_PTR)FileName; +} + +INT_PTR DeleteFileNameSvc(WPARAM wParam,LPARAM) +{ + if (( TCHAR* )wParam != NULL) + delete[] ( TCHAR* ) wParam; + + return 0; +} diff --git a/protocols/YAMN/src/resource.h b/protocols/YAMN/src/resource.h new file mode 100644 index 0000000000..87b4b07da2 --- /dev/null +++ b/protocols/YAMN/src/resource.h @@ -0,0 +1,128 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by YAMN.rc +// +#define IDI_ONLINE 104 +#define IDI_OFFLINE 105 +#define IDD_DLGVIEWMESSAGES 107 +#define IDD_DLGSHOWMESSAGE 108 +#define IDI_ICOYAMN2 112 +#define IDI_ICOYAMN1 113 +#define IDD_DLGBADCONNECT 115 +#define IDD_POP3ACCOUNTOPT 121 +#define IDD_YAMNOPT 126 +#define IDI_NA 131 +#define IDI_ICOTTBUP 138 +#define IDD_PLUGINOPT 141 +#define IDI_OCCUPIED 159 +#define IDD_CHOOSESTATUSMODES 310 +#define IDD_OPTIONS 311 +#define IDD_POP3ACCOUNTPOPUP 312 +#define IDC_EDITSERVER 1000 +#define IDC_EDITPORT 1001 +#define IDC_EDITLOGIN 1002 +#define IDC_EDITPASS 1003 +#define IDC_COMBOACCOUNT 1005 +#define IDC_BTNDEFAULT 1006 +#define IDC_EDITINTERVAL 1007 +#define IDC_CHECKSND 1008 +#define IDC_CHECKMSG 1009 +#define IDC_CHECKAPP 1010 +#define IDC_BTNAPP 1011 +#define IDC_CHECKICO 1012 +#define IDC_CHECK 1013 +#define IDC_BTNDEL 1014 +#define IDC_STSERVER 1015 +#define IDC_CHECKFSND 1016 +#define IDC_CHECKFMSG 1017 +#define IDC_CHECKFICO 1018 +#define IDC_CHECKST0 1019 +#define IDC_CHECKST1 1020 +#define IDC_CHECKST2 1021 +#define IDC_CHECKST3 1022 +#define IDC_CHECKST4 1023 +#define IDC_CHECKST5 1024 +#define IDC_CHECKST6 1025 +#define IDC_CHECKST7 1026 +#define IDC_EDITAPP 1027 +#define IDC_CHECKST8 1028 +#define IDC_CHECKST9 1029 +#define IDC_CHECKCONTACT 1030 +#define IDC_CHECKCONTACTNICK 1031 +#define IDC_CHECKCONTACTNOEVENT 1032 +#define IDC_STTIMELEFT 1033 +#define IDC_LISTMAILS 1038 +#define IDC_LISTHEADERS 1039 +#define IDC_EDITAPPPARAM 1044 +#define IDC_BTNOK 1047 +#define IDC_COMBOCP 1050 +#define IDC_STCP 1055 +#define IDC_STATICMSG 1055 +#define IDC_STPORT 1056 +#define IDC_STLOGIN 1057 +#define IDC_STPASS 1058 +#define IDC_STINTERVAL 1059 +#define IDC_AUTOBODY 1062 +#define IDC_BTNRESET 1063 +#define IDC_CHECKSTART 1064 +#define IDC_STWCHECK 1065 +#define IDC_CHECKFORCE 1066 +#define IDC_RADIOPOP1 1068 +#define IDC_RADIOPOPN 1069 +#define IDC_CPB 1070 +#define IDC_CPNB 1071 +#define IDC_CHECKCOL 1073 +#define IDC_CPT 1074 +#define IDC_CPFB 1075 +#define IDC_CPFT 1076 +#define IDC_CHECKFCOL 1077 +#define IDC_CHECKNCOL 1078 +#define IDC_CPNT 1079 +#define IDC_CHECKPOP 1087 +#define IDC_CHECKNPOP 1088 +#define IDC_CHECKFPOP 1089 +#define IDC_EDITPOPS 1090 +#define IDC_EDITNPOPS 1091 +#define IDC_EDITFPOPS 1092 +#define IDC_GBNEWMAIL 1094 +#define IDC_GBNONEWMAIL 1095 +#define IDC_GBBADCONNECT 1096 +#define IDC_STSTATUS 1102 +#define IDC_COMBOPLUGINS 1104 +#define IDC_STWWW 1111 +#define IDC_STMAIL 1113 +#define IDC_STCOPY 1114 +#define IDC_STDESC 1115 +#define IDC_STVER 1116 +#define IDC_CHECKTTB 1117 +#define IDC_CHECKSSL 1117 +#define IDC_CHECKNMSGP 1118 +#define IDC_CHECKNOTLS 1120 +#define IDC_CHECKKBN 1121 +#define IDC_BTNSTATUS 1123 +#define IDC_OPTIONSTAB 1124 +#define IDC_BTNCHECKALL 1125 +#define IDC_MAINMENU 1126 +#define IDC_CLOSEONDELETE 1127 +#define IDC_LONGDATE 1128 +#define IDC_SMARTDATE 1129 +#define IDC_NOSECONDS 1130 +#define IDC_YAMNASPROTO 1131 +#define IDC_CHECKAPOP 1200 +#define IDC_STATUSGROUP 1338 +#define IDC_SPLITTER 1400 +#define IDC_EDITBODY 1401 +#define IDC_PREVIEW 1402 +#define IDC_BTNADD 1403 +#define IDC_EDITNAME 1404 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 143 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1407 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/protocols/YAMN/src/services.cpp b/protocols/YAMN/src/services.cpp new file mode 100644 index 0000000000..cd01722997 --- /dev/null +++ b/protocols/YAMN/src/services.cpp @@ -0,0 +1,496 @@ + +#include "yamn.h" +#include "main.h" + +extern HANDLE hMenuItemMain, hMenuItemCont, hMenuItemContApp; + +static INT_PTR Service_GetCaps(WPARAM wParam, LPARAM lParam) +{ + if (wParam == PFLAGNUM_4) + return PF4_NOCUSTOMAUTH; + if (wParam == PFLAG_UNIQUEIDTEXT) + return (INT_PTR) Translate("Nick"); + if (wParam == PFLAG_MAXLENOFMESSAGE) + return 400; + if (wParam == PFLAG_UNIQUEIDSETTING) + return (INT_PTR) "Id"; + if (wParam == PFLAGNUM_2) + return PF2_ONLINE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND; + if (wParam == PFLAGNUM_5) { + if (DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_SHOWASPROTO, 1)) + return PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND; + return PF2_ONLINE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND; + } + return 0; +} + +static INT_PTR Service_GetStatus(WPARAM wParam, LPARAM lParam) +{ + return YAMN_STATUS; +} + +static INT_PTR Service_SetStatus(WPARAM wParam, LPARAM lParam) +{ + int newstatus = (wParam != ID_STATUS_OFFLINE)?ID_STATUS_ONLINE:ID_STATUS_OFFLINE; + if (newstatus != YAMN_STATUS){ + int oldstatus = YAMN_STATUS; + YAMN_STATUS = newstatus; + ProtoBroadcastAck(YAMN_DBMODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldstatus, newstatus); + } + return 0; + +} + +static INT_PTR Service_GetName(WPARAM wParam, LPARAM lParam) +{ + lstrcpynA((char *) lParam, YAMN_DBMODULE, wParam);; + return 0; +} + +static INT_PTR Service_LoadIcon(WPARAM wParam, LPARAM lParam) +{ + if ( LOWORD( wParam ) == PLI_PROTOCOL ) + return (INT_PTR)CopyIcon(g_LoadIconEx(0)); // noone cares about other than PLI_PROTOCOL + + return (INT_PTR)(HICON)NULL; +} + +INT_PTR ClistContactDoubleclicked(WPARAM wParam, LPARAM lParam) +{ + ContactDoubleclicked(((CLISTEVENT*)lParam)->lParam, lParam); + return 0; +} + +static int Service_ContactDoubleclicked(WPARAM wParam, LPARAM lParam) +{ + ContactDoubleclicked(wParam, lParam); + return 0; +} + +static INT_PTR ContactApplication(WPARAM wParam, LPARAM lParam) +{ + char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); + if ( lstrcmpA(szProto, YAMN_DBMODULE)) + return 0; + + DBVARIANT dbv; + if ( DBGetContactSetting((HANDLE) wParam, YAMN_DBMODULE, "Id", &dbv)) + return 0; + + HACCOUNT ActualAccount = (HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)dbv.pszVal); + if (ActualAccount != NULL) { + STARTUPINFOW si = { 0 }; + si.cb = sizeof(si); + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ContactApplication:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0 == WaitToReadFcn(ActualAccount->AccountAccessSO)) { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ContactApplication:ualAccountSO-read enter\n"); + #endif + if (ActualAccount->NewMailN.App != NULL) { + WCHAR *Command; + if (ActualAccount->NewMailN.AppParam != NULL) + Command = new WCHAR[wcslen(ActualAccount->NewMailN.App)+wcslen(ActualAccount->NewMailN.AppParam)+6]; + else + Command = new WCHAR[wcslen(ActualAccount->NewMailN.App)+6]; + + if (Command != NULL) { + lstrcpyW(Command, L"\""); + lstrcatW(Command, ActualAccount->NewMailN.App); + lstrcatW(Command, L"\" "); + if (ActualAccount->NewMailN.AppParam != NULL) + lstrcatW(Command, ActualAccount->NewMailN.AppParam); + + PROCESS_INFORMATION pi; + CreateProcessW(NULL, Command, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi); + delete[] Command; + } + } + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ContactApplication:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + } + #ifdef DEBUG_SYNCHRO + else + DebugLog(SynchroFile, "ContactApplication:ActualAccountSO-read enter failed\n"); + #endif + } + DBFreeVariant(&dbv); + return 0; +} + +DWORD WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, DWORD dwTimeout); +static INT_PTR AccountMailCheck(WPARAM wParam, LPARAM lParam){ + //This service will check/sincronize the account pointed by wParam + HACCOUNT ActualAccount = (HACCOUNT)wParam; + HANDLE ThreadRunningEV; + DWORD tid; + // copy/paste make mistakes + if (ActualAccount != NULL) { + //we use event to signal, that running thread has all needed stack parameters copied + if (NULL == (ThreadRunningEV = CreateEvent(NULL, FALSE, FALSE, NULL))) + 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; + + EnterCriticalSection(&PluginRegCS); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "AccountCheck:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0 != SWMRGWaitToRead(ActualAccount->AccountAccessSO, 0)) { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); + #endif + } + else { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); + #endif + if ((ActualAccount->Flags & YAMN_ACC_ENA) && ActualAccount->Plugin->Fcn->SynchroFcnPtr) { + struct CheckParam ParamToPlugin = {YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, lParam?YAMN_FORCECHECK:YAMN_NORMALCHECK, (void *)0, NULL}; + HANDLE NewThread; + + ActualAccount->TimeLeft = ActualAccount->Interval; + if (NewThread = CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->SynchroFcnPtr, &ParamToPlugin, 0, &tid)) { + WaitForSingleObject(ThreadRunningEV, INFINITE); + CloseHandle(NewThread); + } + } + ReadDoneFcn(ActualAccount->AccountAccessSO); + } + LeaveCriticalSection(&PluginRegCS); + CloseHandle(ThreadRunningEV); + } + return 0; +} + +static INT_PTR ContactMailCheck(WPARAM wParam, LPARAM lParam) +{ + char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); + if ( lstrcmpA(szProto, YAMN_DBMODULE)) + return 0; + + DBVARIANT dbv; + if ( DBGetContactSetting((HANDLE) wParam, YAMN_DBMODULE, "Id", &dbv)) + return 0; + + HACCOUNT ActualAccount = (HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)dbv.pszVal); + if (ActualAccount != NULL) { + //we use event to signal, that running thread has all needed stack parameters copied + HANDLE ThreadRunningEV; + if (NULL == (ThreadRunningEV = CreateEvent(NULL, FALSE, FALSE, NULL))) + 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; + EnterCriticalSection(&PluginRegCS); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0 != WaitToReadFcn(ActualAccount->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); + #endif + } + else + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); + #endif + if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) //account cannot be forced to check + { + if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr == NULL) + ReadDoneFcn(ActualAccount->AccountAccessSO); + + DWORD tid; + struct CheckParam ParamToPlugin = {YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_FORCECHECK, (void *)0, NULL}; + if (NULL == CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, &ParamToPlugin, 0, &tid)) + ReadDoneFcn(ActualAccount->AccountAccessSO); + else + WaitForSingleObject(ThreadRunningEV, INFINITE); + } + ReadDoneFcn(ActualAccount->AccountAccessSO); + } + LeaveCriticalSection(&PluginRegCS); + CloseHandle(ThreadRunningEV); + } + DBFreeVariant(&dbv); + return 0; +} + +void MainMenuAccountClicked(WPARAM wParam, LPARAM lParam) +{ +} + +/*static*/ void ContactDoubleclicked(WPARAM wParam, LPARAM lParam) +{ + char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); + if ( lstrcmpA(szProto, YAMN_DBMODULE)) + return; + + DBVARIANT dbv; + if ( DBGetContactSetting(( HANDLE )wParam, YAMN_DBMODULE, "Id", &dbv)) + return; + + HACCOUNT ActualAccount = (HACCOUNT) CallService(MS_YAMN_FINDACCOUNTBYNAME, (WPARAM)POP3Plugin, (LPARAM)dbv.pszVal); + if (ActualAccount != NULL) { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0 == WaitToReadFcn(ActualAccount->AccountAccessSO)) { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read enter\n"); + #endif + YAMN_MAILBROWSERPARAM Param = {(HANDLE)0, ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, 0}; + + 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; + + RunMailBrowserSvc((WPARAM)&Param, (LPARAM)YAMN_MAILBROWSERVERSION); + + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read done\n"); + #endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + } + #ifdef DEBUG_SYNCHRO + else + DebugLog(SynchroFile, "Service_ContactDoubleclicked:ActualAccountSO-read enter failed\n"); + #endif + + } + DBFreeVariant(&dbv); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +HBITMAP LoadBmpFromIcon(HICON hIcon) +{ + int IconSizeX = 16; + int IconSizeY = 16; + + HBRUSH hBkgBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); + + BITMAPINFOHEADER bih = {0}; + bih.biSize = sizeof(bih); + bih.biBitCount = 24; + bih.biPlanes = 1; + bih.biCompression = BI_RGB; + bih.biHeight = IconSizeY; + bih.biWidth = IconSizeX; + + int widthBytes = ((bih.biWidth*bih.biBitCount + 31) >> 5) * 4; + + RECT rc; + rc.top = rc.left = 0; + rc.right = bih.biWidth; + rc.bottom = bih.biHeight; + + HDC hdc = GetDC(NULL); + 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, NULL, DI_NORMAL); + SelectObject(hdcMem, hoBmp); + return hBmp; +} + +int AddTopToolbarIcon(WPARAM,LPARAM) +{ + if ( DBGetContactSettingByte(NULL, YAMN_DBMODULE, YAMN_TTBFCHECK, 1)) { + if ( ServiceExists(MS_TTB_REMOVEBUTTON) && hTTButton == NULL) { + TTBButton btn = {0}; + btn.cbSize = sizeof(btn); + btn.pszService = MS_YAMN_FORCECHECK; + btn.dwFlags = TTBBF_VISIBLE | TTBBF_SHOWTOOLTIP; + btn.hIconHandleUp = g_GetIconHandle(5); + btn.hIconHandleDn = g_GetIconHandle(6); + btn.name = btn.pszTooltipUp = LPGEN("Check mail"); + hTTButton = TopToolbar_AddButton(&btn); + } + } + else { + if (hTTButton != NULL) { + CallService(MS_TTB_REMOVEBUTTON, (WPARAM)hTTButton, 0); + hTTButton = NULL; + } + } + + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +int Shutdown(WPARAM, LPARAM) +{ + CallService(MS_TTB_REMOVEBUTTON, (WPARAM)hTTButton, 0); + + DBWriteContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSX, HeadPosX); + DBWriteContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSY, HeadPosY); + DBWriteContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEX, HeadSizeX); + DBWriteContactSettingDword(NULL, YAMN_DBMODULE, YAMN_DBMSGSIZEY, HeadSizeY); + DBWriteContactSettingWord(NULL, YAMN_DBMODULE, YAMN_DBMSGPOSSPLIT, HeadSplitPos); + YAMNVar.Shutdown = TRUE; + KillTimer(NULL, SecTimer); + + UnregisterProtoPlugins(); + UnregisterFilterPlugins(); + return 0; +} + +int SystemModulesLoaded(WPARAM, LPARAM); //in main.cpp +typedef struct { HANDLE hookHandle; const char *hookName; MIRANDAHOOK mirandaFunction;} HookDataType; +static HookDataType hookData[] = { + {0, ME_SYSTEM_MODULESLOADED, SystemModulesLoaded}, //pop3 plugin must be included after all miranda modules are loaded + {0, ME_TTB_MODULELOADED, AddTopToolbarIcon}, + {0, ME_OPT_INITIALISE, YAMNOptInitSvc}, + {0, ME_SYSTEM_PRESHUTDOWN, Shutdown}, + {0, ME_CLIST_DOUBLECLICKED, Service_ContactDoubleclicked}, + {0, 0, 0}//end marker +}; + +void HookEvents(void) +{ + //We set function which registers needed POP3 accounts. This is a part of internal POP3 plugin. + //Your plugin should do the same task in your Load fcn. Why we call it in MODULESLOADED? Because netlib + //user can be registered after all modules are loaded (see m_netlib.h in Miranda) + for (int i = 0;hookData[i].hookName;i++) { + hookData[i].hookHandle = HookEvent(hookData[i].hookName, hookData[i].mirandaFunction); + } +} +void UnhookEvents(void){ + for (int i = 0;i<(sizeof(hookData)/sizeof(hookData[0]));i++) { + if (hookData[i].hookHandle) UnhookEvent(hookData[i].hookHandle); + } +} + +typedef struct { HANDLE serviceHandle; const char *serviceName; MIRANDASERVICE serviceFunction;} ServiceDataType; +static ServiceDataType serviceData[] = { + {0, YAMN_DBMODULE PS_GETCAPS, Service_GetCaps}, + {0, YAMN_DBMODULE PS_GETSTATUS, Service_GetStatus}, + {0, YAMN_DBMODULE PS_SETSTATUS, Service_SetStatus}, + {0, YAMN_DBMODULE PS_GETNAME, Service_GetName}, + {0, YAMN_DBMODULE PS_LOADICON, Service_LoadIcon}, + + //Function with which protocol plugin can register + {0, MS_YAMN_GETFCNPTR, GetFcnPtrSvc}, + + //Function returns pointer to YAMN variables + {0, MS_YAMN_GETVARIABLES, GetVariablesSvc}, + + //Function with which protocol plugin can register + {0, MS_YAMN_REGISTERPROTOPLUGIN, RegisterProtocolPluginSvc}, + + //Function with which protocol plugin can unregister + {0, MS_YAMN_UNREGISTERPROTOPLUGIN, UnregisterProtocolPluginSvc}, + + //Function creates an account for plugin + {0, MS_YAMN_CREATEPLUGINACCOUNT, CreatePluginAccountSvc}, + + //Function deletes plugin account + {0, MS_YAMN_DELETEPLUGINACCOUNT, DeletePluginAccountSvc}, + + //Finds account for plugin by name + {0, MS_YAMN_FINDACCOUNTBYNAME, FindAccountByNameSvc}, + + //Creates next account for plugin + {0, MS_YAMN_GETNEXTFREEACCOUNT, GetNextFreeAccountSvc}, + + //Function removes account from YAMN queue. Does not delete it from memory + {0, MS_YAMN_DELETEACCOUNT, DeleteAccountSvc}, + + //Function finds accounts for specified plugin + {0, MS_YAMN_READACCOUNTS, AddAccountsFromFileSvc}, + + //Function that stores all plugin mails to one file + {0, MS_YAMN_WRITEACCOUNTS, WriteAccountsToFileSvc}, + + //Function that returns user's filename + {0, MS_YAMN_GETFILENAME, GetFileNameSvc}, + + //Releases unicode string from memory + {0, MS_YAMN_DELETEFILENAME, DeleteFileNameSvc}, + + //Checks mail + {0, MS_YAMN_FORCECHECK, ForceCheckSvc}, + + //Runs YAMN's mail browser + {0, MS_YAMN_MAILBROWSER, RunMailBrowserSvc}, + + //Runs YAMN's bad conenction window + {0, MS_YAMN_BADCONNECTION, RunBadConnectionSvc}, + + //Function creates new mail for plugin + {0, MS_YAMN_CREATEACCOUNTMAIL, CreateAccountMailSvc}, + + //Function deletes plugin account + {0, MS_YAMN_DELETEACCOUNTMAIL, DeleteAccountMailSvc}, + + //Function with which filter plugin can register + {0, MS_YAMN_REGISTERFILTERPLUGIN, RegisterFilterPluginSvc}, + + //Function with which filter plugin can unregister + {0, MS_YAMN_UNREGISTERFILTERPLUGIN, UnregisterFilterPluginSvc}, + + //Function filters mail + {0, MS_YAMN_FILTERMAIL, FilterMailSvc}, + + //Function contact list double click + {0, MS_YAMN_CLISTDBLCLICK, ClistContactDoubleclicked}, + + //Function to check individual account + {0, MS_YAMN_ACCOUNTCHECK, AccountMailCheck}, + + //Function contact list context menu click + {0, MS_YAMN_CLISTCONTEXT, ContactMailCheck}, + + //Function contact list context menu click + {0, MS_YAMN_CLISTCONTEXTAPP, ContactApplication}, + + {0, 0, 0}//end marker +}; + +void CreateServiceFunctions(void) +{ + for (int i = 0;serviceData[i].serviceName;i++) { + serviceData[i].serviceHandle = CreateServiceFunction(serviceData[i].serviceName, serviceData[i].serviceFunction); + } +}; + +void DestroyServiceFunctions(void) +{ + for (int i = 0;serviceData[i].serviceName;i++) { + if (serviceData[i].serviceHandle) DestroyServiceFunction(serviceData[i].serviceHandle); + } +}; + +//Function to put all enabled contact to the Online status +void RefreshContact(void) +{ + HACCOUNT Finder; + for (Finder = POP3Plugin->FirstAccount;Finder != NULL;Finder = Finder->Next) { + if (Finder->hContact != NULL) { + if ((Finder->Flags & YAMN_ACC_ENA) && (Finder->NewMailN.Flags & YAMN_ACC_CONT)) + DBDeleteContactSetting(Finder->hContact, "CList", "Hidden"); + else + DBWriteContactSettingByte(Finder->hContact, "CList", "Hidden", 1); + } + else if ((Finder->Flags & YAMN_ACC_ENA) && (Finder->NewMailN.Flags & YAMN_ACC_CONT)) { + Finder->hContact = (HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0); + CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)Finder->hContact, (LPARAM)YAMN_DBMODULE); + DBWriteContactSettingString(Finder->hContact, YAMN_DBMODULE, "Id", Finder->Name); + DBWriteContactSettingString(Finder->hContact, YAMN_DBMODULE, "Nick", Finder->Name); + DBWriteContactSettingString(Finder->hContact, "Protocol", "p", YAMN_DBMODULE); + DBWriteContactSettingWord(Finder->hContact, YAMN_DBMODULE, "Status", ID_STATUS_ONLINE); + DBWriteContactSettingString(Finder->hContact, "CList", "StatusMsg", Translate("No new mail message")); +} } } diff --git a/protocols/YAMN/src/synchro.cpp b/protocols/YAMN/src/synchro.cpp new file mode 100644 index 0000000000..e510d8bac9 --- /dev/null +++ b/protocols/YAMN/src/synchro.cpp @@ -0,0 +1,359 @@ +/* + * This code implements synchronization objects code between threads. If you want, you can include it to your + * code. This file is not dependent on any other external code (functions) + * + * (c) majvan 2002-2004 + */ + +#include "yamn.h" + +// Initializes a SWMRG structure. This structure must be +// initialized before any writer or reader threads attempt +// to wait on it. +// The structure must be allocated by the application and +// the structure's address is passed as the first parameter. +// The lpszName parameter is the name of the object. Pass +// NULL if you do not want to share the object. +BOOL WINAPI SWMRGInitialize(PSWMRG pSWMRG,TCHAR *Name); + +// Deletes the system resources associated with a SWMRG +// structure. The structure must be deleted only when +// no writer or reader threads in the calling process +// will wait on it. +void WINAPI SWMRGDelete(PSWMRG pSWMRG); + +// A writer thread calls this function to know when +// it can successfully write to the shared data. +// returns WAIT_FINISH when we are in write-access or WAIT_FAILED +// when event about quick finishing is set (or when system returns fail when waiting for synchro object) +DWORD WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG,DWORD dwTimeout); + +// A writer thread calls this function to let other threads +// know that it no longer needs to write to the shared data. +void WINAPI SWMRGDoneWriting(PSWMRG pSWMRG); + +// A reader thread calls this function to know when +// it can successfully read the shared data. +// returns WAIT_FINISH when we are in read-access or WAIT_FAILED +// when event about quick finishing is set (or when system returns fail when waiting for synchro object) +DWORD WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, DWORD dwTimeout); + +// A reader thread calls this function to let other threads +// know when it no longer needs to read the shared data. +void WINAPI SWMRGDoneReading(PSWMRG pSWMRG); + +// WaitToReadFcn +// is used to wait for read access with SWMRG SO, but it also increments counter if successfull +// returns WAIT_FAILED or WAIT_FINISH +// when WAIT_FAILED, we should not begin to access datas, we are not in read-access mode +DWORD WINAPI WaitToReadFcn(PSWMRG SObject); + +// WriteDoneFcn +// is used to release read access with SWMRG SO, but it also decrements counter if successfull +void WINAPI ReadDoneFcn(PSWMRG SObject); + +// This functions is for export purposes +// Plugin can call this function to manage SCOUNTER synchronization object + +// Gets number value stored in SCOUNTER SO +// Note you must not read the number from memory directly, because +// CPU can stop reading thread when it has read HI-Word, then another thread +// can change the value and then OS starts the previous thread, that reads the +// LO-WORD of DWORD. And the return value HI+LO-WORD is corrupted +DWORD WINAPI SCGetNumberFcn(PSCOUNTER SCounter); + +// Increments SCOUNTER and unsets event +// Returns Number after incrementing +DWORD WINAPI SCIncFcn(PSCOUNTER SCounter); + +// Decrements SCOUNTER and sets event if zero +// Returns Number after decrementing +DWORD WINAPI SCDecFcn(PSCOUNTER SCounter); + +struct CExportedFunctions SynchroExportedFcn[]= +{ + {YAMN_WAITTOWRITEID,(void *)WaitToWriteFcn}, + {YAMN_WRITEDONEID,(void *)WriteDoneFcn}, + {YAMN_WAITTOREADID,(void *)WaitToReadFcn}, + {YAMN_READDONEID,(void *)ReadDoneFcn}, + {YAMN_SCGETNUMBERID,(void *)SCGetNumberFcn}, + {YAMN_SCINCID,(void *)SCIncFcn}, + {YAMN_SCDECID,(void *)SCDecFcn}, +}; + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +void WINAPI SWMRGDelete(PSWMRG pSWMRG) +{ +// Destroys any synchronization objects that were +// successfully created. + if (NULL!=pSWMRG->hEventNoWriter) + CloseHandle(pSWMRG->hEventNoWriter); + if (NULL!=pSWMRG->hEventNoReaders) + CloseHandle(pSWMRG->hEventNoReaders); + if (NULL!=pSWMRG->hSemNumReaders) + CloseHandle(pSWMRG->hSemNumReaders); + if (NULL!=pSWMRG->hFinishEV) + CloseHandle(pSWMRG->hFinishEV); +} + +BOOL WINAPI SWMRGInitialize(PSWMRG pSWMRG,TCHAR *Name) +{ + pSWMRG->hEventNoWriter=NULL; + pSWMRG->hEventNoReaders=NULL; + pSWMRG->hSemNumReaders=NULL; + pSWMRG->hFinishEV=NULL; + +// Creates the automatic-reset event that is signalled when +// no writer threads are writing. +// Initially no reader threads are reading. + if (Name!=NULL) + Name[0]=(TCHAR)'W'; + pSWMRG->hEventNoWriter=CreateEvent(NULL,FALSE,TRUE,Name); + +// Creates the manual-reset event that is signalled when +// no reader threads are reading. +// Initially no reader threads are reading. + if (Name!=NULL) + Name[0]=(TCHAR)'R'; + pSWMRG->hEventNoReaders=CreateEvent(NULL,TRUE,TRUE,Name); + +// Initializes the variable that indicates the number of +// reader threads that are reading. +// Initially no reader threads are reading. + if (Name!=NULL) + Name[0]=(TCHAR)'C'; + pSWMRG->hSemNumReaders=CreateSemaphore(NULL,0,0x7FFFFFFF,Name); + + if (Name!=NULL) + Name[0]=(TCHAR)'F'; + pSWMRG->hFinishEV=CreateEvent(NULL,TRUE,FALSE,Name); + +// If a synchronization object could not be created, +// destroys any created objects and return failure. + if ((NULL==pSWMRG->hEventNoWriter) || (NULL==pSWMRG->hEventNoReaders) || (NULL==pSWMRG->hSemNumReaders) || (NULL==pSWMRG->hFinishEV)) + { + SWMRGDelete(pSWMRG); + return FALSE; + } + return TRUE; +} + +DWORD WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG,DWORD dwTimeout) +{ + DWORD dw; + HANDLE aHandles[2]; + +// We can write if the following are true: +// 1. No other threads are writing. +// 2. No threads are reading. +// But first we have to know if SWMRG structure is not about to delete + aHandles[0]=pSWMRG->hEventNoWriter; + aHandles[1]=pSWMRG->hEventNoReaders; + if (WAIT_OBJECT_0==(dw=WaitForSingleObject(pSWMRG->hFinishEV,0))) + return WAIT_FINISH; + if (WAIT_FAILED==dw) + return dw; + dw=WaitForMultipleObjects(2,aHandles,TRUE,dwTimeout); +// if a request to delete became later, we should not catch it. Try once more to ask if account is not about to delete + if ((dw!=WAIT_FAILED) && (WAIT_OBJECT_0==(WaitForSingleObject(pSWMRG->hFinishEV,0)))) + { + SetEvent(pSWMRG->hEventNoWriter); + return WAIT_FINISH; + } + +// This thread can write to the shared data. +// Automatic event for NoWriter sets hEventNoWriter to nonsignaled after WaitForMultipleObject + +// Because a writer thread is writing, the Event +// should not be reset. This stops other +// writers and readers. + return dw; +} + +void WINAPI SWMRGDoneWriting(PSWMRG pSWMRG) +// Presumably, a writer thread calling this function has +// successfully called WaitToWrite. This means that we +// do not have to wait on any synchronization objects +// here because the writer already owns the Event. +{ +// Allow other writer/reader threads to use +// the SWMRG synchronization object. + SetEvent(pSWMRG->hEventNoWriter); +} + +DWORD WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, DWORD dwTimeout) +{ + DWORD dw; + LONG lPreviousCount; + +// We can read if no threads are writing. +// And there's not request to delete structure + if (WAIT_OBJECT_0==(dw=WaitForSingleObject(pSWMRG->hFinishEV,0))) + return WAIT_FINISH; + if (WAIT_FAILED==dw) + return dw; + dw=WaitForSingleObject(pSWMRG->hEventNoWriter, dwTimeout); +// if a request to delete became later, we should not catch it. Try once more to ask if account is not about to delete + if ((dw!=WAIT_FAILED) && (WAIT_OBJECT_0==(WaitForSingleObject(pSWMRG->hFinishEV,0)))) + { + SetEvent(pSWMRG->hEventNoWriter); + return WAIT_FINISH; + } + + if (dw==WAIT_OBJECT_0) + { + // This thread can read from the shared data. + // Increment the number of reader threads. + // But there can't be more than one thread incrementing readers, + // so this is why we use semaphore. + ReleaseSemaphore(pSWMRG->hSemNumReaders,1,&lPreviousCount); + if (lPreviousCount==0) + // If this is the first reader thread, + // set event to reflect this. Other reader threads can read, no writer thread can write. + ResetEvent(pSWMRG->hEventNoReaders); + + // Allow other writer/reader threads to use + // the SWMRG synchronization object. hEventNoWrite is still non-signaled + // (it looks like writer is processing thread, but it is not true) + SetEvent(pSWMRG->hEventNoWriter); + } + + return(dw); +} + +void WINAPI SWMRGDoneReading(PSWMRG pSWMRG) +{ + HANDLE aHandles[2]; + LONG lNumReaders; + +// We can stop reading if the events are available, +// but when we stop reading we must also decrement the +// number of reader threads. + aHandles[0]=pSWMRG->hEventNoWriter; + aHandles[1]=pSWMRG->hSemNumReaders; + WaitForMultipleObjects(2,aHandles,TRUE,INFINITE); + +// Get the remaining number of readers by releasing the +// semaphore and then restoring the count by immediately +// performing a wait. + ReleaseSemaphore(pSWMRG->hSemNumReaders,1,&lNumReaders); + WaitForSingleObject(pSWMRG->hSemNumReaders,INFINITE); + +// If there are no remaining readers, +// set the event to relect this. + if (lNumReaders==0) + // If there are no reader threads, + // set our event to reflect this. + SetEvent(pSWMRG->hEventNoReaders); + +// Allow other writer/reader threads to use +// the SWMRG synchronization object. +// (it looks like writer is processing thread, but it is not true) + SetEvent(pSWMRG->hEventNoWriter); +} + +DWORD WINAPI WaitToWriteFcn(PSWMRG SObject,PSCOUNTER SCounter) +{ + DWORD EnterCode; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tSO WaitToWrite: %x\n",SObject); +#endif + if (WAIT_OBJECT_0==(EnterCode=SWMRGWaitToWrite(SObject,INFINITE))) + if (SCounter!=NULL) + SCIncFcn(SCounter); + return EnterCode; +} + +void WINAPI WriteDoneFcn(PSWMRG SObject,PSCOUNTER SCounter) +{ +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tSO WriteDone: %x\n",SObject); +#endif + SWMRGDoneWriting(SObject); + if (SCounter!=NULL) + SCDecFcn(SCounter); +} + +DWORD WINAPI WaitToReadFcn(PSWMRG SObject) +{ + DWORD EnterCode; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tSO WaitToRead: %x\n",SObject); +#endif + EnterCode=SWMRGWaitToRead(SObject,INFINITE); + return EnterCode; +} + +void WINAPI ReadDoneFcn(PSWMRG SObject) +{ +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tSO ReadDone: %x\n",SObject); +#endif + SWMRGDoneReading(SObject); +} + +DWORD WINAPI SCGetNumberFcn(PSCOUNTER SCounter) +{ + DWORD Temp; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tGetNumber-cs wait\n"); +#endif + EnterCriticalSection(&SCounter->CounterCS); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tGetNumber-cs enter\n"); +#endif + Temp=SCounter->Number; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tValue: %d\n",Temp); + DebugLog(SynchroFile,"\tGetNumber-cs done\n"); +#endif + LeaveCriticalSection(&SCounter->CounterCS); + return Temp; +} + +DWORD WINAPI SCIncFcn(PSCOUNTER SCounter) +{ + DWORD Temp; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tIncrementValue-cs wait\n"); +#endif + EnterCriticalSection(&SCounter->CounterCS); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tIncrementValue-cs enter\n"); +#endif + Temp=++SCounter->Number; + ResetEvent(SCounter->Event); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tValue: %d\n",Temp); + DebugLog(SynchroFile,"\tIncrementValue-cs done\n"); +#endif + LeaveCriticalSection(&SCounter->CounterCS); + return Temp; +} + +DWORD WINAPI SCDecFcn(PSCOUNTER SCounter) +{ + DWORD Temp; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tDecrementValue-cs wait\n"); +#endif + EnterCriticalSection(&SCounter->CounterCS); +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tDecrementValue-cs enter\n"); +#endif + if (!(Temp=--SCounter->Number)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tDecrementValue-zero ev set\n"); +#endif + SetEvent(SCounter->Event); + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile,"\tValue: %d\n",Temp); + DebugLog(SynchroFile,"\tDecrementValue-cs done\n"); +#endif + LeaveCriticalSection(&SCounter->CounterCS); + return Temp; +} diff --git a/protocols/YAMN/src/version.h b/protocols/YAMN/src/version.h new file mode 100644 index 0000000000..e658cfee0c --- /dev/null +++ b/protocols/YAMN/src/version.h @@ -0,0 +1,3 @@ +#define YAMN_VERSION_H 0,1,2,5 +#define YAMN_VERSION PLUGIN_MAKE_VERSION( 0,1,2,5 ) +#define YAMN_VERSION_C "0.1.2.5" diff --git a/protocols/YAMN/src/yamn.cpp b/protocols/YAMN/src/yamn.cpp new file mode 100644 index 0000000000..c93225e609 --- /dev/null +++ b/protocols/YAMN/src/yamn.cpp @@ -0,0 +1,333 @@ +/* + * This code implements miscellaneous usefull functions + * + * (c) majvan 2002-2004 + */ + +#include "yamn.h" + +#include "m_yamn.h" +#include "m_protoplugin.h" +#include "m_messages.h" +#include "m_synchro.h" +#include "main.h" + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +//Plugin registration CS +//Used if we add (register) plugin to YAMN plugins and when we browse through registered plugins +CRITICAL_SECTION PluginRegCS; + +//AccountWriterCS +//We want to store number of writers of Accounts (number of Accounts used for writing) +//If we want to read all accounts (for saving to file) immidiatelly, we have to wait until no account is changing (no thread writing to account) +SCOUNTER *AccountWriterSO; + +//NoExitEV +//Event that is signaled when there's a request to exit, so no new pop3 check should be performed +HANDLE ExitEV; + +//WriteToFileEV +//If this is signaled, write accounts to file is performed. Set this event if you want to actualize your accounts and messages +HANDLE WriteToFileEV; + +//Returns pointer to YAMN exported function +INT_PTR GetFcnPtrSvc(WPARAM wParam, LPARAM lParam); + +//Returns pointer to YAMN variables +INT_PTR GetVariablesSvc(WPARAM wParam, LPARAM); + +// Function every seconds decrements account counter of seconds and checks if they are 0 +// If yes, creates a POP3 thread to check account +void CALLBACK TimerProc(HWND, UINT, UINT, DWORD); + +// Function called to check all accounts immidialtelly +// no params +INT_PTR ForceCheckSvc(WPARAM, LPARAM); + +//thread is running all the time +//waits for WriteToFileEV and then writes all accounts to file +//DWORD WINAPI FileWritingThread(PVOID); + +// Function is called when Miranda notifies plugin that it is about to exit +// Ensures succesfull end of POP3 checking, sets event that no next checking should be performed +// If there's no writer to account (POP3 thread), saves the results to the file +//not used now, perhaps in the future + + +//int ExitProc(WPARAM wParam, LPARAM lParam); + +//-------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------- + +INT_PTR GetFcnPtrSvc(WPARAM wParam, LPARAM lParam) +{ + register int i; + + for (i=0;iNext) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read wait\n"); +#endif + if (WAIT_OBJECT_0!=SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, 0)) //we want to access accounts immiadtelly + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read enter failed\n"); +#endif + LeaveCriticalSection(&PluginRegCS); + return; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read enter\n"); +#endif + for (ActualAccount=ActualPlugin->Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=ActualAccount->Next) + { + if (ActualAccount->Plugin==NULL || ActualAccount->Plugin->Fcn==NULL) //account not inited + continue; +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read wait\n"); +#endif + if (WAIT_OBJECT_0!=SWMRGWaitToRead(ActualAccount->AccountAccessSO, 0)) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read wait failed\n"); +#endif + continue; + } +#ifdef DEBUG_SYNCHRO + + switch(Status) + { + case ID_STATUS_OFFLINE: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status offline\n"); + break; + case ID_STATUS_ONLINE: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status online\n"); + break; + case ID_STATUS_AWAY: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status away\n"); + break; + case ID_STATUS_DND: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status dnd\n"); + break; + case ID_STATUS_NA: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status na\n"); + break; + case ID_STATUS_OCCUPIED: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status occupied\n"); + break; + case ID_STATUS_FREECHAT: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status freechat\n"); + break; + case ID_STATUS_INVISIBLE: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status invisible\n"); + break; + case ID_STATUS_ONTHEPHONE: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status onthephone\n"); + break; + case ID_STATUS_OUTTOLUNCH: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status outtolunch\n"); + break; + default: + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status unknown\n"); + break; + } +#endif + BOOL isAccountCounting = 0; + if ( + (ActualAccount->Flags & YAMN_ACC_ENA) && + (((ActualAccount->StatusFlags & YAMN_ACC_ST0) && (Status<=ID_STATUS_OFFLINE)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST1) && (Status==ID_STATUS_ONLINE)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST2) && (Status==ID_STATUS_AWAY)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST3) && (Status==ID_STATUS_DND)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST4) && (Status==ID_STATUS_NA)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST5) && (Status==ID_STATUS_OCCUPIED)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST6) && (Status==ID_STATUS_FREECHAT)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST7) && (Status==ID_STATUS_INVISIBLE)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST8) && (Status==ID_STATUS_ONTHEPHONE)) || + ((ActualAccount->StatusFlags & YAMN_ACC_ST9) && (Status==ID_STATUS_OUTTOLUNCH)))) + { + + if ((!ActualAccount->Interval && !ActualAccount->TimeLeft) || ActualAccount->Plugin->Fcn->TimeoutFcnPtr==NULL) + { + goto ChangeIsCountingStatusLabel; + } + if (ActualAccount->TimeLeft){ + ActualAccount->TimeLeft--; + isAccountCounting = TRUE; + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "TimerProc:time left : %i\n", ActualAccount->TimeLeft); +#endif + WindowList_BroadcastAsync(YAMNVar.MessageWnds, WM_YAMN_CHANGETIME, (WPARAM)ActualAccount, (LPARAM)ActualAccount->TimeLeft); + if (!ActualAccount->TimeLeft) + { + struct CheckParam ParamToPlugin={YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_NORMALCHECK, (void *)0, NULL}; + HANDLE NewThread; + + ActualAccount->TimeLeft=ActualAccount->Interval; + if (NULL==(NewThread=CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->TimeoutFcnPtr, &ParamToPlugin, 0, &tid))) + { +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read done\n"); +#endif + ReadDoneFcn(ActualAccount->AccountAccessSO); + continue; + } + else + { + WaitForSingleObject(ThreadRunningEV, INFINITE); + CloseHandle(NewThread); + } + } + + } +ChangeIsCountingStatusLabel: +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read done\n"); +#endif + if (((ActualAccount->isCounting)!=0)!=isAccountCounting){ + ActualAccount->isCounting=isAccountCounting; + WORD cStatus = DBGetContactSettingWord(ActualAccount->hContact, YAMN_DBMODULE, "Status", 0); + switch (cStatus){ + case ID_STATUS_ONLINE: + case ID_STATUS_OFFLINE: + DBWriteContactSettingWord(ActualAccount->hContact, YAMN_DBMODULE, "Status", isAccountCounting?ID_STATUS_ONLINE:ID_STATUS_OFFLINE); + default: break; + } + } + ReadDoneFcn(ActualAccount->AccountAccessSO); + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read done\n"); +#endif + SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); + } + LeaveCriticalSection(&PluginRegCS); + CloseHandle(ThreadRunningEV); + return; +} + +INT_PTR ForceCheckSvc(WPARAM, LPARAM) +{ + PYAMN_PROTOPLUGINQUEUE ActualPlugin; + HACCOUNT ActualAccount; + HANDLE ThreadRunningEV; + DWORD tid; + + //we use event to signal, that running thread has all needed stack parameters copied + if (NULL==(ThreadRunningEV=CreateEvent(NULL, FALSE, FALSE, NULL))) + 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; + EnterCriticalSection(&PluginRegCS); + for (ActualPlugin=FirstProtoPlugin;ActualPlugin!=NULL;ActualPlugin=ActualPlugin->Next) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read wait\n"); + #endif + SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, INFINITE); + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read enter\n"); + #endif + for (ActualAccount=ActualPlugin->Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=ActualAccount->Next) + { + if (ActualAccount->Plugin->Fcn==NULL) //account not inited + continue; + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait\n"); + #endif + if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) + { + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); + #endif + continue; + } + #ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); + #endif + if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) //account cannot be forced to check + { + if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr==NULL) + { + ReadDoneFcn(ActualAccount->AccountAccessSO); + continue; + } + struct CheckParam ParamToPlugin={YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_FORCECHECK, (void *)0, NULL}; + + if (NULL==CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, &ParamToPlugin, 0, &tid)) + { + ReadDoneFcn(ActualAccount->AccountAccessSO); + continue; + } + else + WaitForSingleObject(ThreadRunningEV, INFINITE); + } + ReadDoneFcn(ActualAccount->AccountAccessSO); + } +#ifdef DEBUG_SYNCHRO + DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read done\n"); +#endif + SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); + } + LeaveCriticalSection(&PluginRegCS); + CloseHandle(ThreadRunningEV); + + if (hTTButton) CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTTButton, TTBST_RELEASED); + return 1; +} diff --git a/protocols/YAMN/src/yamn.h b/protocols/YAMN/src/yamn.h new file mode 100644 index 0000000000..c8cd8d596d --- /dev/null +++ b/protocols/YAMN/src/yamn.h @@ -0,0 +1,271 @@ + +#ifndef __YAMN_H +#define __YAMN_H +#ifndef _WIN32_IE + #define _WIN32_IE 0x0400 +#endif +#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 +#endif + +#include +#include +#include +#include +#include //For _chdir() + +#define MIRANDA_VER 0x0A00 + +#include //For hotkeys +#include "win2k.h" +#include "newpluginapi.h" //CallService,UnHookEvent +#include "m_utils.h" //window broadcasting +#include "m_system.h" +#include "m_skin.h" +#include "m_langpack.h" +#include "m_clist.h" +#include "m_clui.h" +#include "m_options.h" +#include "m_database.h" //database +#include "m_contacts.h" //contact +#include "m_protocols.h" //protocols +#include "m_protomod.h" //protocols module +#include "m_protosvc.h" +#include "m_toptoolbar.h" +#include "m_icolib.h" +#include "m_kbdnotify.h" +#include "m_popup.h" +#include "m_account.h" //Account structure and all needed structures to cooperate with YAMN +#include "m_messages.h" //Messages sent to YAMN windows +#include "m_mails.h" //use YAMN's mails +#include "mails/m_decode.h" //use decoding macros (needed for header extracting) +#include "browser/m_browser.h" //we want to run YAMN mailbrowser, no new mail notification and bad connect window +#include "resource.h" +#include "m_protoplugin.h" +#include "m_filterplugin.h" +#include "m_yamn.h" //Main YAMN's variables +#include "m_protoplugin.h" //Protocol registration and so on +#include "m_synchro.h" //Synchronization +#include "debug.h" +#include + + +//From services.cpp +void CreateServiceFunctions(void); +void DestroyServiceFunctions(void); +void HookEvents(void); +void UnhookEvents(void); +void RefreshContact(void); +void ContactDoubleclicked(WPARAM wParam,LPARAM lParam); +INT_PTR ClistContactDoubleclicked(WPARAM wParam, LPARAM lParam); + +extern CRITICAL_SECTION PluginRegCS; +extern SCOUNTER *AccountWriterSO; +extern HANDLE ExitEV; +extern HANDLE WriteToFileEV; + +//From debug.cpp +#undef YAMN_DEBUG +#ifdef YAMN_DEBUG +void InitDebug(); +void UnInitDebug(); +#endif + +//From synchro.cpp +//struct CExportedFunctions SynchroExported[]; + +//From yamn.cpp +INT_PTR GetFcnPtrSvc(WPARAM wParam,LPARAM lParam); +INT_PTR GetVariablesSvc(WPARAM,LPARAM); +void CALLBACK TimerProc(HWND,UINT,UINT,DWORD); +INT_PTR ForceCheckSvc(WPARAM,LPARAM); + +extern struct YAMNExportedFcns *pYAMNFcn; + +//From account.cpp +extern CRITICAL_SECTION AccountStatusCS; +extern CRITICAL_SECTION FileWritingCS; + +INT_PTR CreatePluginAccountSvc(WPARAM wParam,LPARAM lParam); +INT_PTR DeletePluginAccountSvc(WPARAM wParam,LPARAM); +int InitAccount(HACCOUNT Which); +void DeInitAccount(HACCOUNT Which); +void StopSignalFcn(HACCOUNT Which); +void CodeDecodeString(char *Dest,BOOL Encrypt); +DWORD FileToMemory(TCHAR *FileName,char **MemFile,char **End); + +#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) +DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo,char *DebugString); +#endif +DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo); +DWORD ReadMessagesFromMemory(HACCOUNT Which,char **Parser,char *End); +DWORD ReadAccountFromMemory(HACCOUNT Which,char **Parser,TCHAR *End); +INT_PTR AddAccountsFromFileSvc(WPARAM wParam,LPARAM lParam); + +DWORD WriteStringToFile(HANDLE File,char *Source); +DWORD WriteStringToFileW(HANDLE File,WCHAR *Source); + + +DWORD WriteMessagesToFile(HANDLE File,HACCOUNT Which); +DWORD WINAPI WritePOP3Accounts(); +INT_PTR WriteAccountsToFileSvc(WPARAM wParam,LPARAM lParam); +INT_PTR FindAccountByNameSvc(WPARAM wParam,LPARAM lParam); +INT_PTR GetNextFreeAccountSvc(WPARAM wParam,LPARAM lParam); + +INT_PTR DeleteAccountSvc(WPARAM wParam,LPARAM); +DWORD WINAPI DeleteAccountInBackground(LPVOID Which); +int StopAccounts(HYAMNPROTOPLUGIN Plugin); +int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin,BOOL GetAccountBrowserAccess=FALSE); +int DeleteAccounts(HYAMNPROTOPLUGIN Plugin); + +void WINAPI GetStatusFcn(HACCOUNT Which,TCHAR *Value); +void WINAPI SetStatusFcn(HACCOUNT Which,TCHAR *Value); + +INT_PTR UnregisterProtoPlugins(); +INT_PTR RegisterProtocolPluginSvc(WPARAM,LPARAM); +INT_PTR UnregisterProtocolPluginSvc(WPARAM,LPARAM); +INT_PTR GetFileNameSvc(WPARAM,LPARAM); +INT_PTR DeleteFileNameSvc(WPARAM,LPARAM); + +//From filterplugin.cpp +//struct CExportedFunctions FilterPluginExported[]; +INT_PTR UnregisterFilterPlugins(); +INT_PTR RegisterFilterPluginSvc(WPARAM,LPARAM); +INT_PTR UnregisterFilterPluginSvc(WPARAM,LPARAM); +INT_PTR FilterMailSvc(WPARAM,LPARAM); + +//From mails.cpp (MIME) +//struct CExportedFunctions MailExported[]; +INT_PTR CreateAccountMailSvc(WPARAM wParam,LPARAM lParam); +INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam); +INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam); +INT_PTR UnloadMailDataSvc(WPARAM wParam,LPARAM); +INT_PTR SaveMailDataSvc(WPARAM wParam,LPARAM lParam); + +//From mime.cpp +//void WINAPI ExtractHeaderFcn(char *,int,WORD,HYAMNMAIL); //already in MailExported +struct _tcptable +{ + char *NameBase,*NameSub; + BOOLEAN isValid; + unsigned short int CP; +}; +extern struct _tcptable CodePageNamesAll[]; // in mime/decode.cpp +extern int CPLENALL; +extern struct _tcptable *CodePageNamesSupp; // in mime/decode.cpp +extern int CPLENSUPP; + +extern int PosX,PosY,SizeX,SizeY; +extern int HeadPosX,HeadPosY,HeadSizeX,HeadSizeY,HeadSplitPos; + +//#define CPDEFINDEX 63 //ISO-8859-1 +#define CPDEFINDEX 0 //ACP + +//From pop3comm.cpp +int RegisterPOP3Plugin(WPARAM,LPARAM); + +//From mailbrowser.cpp +INT_PTR RunMailBrowserSvc(WPARAM,LPARAM); + +//From badconnect.cpp +INT_PTR RunBadConnectionSvc(WPARAM,LPARAM); + +//From YAMNopts.cpp +int YAMNOptInitSvc(WPARAM,LPARAM); + +//From main.cpp +int PostLoad(WPARAM,LPARAM); //Executed after all plugins loaded YAMN reads mails from file and notify every protocol it should set its functions +int Shutdown(WPARAM,LPARAM); //Executed before Miranda is going to shutdown +int AddTopToolbarIcon(WPARAM,LPARAM); //Executed when TopToolBar plugin loaded Adds bitmap to toolbar + +extern TCHAR UserDirectory[]; //e.g. "F:\WINNT\Profiles\UserXYZ" +extern TCHAR ProfileName[]; //e.g. "majvan" +extern SWMRG *AccountBrowserSO; +extern CRITICAL_SECTION PluginRegCS; +extern YAMN_VARIABLES YAMNVar; +extern HANDLE hNewMailHook; +extern HANDLE WriteToFileEV; +extern HANDLE hTTButton; +extern HCURSOR hCurSplitNS, hCurSplitWE; +extern UINT SecTimer; + +HANDLE WINAPI g_GetIconHandle( int idx ); +HICON WINAPI g_LoadIconEx( int idx, bool big = false ); +void WINAPI g_ReleaseIcon( HICON hIcon ); + +//From synchro.cpp +void WINAPI DeleteMessagesToEndFcn(HACCOUNT Account,HYAMNMAIL From); +DWORD WINAPI WaitToWriteFcn(PSWMRG SObject,PSCOUNTER SCounter=NULL); +void WINAPI WriteDoneFcn(PSWMRG SObject,PSCOUNTER SCounter=NULL); +DWORD WINAPI WaitToReadFcn(PSWMRG SObject); +void WINAPI ReadDoneFcn(PSWMRG SObject); +DWORD WINAPI SCIncFcn(PSCOUNTER SCounter); +DWORD WINAPI SCDecFcn(PSCOUNTER SCounter); +BOOL WINAPI SWMRGInitialize(PSWMRG,TCHAR *); +void WINAPI SWMRGDelete(PSWMRG); +DWORD WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG,DWORD dwTimeout); +void WINAPI SWMRGDoneWriting(PSWMRG pSWMRG); +DWORD WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, DWORD dwTimeout); +void WINAPI SWMRGDoneReading(PSWMRG pSWMRG); + +//From mails.cpp +void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From,HYAMNMAIL Which,int mode); +void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From,DWORD FlagsSet,DWORD FlagsNotSet,DWORD FlagsToSet,int mode); + +//From mime.cpp +void ExtractHeader(struct CMimeItem *items,int &CP,struct CHeader *head); +void ExtractShortHeader(struct CMimeItem *items,struct CShortHeader *head); +void DeleteHeaderContent(struct CHeader *head); +void DeleteShortHeaderContent(struct CShortHeader *head); +char *ExtractFromContentType(char *ContentType,char *value); +WCHAR *ParseMultipartBody(char *src, char *bond); + +//From account.cpp +void WINAPI GetStatusFcn(HACCOUNT Which,TCHAR *Value); +extern int StopAccounts(HYAMNPROTOPLUGIN Plugin); +extern int DeleteAccounts(HYAMNPROTOPLUGIN Plugin); +extern int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin,BOOL GetAccountBrowserAccess); + +extern HYAMNPROTOPLUGIN POP3Plugin; + +//from decode.cpp +int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ); +int DecodeBase64(char *Src,char *Dst,int DstLen); + +//From maild.cpp +extern INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam); +extern INT_PTR UnloadMailDataSvc(WPARAM wParam,LPARAM); +extern INT_PTR SaveMailDataSvc(WPARAM wParam,LPARAM lParam); + +//From filterplugin.cpp +extern PYAMN_FILTERPLUGINQUEUE FirstFilterPlugin; + +//From protoplugin.cpp +extern PYAMN_PROTOPLUGINQUEUE FirstProtoPlugin; + +extern struct CExportedFunctions ProtoPluginExportedFcn[1]; +extern struct CExportedServices ProtoPluginExportedSvc[5]; +//From filterplugin.cpp +extern struct CExportedFunctions FilterPluginExportedFcn[1]; +extern struct CExportedServices FilterPluginExportedSvc[2]; +//From synchro.cpp +extern struct CExportedFunctions SynchroExportedFcn[7]; +//From account.cpp +extern struct CExportedFunctions AccountExportedFcn[2]; +extern struct CExportedServices AccountExportedSvc[9]; +//From mails.cpp (MIME) +extern struct CExportedFunctions MailExportedFcn[8]; +extern struct CExportedServices MailExportedSvc[5]; + +extern char *iconDescs[]; +extern char *iconNames[]; +extern HIMAGELIST CSImages; + +extern void __stdcall SSL_DebugLog( const char *fmt, ... ); + +extern int YAMN_STATUS; + +extern PYAMN_VARIABLES pYAMNVar; +extern HYAMNPROTOPLUGIN POP3Plugin; + +#endif diff --git a/protocols/YAMN/synchro.cpp b/protocols/YAMN/synchro.cpp deleted file mode 100644 index e510d8bac9..0000000000 --- a/protocols/YAMN/synchro.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/* - * This code implements synchronization objects code between threads. If you want, you can include it to your - * code. This file is not dependent on any other external code (functions) - * - * (c) majvan 2002-2004 - */ - -#include "yamn.h" - -// Initializes a SWMRG structure. This structure must be -// initialized before any writer or reader threads attempt -// to wait on it. -// The structure must be allocated by the application and -// the structure's address is passed as the first parameter. -// The lpszName parameter is the name of the object. Pass -// NULL if you do not want to share the object. -BOOL WINAPI SWMRGInitialize(PSWMRG pSWMRG,TCHAR *Name); - -// Deletes the system resources associated with a SWMRG -// structure. The structure must be deleted only when -// no writer or reader threads in the calling process -// will wait on it. -void WINAPI SWMRGDelete(PSWMRG pSWMRG); - -// A writer thread calls this function to know when -// it can successfully write to the shared data. -// returns WAIT_FINISH when we are in write-access or WAIT_FAILED -// when event about quick finishing is set (or when system returns fail when waiting for synchro object) -DWORD WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG,DWORD dwTimeout); - -// A writer thread calls this function to let other threads -// know that it no longer needs to write to the shared data. -void WINAPI SWMRGDoneWriting(PSWMRG pSWMRG); - -// A reader thread calls this function to know when -// it can successfully read the shared data. -// returns WAIT_FINISH when we are in read-access or WAIT_FAILED -// when event about quick finishing is set (or when system returns fail when waiting for synchro object) -DWORD WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, DWORD dwTimeout); - -// A reader thread calls this function to let other threads -// know when it no longer needs to read the shared data. -void WINAPI SWMRGDoneReading(PSWMRG pSWMRG); - -// WaitToReadFcn -// is used to wait for read access with SWMRG SO, but it also increments counter if successfull -// returns WAIT_FAILED or WAIT_FINISH -// when WAIT_FAILED, we should not begin to access datas, we are not in read-access mode -DWORD WINAPI WaitToReadFcn(PSWMRG SObject); - -// WriteDoneFcn -// is used to release read access with SWMRG SO, but it also decrements counter if successfull -void WINAPI ReadDoneFcn(PSWMRG SObject); - -// This functions is for export purposes -// Plugin can call this function to manage SCOUNTER synchronization object - -// Gets number value stored in SCOUNTER SO -// Note you must not read the number from memory directly, because -// CPU can stop reading thread when it has read HI-Word, then another thread -// can change the value and then OS starts the previous thread, that reads the -// LO-WORD of DWORD. And the return value HI+LO-WORD is corrupted -DWORD WINAPI SCGetNumberFcn(PSCOUNTER SCounter); - -// Increments SCOUNTER and unsets event -// Returns Number after incrementing -DWORD WINAPI SCIncFcn(PSCOUNTER SCounter); - -// Decrements SCOUNTER and sets event if zero -// Returns Number after decrementing -DWORD WINAPI SCDecFcn(PSCOUNTER SCounter); - -struct CExportedFunctions SynchroExportedFcn[]= -{ - {YAMN_WAITTOWRITEID,(void *)WaitToWriteFcn}, - {YAMN_WRITEDONEID,(void *)WriteDoneFcn}, - {YAMN_WAITTOREADID,(void *)WaitToReadFcn}, - {YAMN_READDONEID,(void *)ReadDoneFcn}, - {YAMN_SCGETNUMBERID,(void *)SCGetNumberFcn}, - {YAMN_SCINCID,(void *)SCIncFcn}, - {YAMN_SCDECID,(void *)SCDecFcn}, -}; - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -void WINAPI SWMRGDelete(PSWMRG pSWMRG) -{ -// Destroys any synchronization objects that were -// successfully created. - if (NULL!=pSWMRG->hEventNoWriter) - CloseHandle(pSWMRG->hEventNoWriter); - if (NULL!=pSWMRG->hEventNoReaders) - CloseHandle(pSWMRG->hEventNoReaders); - if (NULL!=pSWMRG->hSemNumReaders) - CloseHandle(pSWMRG->hSemNumReaders); - if (NULL!=pSWMRG->hFinishEV) - CloseHandle(pSWMRG->hFinishEV); -} - -BOOL WINAPI SWMRGInitialize(PSWMRG pSWMRG,TCHAR *Name) -{ - pSWMRG->hEventNoWriter=NULL; - pSWMRG->hEventNoReaders=NULL; - pSWMRG->hSemNumReaders=NULL; - pSWMRG->hFinishEV=NULL; - -// Creates the automatic-reset event that is signalled when -// no writer threads are writing. -// Initially no reader threads are reading. - if (Name!=NULL) - Name[0]=(TCHAR)'W'; - pSWMRG->hEventNoWriter=CreateEvent(NULL,FALSE,TRUE,Name); - -// Creates the manual-reset event that is signalled when -// no reader threads are reading. -// Initially no reader threads are reading. - if (Name!=NULL) - Name[0]=(TCHAR)'R'; - pSWMRG->hEventNoReaders=CreateEvent(NULL,TRUE,TRUE,Name); - -// Initializes the variable that indicates the number of -// reader threads that are reading. -// Initially no reader threads are reading. - if (Name!=NULL) - Name[0]=(TCHAR)'C'; - pSWMRG->hSemNumReaders=CreateSemaphore(NULL,0,0x7FFFFFFF,Name); - - if (Name!=NULL) - Name[0]=(TCHAR)'F'; - pSWMRG->hFinishEV=CreateEvent(NULL,TRUE,FALSE,Name); - -// If a synchronization object could not be created, -// destroys any created objects and return failure. - if ((NULL==pSWMRG->hEventNoWriter) || (NULL==pSWMRG->hEventNoReaders) || (NULL==pSWMRG->hSemNumReaders) || (NULL==pSWMRG->hFinishEV)) - { - SWMRGDelete(pSWMRG); - return FALSE; - } - return TRUE; -} - -DWORD WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG,DWORD dwTimeout) -{ - DWORD dw; - HANDLE aHandles[2]; - -// We can write if the following are true: -// 1. No other threads are writing. -// 2. No threads are reading. -// But first we have to know if SWMRG structure is not about to delete - aHandles[0]=pSWMRG->hEventNoWriter; - aHandles[1]=pSWMRG->hEventNoReaders; - if (WAIT_OBJECT_0==(dw=WaitForSingleObject(pSWMRG->hFinishEV,0))) - return WAIT_FINISH; - if (WAIT_FAILED==dw) - return dw; - dw=WaitForMultipleObjects(2,aHandles,TRUE,dwTimeout); -// if a request to delete became later, we should not catch it. Try once more to ask if account is not about to delete - if ((dw!=WAIT_FAILED) && (WAIT_OBJECT_0==(WaitForSingleObject(pSWMRG->hFinishEV,0)))) - { - SetEvent(pSWMRG->hEventNoWriter); - return WAIT_FINISH; - } - -// This thread can write to the shared data. -// Automatic event for NoWriter sets hEventNoWriter to nonsignaled after WaitForMultipleObject - -// Because a writer thread is writing, the Event -// should not be reset. This stops other -// writers and readers. - return dw; -} - -void WINAPI SWMRGDoneWriting(PSWMRG pSWMRG) -// Presumably, a writer thread calling this function has -// successfully called WaitToWrite. This means that we -// do not have to wait on any synchronization objects -// here because the writer already owns the Event. -{ -// Allow other writer/reader threads to use -// the SWMRG synchronization object. - SetEvent(pSWMRG->hEventNoWriter); -} - -DWORD WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, DWORD dwTimeout) -{ - DWORD dw; - LONG lPreviousCount; - -// We can read if no threads are writing. -// And there's not request to delete structure - if (WAIT_OBJECT_0==(dw=WaitForSingleObject(pSWMRG->hFinishEV,0))) - return WAIT_FINISH; - if (WAIT_FAILED==dw) - return dw; - dw=WaitForSingleObject(pSWMRG->hEventNoWriter, dwTimeout); -// if a request to delete became later, we should not catch it. Try once more to ask if account is not about to delete - if ((dw!=WAIT_FAILED) && (WAIT_OBJECT_0==(WaitForSingleObject(pSWMRG->hFinishEV,0)))) - { - SetEvent(pSWMRG->hEventNoWriter); - return WAIT_FINISH; - } - - if (dw==WAIT_OBJECT_0) - { - // This thread can read from the shared data. - // Increment the number of reader threads. - // But there can't be more than one thread incrementing readers, - // so this is why we use semaphore. - ReleaseSemaphore(pSWMRG->hSemNumReaders,1,&lPreviousCount); - if (lPreviousCount==0) - // If this is the first reader thread, - // set event to reflect this. Other reader threads can read, no writer thread can write. - ResetEvent(pSWMRG->hEventNoReaders); - - // Allow other writer/reader threads to use - // the SWMRG synchronization object. hEventNoWrite is still non-signaled - // (it looks like writer is processing thread, but it is not true) - SetEvent(pSWMRG->hEventNoWriter); - } - - return(dw); -} - -void WINAPI SWMRGDoneReading(PSWMRG pSWMRG) -{ - HANDLE aHandles[2]; - LONG lNumReaders; - -// We can stop reading if the events are available, -// but when we stop reading we must also decrement the -// number of reader threads. - aHandles[0]=pSWMRG->hEventNoWriter; - aHandles[1]=pSWMRG->hSemNumReaders; - WaitForMultipleObjects(2,aHandles,TRUE,INFINITE); - -// Get the remaining number of readers by releasing the -// semaphore and then restoring the count by immediately -// performing a wait. - ReleaseSemaphore(pSWMRG->hSemNumReaders,1,&lNumReaders); - WaitForSingleObject(pSWMRG->hSemNumReaders,INFINITE); - -// If there are no remaining readers, -// set the event to relect this. - if (lNumReaders==0) - // If there are no reader threads, - // set our event to reflect this. - SetEvent(pSWMRG->hEventNoReaders); - -// Allow other writer/reader threads to use -// the SWMRG synchronization object. -// (it looks like writer is processing thread, but it is not true) - SetEvent(pSWMRG->hEventNoWriter); -} - -DWORD WINAPI WaitToWriteFcn(PSWMRG SObject,PSCOUNTER SCounter) -{ - DWORD EnterCode; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSO WaitToWrite: %x\n",SObject); -#endif - if (WAIT_OBJECT_0==(EnterCode=SWMRGWaitToWrite(SObject,INFINITE))) - if (SCounter!=NULL) - SCIncFcn(SCounter); - return EnterCode; -} - -void WINAPI WriteDoneFcn(PSWMRG SObject,PSCOUNTER SCounter) -{ -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSO WriteDone: %x\n",SObject); -#endif - SWMRGDoneWriting(SObject); - if (SCounter!=NULL) - SCDecFcn(SCounter); -} - -DWORD WINAPI WaitToReadFcn(PSWMRG SObject) -{ - DWORD EnterCode; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSO WaitToRead: %x\n",SObject); -#endif - EnterCode=SWMRGWaitToRead(SObject,INFINITE); - return EnterCode; -} - -void WINAPI ReadDoneFcn(PSWMRG SObject) -{ -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tSO ReadDone: %x\n",SObject); -#endif - SWMRGDoneReading(SObject); -} - -DWORD WINAPI SCGetNumberFcn(PSCOUNTER SCounter) -{ - DWORD Temp; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetNumber-cs wait\n"); -#endif - EnterCriticalSection(&SCounter->CounterCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tGetNumber-cs enter\n"); -#endif - Temp=SCounter->Number; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tValue: %d\n",Temp); - DebugLog(SynchroFile,"\tGetNumber-cs done\n"); -#endif - LeaveCriticalSection(&SCounter->CounterCS); - return Temp; -} - -DWORD WINAPI SCIncFcn(PSCOUNTER SCounter) -{ - DWORD Temp; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tIncrementValue-cs wait\n"); -#endif - EnterCriticalSection(&SCounter->CounterCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tIncrementValue-cs enter\n"); -#endif - Temp=++SCounter->Number; - ResetEvent(SCounter->Event); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tValue: %d\n",Temp); - DebugLog(SynchroFile,"\tIncrementValue-cs done\n"); -#endif - LeaveCriticalSection(&SCounter->CounterCS); - return Temp; -} - -DWORD WINAPI SCDecFcn(PSCOUNTER SCounter) -{ - DWORD Temp; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tDecrementValue-cs wait\n"); -#endif - EnterCriticalSection(&SCounter->CounterCS); -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tDecrementValue-cs enter\n"); -#endif - if (!(Temp=--SCounter->Number)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tDecrementValue-zero ev set\n"); -#endif - SetEvent(SCounter->Event); - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile,"\tValue: %d\n",Temp); - DebugLog(SynchroFile,"\tDecrementValue-cs done\n"); -#endif - LeaveCriticalSection(&SCounter->CounterCS); - return Temp; -} diff --git a/protocols/YAMN/version.h b/protocols/YAMN/version.h deleted file mode 100644 index e658cfee0c..0000000000 --- a/protocols/YAMN/version.h +++ /dev/null @@ -1,3 +0,0 @@ -#define YAMN_VERSION_H 0,1,2,5 -#define YAMN_VERSION PLUGIN_MAKE_VERSION( 0,1,2,5 ) -#define YAMN_VERSION_C "0.1.2.5" diff --git a/protocols/YAMN/yamn-translation.txt b/protocols/YAMN/yamn-translation.txt deleted file mode 100644 index 7acbad549f..0000000000 --- a/protocols/YAMN/yamn-translation.txt +++ /dev/null @@ -1,184 +0,0 @@ -; Common strings that belong to many files -;[Cancel] -;[Check mail] -;[Default] -;[New Mail] -;[No new mail message] -;[Offline] -;[YAMN] - -; ../../protocols/YAMN/browser/badconnect.cpp -;[ - connection error] -;[Unknown error] - -; ../../protocols/YAMN/browser/mailbrowser.cpp -;[%d new mail message(s), %d total] -;[%s : %d new mail message(s), %d total] -;[- new mail message(s)] -;[Copy All] -;[Copy Selected] -;[Delete confirmation] -;[Do you really want to delete %d selected mails?] -;[Header] -;[No new mail message, %d spam(s)] -;[Value] - -; ../../protocols/YAMN/mails/mime.cpp -;[Part] - -; ../../protocols/YAMN/main.cpp -;[Connect Fail] -;[Launch Application] -;[Neutral] -;[TopToolBar Down] -;[TopToolBar UP] - -; ../../protocols/YAMN/proto/netlib.cpp -;[%s connection] - -; ../../protocols/YAMN/proto/pop3/pop3comm.cpp -;[Account is about to be stopped.] -;[Bad user or password.] -;[Cannot allocate memory for received data.] -;[Cannot connect to POP3 server.] -;[Cannot connect to server with NetLib.] -;[Cannot login to POP3 server.] -;[Cannot read SSL data.] -;[Cannot receive data.] -;[Cannot send data.] -;[Cannot write SSL data.] -;[Connecting to server] -;[DNS lookup error.] -;[Deleting requested mails] -;[Deleting spam] -;[Disconnected] -;[Entering POP3 account] -;[Error %d-%d-%d-%d:] -;[Error connecting socket with SSL.] -;[Error connecting to server with socket.] -;[Error reading account file. Account file corrupted.] -;[Error while copying data to disk occured. File in use?] -;[Error while creating SSL structure.] -;[Error while creating base socket.] -;[Error while executing POP3 command.] -;[Found new version of account book, not compatible with this version of YAMN.] -;[Mail notifier and browser for Miranda IM. Included POP3 protocol.] -;[Memory allocation error while data reading] -;[Memory allocation error.] -;[OpenSSL not loaded.] -;[POP3 plugin- write file error] -;[POP3 protocol (internal)] -;[Reading body %s] -;[Reading file error. File already in use?] -;[Reading new mail messages (%d%% done)] -;[Searching for new mail message] -;[Server does not support APOP authorization.] -;[Server rejected connection with SSL.] -;[Windows socket 2.0 init failed.] -;[YAMN (internal POP3) read error] - -; ../../protocols/YAMN/proto/pop3/pop3opt.cpp -;[Account Test] -;[Account Test (failed)] -;[Accounts] -;[All Files] -;[Cannot allocate memory space for new account] -;[Connection failed message] -;[Delete account confirmation] -;[Do you really want to delete this account?] -;[Executables] -;[General] -;[Input error] -;[Memory error] -;[Network] -;[New Account] -;[No account selected] -;[Please select application to run] -;[Please wait while no account is in use.] -;[Plugins] -;[PopUps] -;[Select executable used for notification] -;[This is not a valid number value] -;[Time left to next check [s]: %d] -;[You have N new mail messages] - -; ../../protocols/YAMN/resources/YAMN.rc -;[..s Popup duration] -;[APOP] -;[Account] -;[Auto retrieve body] -;[Away] -;[Background colour] -;[Check from menu] -;[Check interval [min]:] -;[Check this account] -;[Check while ...] -;[Choose modes] -;[Codepage:] -;[Connection failure notifications] -;[Contact:] -;[Copyright:] -;[DND] -;[Date/Time Representation] -;[Description:] -;[Disable Events] -;[Disable STLS] -;[Don't show seconds] -;[Don't show today's date] -;[Enable Close on Delete Button] -;[Enable YAMN Main Menu] -;[Errors] -;[Execute Application] -;[Free for chat] -;[Installed plugins] -;[Invisible] -;[Keyboard Flash] -;[List4] -;[List5] -;[Mail Notifications] -;[MailBrowser Options] -;[Message] -;[Message notification if failed] -;[Multi popup] -;[N/A] -;[Name:] -;[No new mail notifications] -;[Notifications] -;[OK] -;[Occupied] -;[On the phone] -;[Online] -;[Only check when ...] -;[Options] -;[Out to lunch] -;[Password:] -;[Persistant message] -;[Popup] -;[Popup if no mail] -;[Popup notification if failed] -;[Port:] -;[Preview] -;[Replace nick name] -;[Reset counter] -;[SSL] -;[Server:] -;[Show YAMN as a Protocol (Require Restart)] -;[Show long localised date] -;[Single popup] -;[Sound] -;[Sound notification if failed] -;[Startup check] -;[Status:] -;[Text colour] -;[TopToolBar button \"Check mail\"] -;[Tray Icon] -;[Tray icon notification if failed] -;[Use contact notification for this account] -;[Use custom colour] -;[User Name:] -;[Version:] -;[WWW:] -;[YAMN General Options] - -; ../../protocols/YAMN/services.cpp -;[Nick] diff --git a/protocols/YAMN/yamn.cpp b/protocols/YAMN/yamn.cpp deleted file mode 100644 index c93225e609..0000000000 --- a/protocols/YAMN/yamn.cpp +++ /dev/null @@ -1,333 +0,0 @@ -/* - * This code implements miscellaneous usefull functions - * - * (c) majvan 2002-2004 - */ - -#include "yamn.h" - -#include "m_yamn.h" -#include "m_protoplugin.h" -#include "m_messages.h" -#include "m_synchro.h" -#include "main.h" - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -//Plugin registration CS -//Used if we add (register) plugin to YAMN plugins and when we browse through registered plugins -CRITICAL_SECTION PluginRegCS; - -//AccountWriterCS -//We want to store number of writers of Accounts (number of Accounts used for writing) -//If we want to read all accounts (for saving to file) immidiatelly, we have to wait until no account is changing (no thread writing to account) -SCOUNTER *AccountWriterSO; - -//NoExitEV -//Event that is signaled when there's a request to exit, so no new pop3 check should be performed -HANDLE ExitEV; - -//WriteToFileEV -//If this is signaled, write accounts to file is performed. Set this event if you want to actualize your accounts and messages -HANDLE WriteToFileEV; - -//Returns pointer to YAMN exported function -INT_PTR GetFcnPtrSvc(WPARAM wParam, LPARAM lParam); - -//Returns pointer to YAMN variables -INT_PTR GetVariablesSvc(WPARAM wParam, LPARAM); - -// Function every seconds decrements account counter of seconds and checks if they are 0 -// If yes, creates a POP3 thread to check account -void CALLBACK TimerProc(HWND, UINT, UINT, DWORD); - -// Function called to check all accounts immidialtelly -// no params -INT_PTR ForceCheckSvc(WPARAM, LPARAM); - -//thread is running all the time -//waits for WriteToFileEV and then writes all accounts to file -//DWORD WINAPI FileWritingThread(PVOID); - -// Function is called when Miranda notifies plugin that it is about to exit -// Ensures succesfull end of POP3 checking, sets event that no next checking should be performed -// If there's no writer to account (POP3 thread), saves the results to the file -//not used now, perhaps in the future - - -//int ExitProc(WPARAM wParam, LPARAM lParam); - -//-------------------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------------------- - -INT_PTR GetFcnPtrSvc(WPARAM wParam, LPARAM lParam) -{ - register int i; - - for (i=0;iNext) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read wait\n"); -#endif - if (WAIT_OBJECT_0!=SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, 0)) //we want to access accounts immiadtelly - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read enter failed\n"); -#endif - LeaveCriticalSection(&PluginRegCS); - return; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read enter\n"); -#endif - for (ActualAccount=ActualPlugin->Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=ActualAccount->Next) - { - if (ActualAccount->Plugin==NULL || ActualAccount->Plugin->Fcn==NULL) //account not inited - continue; -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read wait\n"); -#endif - if (WAIT_OBJECT_0!=SWMRGWaitToRead(ActualAccount->AccountAccessSO, 0)) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read wait failed\n"); -#endif - continue; - } -#ifdef DEBUG_SYNCHRO - - switch(Status) - { - case ID_STATUS_OFFLINE: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status offline\n"); - break; - case ID_STATUS_ONLINE: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status online\n"); - break; - case ID_STATUS_AWAY: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status away\n"); - break; - case ID_STATUS_DND: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status dnd\n"); - break; - case ID_STATUS_NA: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status na\n"); - break; - case ID_STATUS_OCCUPIED: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status occupied\n"); - break; - case ID_STATUS_FREECHAT: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status freechat\n"); - break; - case ID_STATUS_INVISIBLE: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status invisible\n"); - break; - case ID_STATUS_ONTHEPHONE: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status onthephone\n"); - break; - case ID_STATUS_OUTTOLUNCH: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status outtolunch\n"); - break; - default: - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read enter status unknown\n"); - break; - } -#endif - BOOL isAccountCounting = 0; - if ( - (ActualAccount->Flags & YAMN_ACC_ENA) && - (((ActualAccount->StatusFlags & YAMN_ACC_ST0) && (Status<=ID_STATUS_OFFLINE)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST1) && (Status==ID_STATUS_ONLINE)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST2) && (Status==ID_STATUS_AWAY)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST3) && (Status==ID_STATUS_DND)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST4) && (Status==ID_STATUS_NA)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST5) && (Status==ID_STATUS_OCCUPIED)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST6) && (Status==ID_STATUS_FREECHAT)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST7) && (Status==ID_STATUS_INVISIBLE)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST8) && (Status==ID_STATUS_ONTHEPHONE)) || - ((ActualAccount->StatusFlags & YAMN_ACC_ST9) && (Status==ID_STATUS_OUTTOLUNCH)))) - { - - if ((!ActualAccount->Interval && !ActualAccount->TimeLeft) || ActualAccount->Plugin->Fcn->TimeoutFcnPtr==NULL) - { - goto ChangeIsCountingStatusLabel; - } - if (ActualAccount->TimeLeft){ - ActualAccount->TimeLeft--; - isAccountCounting = TRUE; - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:time left : %i\n", ActualAccount->TimeLeft); -#endif - WindowList_BroadcastAsync(YAMNVar.MessageWnds, WM_YAMN_CHANGETIME, (WPARAM)ActualAccount, (LPARAM)ActualAccount->TimeLeft); - if (!ActualAccount->TimeLeft) - { - struct CheckParam ParamToPlugin={YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_NORMALCHECK, (void *)0, NULL}; - HANDLE NewThread; - - ActualAccount->TimeLeft=ActualAccount->Interval; - if (NULL==(NewThread=CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->TimeoutFcnPtr, &ParamToPlugin, 0, &tid))) - { -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read done\n"); -#endif - ReadDoneFcn(ActualAccount->AccountAccessSO); - continue; - } - else - { - WaitForSingleObject(ThreadRunningEV, INFINITE); - CloseHandle(NewThread); - } - } - - } -ChangeIsCountingStatusLabel: -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read done\n"); -#endif - if (((ActualAccount->isCounting)!=0)!=isAccountCounting){ - ActualAccount->isCounting=isAccountCounting; - WORD cStatus = DBGetContactSettingWord(ActualAccount->hContact, YAMN_DBMODULE, "Status", 0); - switch (cStatus){ - case ID_STATUS_ONLINE: - case ID_STATUS_OFFLINE: - DBWriteContactSettingWord(ActualAccount->hContact, YAMN_DBMODULE, "Status", isAccountCounting?ID_STATUS_ONLINE:ID_STATUS_OFFLINE); - default: break; - } - } - ReadDoneFcn(ActualAccount->AccountAccessSO); - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "TimerProc:AccountBrowserSO-read done\n"); -#endif - SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); - } - LeaveCriticalSection(&PluginRegCS); - CloseHandle(ThreadRunningEV); - return; -} - -INT_PTR ForceCheckSvc(WPARAM, LPARAM) -{ - PYAMN_PROTOPLUGINQUEUE ActualPlugin; - HACCOUNT ActualAccount; - HANDLE ThreadRunningEV; - DWORD tid; - - //we use event to signal, that running thread has all needed stack parameters copied - if (NULL==(ThreadRunningEV=CreateEvent(NULL, FALSE, FALSE, NULL))) - 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; - EnterCriticalSection(&PluginRegCS); - for (ActualPlugin=FirstProtoPlugin;ActualPlugin!=NULL;ActualPlugin=ActualPlugin->Next) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read wait\n"); - #endif - SWMRGWaitToRead(ActualPlugin->Plugin->AccountBrowserSO, INFINITE); - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read enter\n"); - #endif - for (ActualAccount=ActualPlugin->Plugin->FirstAccount;ActualAccount!=NULL;ActualAccount=ActualAccount->Next) - { - if (ActualAccount->Plugin->Fcn==NULL) //account not inited - continue; - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait\n"); - #endif - if (WAIT_OBJECT_0!=WaitToReadFcn(ActualAccount->AccountAccessSO)) - { - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read wait failed\n"); - #endif - continue; - } - #ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:ActualAccountSO-read enter\n"); - #endif - if ((ActualAccount->Flags & YAMN_ACC_ENA) && (ActualAccount->StatusFlags & YAMN_ACC_FORCE)) //account cannot be forced to check - { - if (ActualAccount->Plugin->Fcn->ForceCheckFcnPtr==NULL) - { - ReadDoneFcn(ActualAccount->AccountAccessSO); - continue; - } - struct CheckParam ParamToPlugin={YAMN_CHECKVERSION, ThreadRunningEV, ActualAccount, YAMN_FORCECHECK, (void *)0, NULL}; - - if (NULL==CreateThread(NULL, 0, (YAMN_STANDARDFCN)ActualAccount->Plugin->Fcn->ForceCheckFcnPtr, &ParamToPlugin, 0, &tid)) - { - ReadDoneFcn(ActualAccount->AccountAccessSO); - continue; - } - else - WaitForSingleObject(ThreadRunningEV, INFINITE); - } - ReadDoneFcn(ActualAccount->AccountAccessSO); - } -#ifdef DEBUG_SYNCHRO - DebugLog(SynchroFile, "ForceCheck:AccountBrowserSO-read done\n"); -#endif - SWMRGDoneReading(ActualPlugin->Plugin->AccountBrowserSO); - } - LeaveCriticalSection(&PluginRegCS); - CloseHandle(ThreadRunningEV); - - if (hTTButton) CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTTButton, TTBST_RELEASED); - return 1; -} diff --git a/protocols/YAMN/yamn.h b/protocols/YAMN/yamn.h deleted file mode 100644 index c9511fd953..0000000000 --- a/protocols/YAMN/yamn.h +++ /dev/null @@ -1,274 +0,0 @@ - -#ifndef __YAMN_H -#define __YAMN_H -#ifndef _WIN32_IE - #define _WIN32_IE 0x0400 -#endif -#ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0501 -#endif - -#include -#include -#include -#include -#include //For _chdir() - -#define MIRANDA_VER 0x0A00 - -#include //For hotkeys -#include "win2k.h" -#include "newpluginapi.h" //CallService,UnHookEvent -#include "m_utils.h" //window broadcasting -#include "m_system.h" -#include "m_skin.h" -#include "m_langpack.h" -#include "m_clist.h" -#include "m_clui.h" -#include "m_options.h" -#include "m_database.h" //database -#include "m_contacts.h" //contact -#include "m_protocols.h" //protocols -#include "m_protomod.h" //protocols module -#include "m_protosvc.h" -#include "m_toptoolbar.h" -#include "m_icolib.h" -#include "m_kbdnotify.h" -#include "m_popup.h" -#include "m_account.h" //Account structure and all needed structures to cooperate with YAMN -#include "m_messages.h" //Messages sent to YAMN windows -#include "m_mails.h" //use YAMN's mails -#include "mails/m_decode.h" //use decoding macros (needed for header extracting) -#include "browser/m_browser.h" //we want to run YAMN mailbrowser, no new mail notification and bad connect window -#include "resources/resource.h" -#include "m_protoplugin.h" -#include "m_filterplugin.h" -#include "m_yamn.h" //Main YAMN's variables -#include "m_protoplugin.h" //Protocol registration and so on -#include "m_synchro.h" //Synchronization -#include "debug.h" -#include - - -//icons definitions -#define ICONSNUMBER 8 - -//From services.cpp -void CreateServiceFunctions(void); -void DestroyServiceFunctions(void); -void HookEvents(void); -void UnhookEvents(void); -void RefreshContact(void); -void ContactDoubleclicked(WPARAM wParam,LPARAM lParam); -INT_PTR ClistContactDoubleclicked(WPARAM wParam, LPARAM lParam); - -extern CRITICAL_SECTION PluginRegCS; -extern SCOUNTER *AccountWriterSO; -extern HANDLE ExitEV; -extern HANDLE WriteToFileEV; - -//From debug.cpp -#undef YAMN_DEBUG -#ifdef YAMN_DEBUG -void InitDebug(); -void UnInitDebug(); -#endif - -//From synchro.cpp -//struct CExportedFunctions SynchroExported[]; - -//From yamn.cpp -INT_PTR GetFcnPtrSvc(WPARAM wParam,LPARAM lParam); -INT_PTR GetVariablesSvc(WPARAM,LPARAM); -void CALLBACK TimerProc(HWND,UINT,UINT,DWORD); -INT_PTR ForceCheckSvc(WPARAM,LPARAM); - -extern struct YAMNExportedFcns *pYAMNFcn; - -//From account.cpp -extern CRITICAL_SECTION AccountStatusCS; -extern CRITICAL_SECTION FileWritingCS; - -INT_PTR CreatePluginAccountSvc(WPARAM wParam,LPARAM lParam); -INT_PTR DeletePluginAccountSvc(WPARAM wParam,LPARAM); -int InitAccount(HACCOUNT Which); -void DeInitAccount(HACCOUNT Which); -void StopSignalFcn(HACCOUNT Which); -void CodeDecodeString(char *Dest,BOOL Encrypt); -DWORD FileToMemory(TCHAR *FileName,char **MemFile,char **End); - -#if defined(DEBUG_FILEREAD) || defined(DEBUG_FILEREADMESSAGES) -DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo,char *DebugString); -#endif -DWORD ReadStringFromMemory(char **Parser,char *End,char **StoreTo); -DWORD ReadMessagesFromMemory(HACCOUNT Which,char **Parser,char *End); -DWORD ReadAccountFromMemory(HACCOUNT Which,char **Parser,TCHAR *End); -INT_PTR AddAccountsFromFileSvc(WPARAM wParam,LPARAM lParam); - -DWORD WriteStringToFile(HANDLE File,char *Source); -DWORD WriteStringToFileW(HANDLE File,WCHAR *Source); - - -DWORD WriteMessagesToFile(HANDLE File,HACCOUNT Which); -DWORD WINAPI WritePOP3Accounts(); -INT_PTR WriteAccountsToFileSvc(WPARAM wParam,LPARAM lParam); -INT_PTR FindAccountByNameSvc(WPARAM wParam,LPARAM lParam); -INT_PTR GetNextFreeAccountSvc(WPARAM wParam,LPARAM lParam); - -INT_PTR DeleteAccountSvc(WPARAM wParam,LPARAM); -DWORD WINAPI DeleteAccountInBackground(LPVOID Which); -int StopAccounts(HYAMNPROTOPLUGIN Plugin); -int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin,BOOL GetAccountBrowserAccess=FALSE); -int DeleteAccounts(HYAMNPROTOPLUGIN Plugin); - -void WINAPI GetStatusFcn(HACCOUNT Which,TCHAR *Value); -void WINAPI SetStatusFcn(HACCOUNT Which,TCHAR *Value); - -INT_PTR UnregisterProtoPlugins(); -INT_PTR RegisterProtocolPluginSvc(WPARAM,LPARAM); -INT_PTR UnregisterProtocolPluginSvc(WPARAM,LPARAM); -INT_PTR GetFileNameSvc(WPARAM,LPARAM); -INT_PTR DeleteFileNameSvc(WPARAM,LPARAM); - -//From filterplugin.cpp -//struct CExportedFunctions FilterPluginExported[]; -INT_PTR UnregisterFilterPlugins(); -INT_PTR RegisterFilterPluginSvc(WPARAM,LPARAM); -INT_PTR UnregisterFilterPluginSvc(WPARAM,LPARAM); -INT_PTR FilterMailSvc(WPARAM,LPARAM); - -//From mails.cpp (MIME) -//struct CExportedFunctions MailExported[]; -INT_PTR CreateAccountMailSvc(WPARAM wParam,LPARAM lParam); -INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam); -INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam); -INT_PTR UnloadMailDataSvc(WPARAM wParam,LPARAM); -INT_PTR SaveMailDataSvc(WPARAM wParam,LPARAM lParam); - -//From mime.cpp -//void WINAPI ExtractHeaderFcn(char *,int,WORD,HYAMNMAIL); //already in MailExported -struct _tcptable -{ - char *NameBase,*NameSub; - BOOLEAN isValid; - unsigned short int CP; -}; -extern struct _tcptable CodePageNamesAll[]; // in mime/decode.cpp -extern int CPLENALL; -extern struct _tcptable *CodePageNamesSupp; // in mime/decode.cpp -extern int CPLENSUPP; - -extern int PosX,PosY,SizeX,SizeY; -extern int HeadPosX,HeadPosY,HeadSizeX,HeadSizeY,HeadSplitPos; - -//#define CPDEFINDEX 63 //ISO-8859-1 -#define CPDEFINDEX 0 //ACP - -//From pop3comm.cpp -int RegisterPOP3Plugin(WPARAM,LPARAM); - -//From mailbrowser.cpp -INT_PTR RunMailBrowserSvc(WPARAM,LPARAM); - -//From badconnect.cpp -INT_PTR RunBadConnectionSvc(WPARAM,LPARAM); - -//From YAMNopts.cpp -int YAMNOptInitSvc(WPARAM,LPARAM); - -//From main.cpp -int PostLoad(WPARAM,LPARAM); //Executed after all plugins loaded YAMN reads mails from file and notify every protocol it should set its functions -int Shutdown(WPARAM,LPARAM); //Executed before Miranda is going to shutdown -int AddTopToolbarIcon(WPARAM,LPARAM); //Executed when TopToolBar plugin loaded Adds bitmap to toolbar - -extern TCHAR UserDirectory[]; //e.g. "F:\WINNT\Profiles\UserXYZ" -extern TCHAR ProfileName[]; //e.g. "majvan" -extern SWMRG *AccountBrowserSO; -extern CRITICAL_SECTION PluginRegCS; -extern YAMN_VARIABLES YAMNVar; -extern HANDLE hNewMailHook; -extern HANDLE WriteToFileEV; -extern HANDLE hTTButton; -extern HCURSOR hCurSplitNS, hCurSplitWE; -extern UINT SecTimer; - -HANDLE WINAPI g_GetIconHandle( int idx ); -HICON WINAPI g_LoadIconEx( int idx, bool big = false ); -void WINAPI g_ReleaseIcon( HICON hIcon ); - -//From synchro.cpp -void WINAPI DeleteMessagesToEndFcn(HACCOUNT Account,HYAMNMAIL From); -DWORD WINAPI WaitToWriteFcn(PSWMRG SObject,PSCOUNTER SCounter=NULL); -void WINAPI WriteDoneFcn(PSWMRG SObject,PSCOUNTER SCounter=NULL); -DWORD WINAPI WaitToReadFcn(PSWMRG SObject); -void WINAPI ReadDoneFcn(PSWMRG SObject); -DWORD WINAPI SCIncFcn(PSCOUNTER SCounter); -DWORD WINAPI SCDecFcn(PSCOUNTER SCounter); -BOOL WINAPI SWMRGInitialize(PSWMRG,TCHAR *); -void WINAPI SWMRGDelete(PSWMRG); -DWORD WINAPI SWMRGWaitToWrite(PSWMRG pSWMRG,DWORD dwTimeout); -void WINAPI SWMRGDoneWriting(PSWMRG pSWMRG); -DWORD WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, DWORD dwTimeout); -void WINAPI SWMRGDoneReading(PSWMRG pSWMRG); - -//From mails.cpp -void WINAPI DeleteMessageFromQueueFcn(HYAMNMAIL *From,HYAMNMAIL Which,int mode); -void WINAPI SetRemoveFlagsInQueueFcn(HYAMNMAIL From,DWORD FlagsSet,DWORD FlagsNotSet,DWORD FlagsToSet,int mode); - -//From mime.cpp -void ExtractHeader(struct CMimeItem *items,int &CP,struct CHeader *head); -void ExtractShortHeader(struct CMimeItem *items,struct CShortHeader *head); -void DeleteHeaderContent(struct CHeader *head); -void DeleteShortHeaderContent(struct CShortHeader *head); -char *ExtractFromContentType(char *ContentType,char *value); -WCHAR *ParseMultipartBody(char *src, char *bond); - -//From account.cpp -void WINAPI GetStatusFcn(HACCOUNT Which,TCHAR *Value); -extern int StopAccounts(HYAMNPROTOPLUGIN Plugin); -extern int DeleteAccounts(HYAMNPROTOPLUGIN Plugin); -extern int WaitForAllAccounts(HYAMNPROTOPLUGIN Plugin,BOOL GetAccountBrowserAccess); - -extern HYAMNPROTOPLUGIN POP3Plugin; - -//from decode.cpp -int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ); -int DecodeBase64(char *Src,char *Dst,int DstLen); - -//From maild.cpp -extern INT_PTR LoadMailDataSvc(WPARAM wParam,LPARAM lParam); -extern INT_PTR UnloadMailDataSvc(WPARAM wParam,LPARAM); -extern INT_PTR SaveMailDataSvc(WPARAM wParam,LPARAM lParam); - -//From filterplugin.cpp -extern PYAMN_FILTERPLUGINQUEUE FirstFilterPlugin; - -//From protoplugin.cpp -extern PYAMN_PROTOPLUGINQUEUE FirstProtoPlugin; - -extern struct CExportedFunctions ProtoPluginExportedFcn[1]; -extern struct CExportedServices ProtoPluginExportedSvc[5]; -//From filterplugin.cpp -extern struct CExportedFunctions FilterPluginExportedFcn[1]; -extern struct CExportedServices FilterPluginExportedSvc[2]; -//From synchro.cpp -extern struct CExportedFunctions SynchroExportedFcn[7]; -//From account.cpp -extern struct CExportedFunctions AccountExportedFcn[2]; -extern struct CExportedServices AccountExportedSvc[9]; -//From mails.cpp (MIME) -extern struct CExportedFunctions MailExportedFcn[8]; -extern struct CExportedServices MailExportedSvc[5]; - -extern char *iconDescs[]; -extern char *iconNames[]; -extern HIMAGELIST CSImages; - -extern void __stdcall SSL_DebugLog( const char *fmt, ... ); - -extern int YAMN_STATUS; - -extern PYAMN_VARIABLES pYAMNVar; -extern HYAMNPROTOPLUGIN POP3Plugin; - -#endif -- cgit v1.2.3