diff options
author | George Hazan <george.hazan@gmail.com> | 2023-10-08 15:35:54 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-10-08 15:35:54 +0300 |
commit | f56c7ac5e668acd8633e8c91b438fec506162fc2 (patch) | |
tree | e21c7092611922e9b5d389bacd18854fe0934c2d /protocols/YAMN/src/mails | |
parent | 1572f78c8d183b01614b599f67d7cc29e3b77240 (diff) |
YAMN: another bunch of services removed
Diffstat (limited to 'protocols/YAMN/src/mails')
-rw-r--r-- | protocols/YAMN/src/mails/mails.cpp | 323 |
1 files changed, 126 insertions, 197 deletions
diff --git a/protocols/YAMN/src/mails/mails.cpp b/protocols/YAMN/src/mails/mails.cpp index 87a4faaf42..606a21ebbd 100644 --- a/protocols/YAMN/src/mails/mails.cpp +++ b/protocols/YAMN/src/mails/mails.cpp @@ -6,142 +6,40 @@ #include "../stdafx.h"
- //--------------------------------------------------------------------------------------------------
- //--------------------------------------------------------------------------------------------------
+/////////////////////////////////////////////////////////////////////////////////////////
+// Creates new mail for plugin (calling plugin's constructor, when plugin imported to YAMN)
- // 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(CAccount *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(CAccount *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, uint32_t FlagsSet, uint32_t FlagsNotSet, uint32_t FlagsToSetRemove, int mode);
-
-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)
+HYAMNMAIL CreateAccountMail(CAccount *Account)
{
- CAccount *Account = (CAccount *)wParam;
- uint32_t MailVersion = (uint32_t)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)
+ if (Account->Plugin == nullptr)
return NULL;
- if (Account->Plugin != nullptr) {
- if (Account->Plugin->MailFcn->NewMailFcnPtr != nullptr) {
- //Let plugin create its own structure, which can be derived from CAccount structure
- if (nullptr == (NewMail = Account->Plugin->MailFcn->NewMailFcnPtr(Account, YAMN_MAILVERSION)))
- return NULL;
- }
- else {
- //We suggest plugin uses standard CAccount structure, so we create it
- if (nullptr == (NewMail = new YAMNMAIL))
- //If not created successfully
- return NULL;
- NewMail->MailData = nullptr;
- }
- //Init every members of structure, used by YAMN
- return (INT_PTR)NewMail;
+ if (Account->Plugin->MailFcn->NewMailFcnPtr != nullptr) {
+ // Let plugin create its own structure, which can be derived from CAccount structure
+ if (nullptr == (NewMail = Account->Plugin->MailFcn->NewMailFcnPtr(Account)))
+ return NULL;
}
- return NULL;
+ else {
+ // We suggest plugin uses standard CAccount structure, so we create it
+ NewMail = new YAMNMAIL();
+ NewMail->MailData = nullptr;
+ }
+ // Init every members of structure, used by YAMN
+ return NewMail;
}
-INT_PTR DeleteAccountMailSvc(WPARAM wParam, LPARAM lParam)
+/////////////////////////////////////////////////////////////////////////////////////////
+// Deletes mail for plugin (calling plugin's destructor, when plugin imported to YAMN)
+
+int DeleteAccountMail(YAMN_PROTOPLUGIN *Plugin, HYAMNMAIL OldMail)
{
- YAMN_PROTOPLUGIN *Plugin = (YAMN_PROTOPLUGIN*)wParam;
- HYAMNMAIL OldMail = (HYAMNMAIL)lParam;
struct CMimeItem *TH;
if (Plugin->MailFcn != nullptr) {
if (Plugin->MailFcn->DeleteMailFcnPtr != nullptr) {
- //Let plugin delete its own CMimeMsgQueue derived structure
+ // Let plugin delete its own CMimeMsgQueue derived structure
Plugin->MailFcn->DeleteMailFcnPtr(OldMail);
return 1;
}
@@ -164,10 +62,13 @@ INT_PTR DeleteAccountMailSvc(WPARAM wParam, LPARAM lParam) if (OldMail->ID != nullptr)
delete[] OldMail->ID;
- delete OldMail; //consider mail as standard HYAMNMAIL, not initialized before and use its own destructor
+ delete OldMail; // consider mail as standard HYAMNMAIL, not initialized before and use its own destructor
return 1;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// 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)
{
@@ -176,39 +77,31 @@ void WINAPI AppendQueueFcn(HYAMNMAIL first, HYAMNMAIL second) Finder->Next = second;
}
-INT_PTR LoadMailDataSvc(WPARAM wParam, LPARAM lParam)
-{
- HYAMNMAIL Mail = (HYAMNMAIL)wParam;
- uint32_t MailVersion = (uint32_t)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, LPARAM)
-{
- return 1;
-}
-
-INT_PTR SaveMailDataSvc(WPARAM, LPARAM lParam)
-{
- uint32_t MailVersion = (uint32_t)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;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// 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(CAccount *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)
+// 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;
@@ -218,73 +111,70 @@ void WINAPI SynchroMessagesFcn(CAccount *Account, HYAMNMAIL *OldQueue, HYAMNMAIL if (RemovedNew != nullptr) *RemovedNew = nullptr;
for (FinderPrev = nullptr, Finder = *OldQueue; Finder != nullptr;) {
- if (Finder->Flags & YAMN_MSG_DELETED) //if old queue contains deleted mail
+ 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
+ Finder = Finder->Next; // get next message in old queue for testing
continue;
}
for (ParserPrev = nullptr, Parser = *NewQueue; Parser != nullptr; ParserPrev = Parser, Parser = Parser->Next) {
if (Parser->Flags & YAMN_MSG_DELETED)
continue;
- if (Parser->ID == nullptr) //simply ignore the message, that has not filled its ID
+ if (Parser->ID == nullptr) // simply ignore the message, that has not filled its ID
continue;
- if (0 == mir_strcmp(Parser->ID, Finder->ID)) //search for equal message in new queue
+ if (0 == mir_strcmp(Parser->ID, Finder->ID)) // search for equal message in new queue
break;
}
- if (Parser != nullptr) //found equal message in new queue
- {
+
+ if (Parser != nullptr) { // 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 == nullptr) //delete from new queue
- DeleteAccountMailSvc((WPARAM)Account->Plugin, (LPARAM)Parser);
- else //or move to RemovedNew
- {
- if (RemovedNewParser == nullptr) //if it is first mail removed from NewQueue
- *RemovedNew = Parser; //set RemovedNew queue to point to first message in removed queue
+ Finder->Number = Parser->Number; // rewrite the number of current message in old queue
+
+ if (RemovedNew == nullptr) // delete from new queue
+ DeleteAccountMail(Account->Plugin, Parser);
+ else { // or move to RemovedNew
+ if (RemovedNewParser == nullptr) // 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 = Parser; // else don't forget to show to next message in RemovedNew queue
+ RemovedNewParser = Parser; // follow RemovedNew queue
RemovedNewParser->Next = nullptr;
}
FinderPrev = Finder;
- Finder = Finder->Next; //get next message in old queue for testing
+ 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 == nullptr) //delete from old queue
- DeleteAccountMailSvc((WPARAM)Account->Plugin, (LPARAM)Finder);
- else //or move to RemovedOld
- {
- if (RemovedOldParser == nullptr) //if it is first mail removed from OldQueue
- *RemovedOld = Finder; //set RemovedOld queue to point to first message in removed queue
+ 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 == nullptr) // delete from old queue
+ DeleteAccountMail(Account->Plugin, Finder);
+ else { // or move to RemovedOld
+ if (RemovedOldParser == nullptr) // 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 = Finder; // else don't forget to show to next message in RemovedNew queue
+ RemovedOldParser = Finder; // follow RemovedOld queue
RemovedOldParser->Next = nullptr;
}
Finder = *OldQueue;
}
else {
FinderPrev->Next = Finder->Next;
- if (RemovedOld == nullptr) //delete from old queue
- DeleteAccountMailSvc((WPARAM)Account->Plugin, (LPARAM)Finder);
- else //or move to RemovedOld
- {
- if (RemovedOldParser == nullptr) //if it is first mail removed from OldQueue
- *RemovedOld = Finder; //set RemovedOld queue to point to first message in removed queue
+ // delete from old queue
+ if (RemovedOld == nullptr)
+ DeleteAccountMail(Account->Plugin, Finder);
+ // or move to RemovedOld
+ else {
+ if (RemovedOldParser == nullptr) // 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 = Finder; // else don't forget to show to next message in RemovedNew queue
+ RemovedOldParser = Finder; // follow RemovedOld queue
RemovedOldParser->Next = nullptr;
}
Finder = FinderPrev->Next;
@@ -293,16 +183,27 @@ void WINAPI SynchroMessagesFcn(CAccount *Account, HYAMNMAIL *OldQueue, HYAMNMAIL }
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// 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(CAccount *Account, HYAMNMAIL From)
{
HYAMNMAIL Temp;
while (From != nullptr) {
Temp = From;
From = From->Next;
- DeleteAccountMailSvc((WPARAM)Account->Plugin, (LPARAM)Temp);
+ DeleteAccountMail(Account->Plugin, Temp);
}
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// 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)
{
uint32_t Number = Which->Number;
@@ -332,6 +233,12 @@ void DeleteMessagesFromQueue(HYAMNMAIL *From, HYAMNMAIL Which, int mode = 0) DeleteMessageFromQueueFcn(From, Parser, 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)
{
HYAMNMAIL Browser;
@@ -342,6 +249,13 @@ HYAMNMAIL WINAPI FindMessageByIDFcn(HYAMNMAIL From, char *ID) return Browser;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// 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)
{
try {
@@ -352,8 +266,8 @@ void WINAPI TranslateHeaderFcn(char *stream, int len, struct CMimeItem **head) while (finder <= (stream + len)) {
while (ENDLINEWS(finder)) finder++;
- //at the start of line
- if (DOTLINE(finder + 1)) //at the end of stream
+ // at the start of line
+ if (DOTLINE(finder + 1)) // at the end of stream
break;
prev1 = finder;
@@ -371,7 +285,7 @@ void WINAPI TranslateHeaderFcn(char *stream, int len, struct CMimeItem **head) break;
do {
- if (ENDLINEWS(finder)) finder += 2; //after endline information continues
+ if (ENDLINEWS(finder)) finder += 2; // after endline information continues
while (!ENDLINE(finder) && !EOS(finder)) finder++;
} while (ENDLINEWS(finder));
@@ -407,7 +321,7 @@ void WINAPI TranslateHeaderFcn(char *stream, int len, struct CMimeItem **head) if (prev2 > prev1) { // yes, we have body
Item->Next = new CMimeItem();
Item = Item->Next;
- Item->Next = nullptr;//just in case;
+ Item->Next = nullptr;// just in case;
Item->name = new char[5]; strncpy(Item->name, "Body", 5);
Item->value = new char[prev2 - prev1];
mir_strncpy(Item->value, prev1, prev2 - prev1 - 1);
@@ -422,6 +336,13 @@ 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)
{
HYAMNMAIL FirstMail, Browser = nullptr;
@@ -446,6 +367,14 @@ HYAMNMAIL WINAPI CreateNewDeleteQueueFcn(HYAMNMAIL From) return FirstMail;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// 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, uint32_t FlagsSet, uint32_t FlagsNotSet, uint32_t FlagsToSetRemove, int mode)
{
HYAMNMAIL msgq;
|