Update of /cvsroot/mahogany/M/src/mail
In directory usw-pr-cvs1:/tmp/cvs-serv6662/src/mail
Modified Files:
MailFolderCC.cpp MailFolderCmn.cpp
Log Message:
1. made it possible to return either msgnos or UIDs from MF::SearchMessages()
2. moved the generic implementation to MFCmn from MFCC
Index: MailFolderCC.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/MailFolderCC.cpp,v
retrieving revision 1.625
retrieving revision 1.626
diff -b -u -2 -r1.625 -r1.626
--- MailFolderCC.cpp 4 Jul 2002 17:22:38 -0000 1.625
+++ MailFolderCC.cpp 5 Jul 2002 15:57:06 -0000 1.626
@@ -3870,8 +3870,11 @@
// ----------------------------------------------------------------------------
-MsgnoArray *MailFolderCC::DoSearch(struct search_program *pgm,
- int ccSearchFlags) const
+MsgnoArray *
+MailFolderCC::DoSearch(struct search_program *pgm, int flags) const
{
- CHECK( m_MailStream, NULL, "SearchAndCountResults: folder is closed" );
+ ASSERT_MSG( flags == SEARCH_UID || flags == SEARCH_MSGNO,
+ "DoSearch(): invalid flags value" );
+
+ CHECK( m_MailStream, NULL, "DoSearch(): folder is closed" );
// at best we're going to have a memory leak, at worse c-client is locked
@@ -3882,9 +3885,16 @@
self->m_SearchMessagesFound = new UIdArray;
- // never prefetch the results as we often want to just count them
- //
+ // never prefetch the results as we often want to just count them and
// prefetching messages may also result in unwanted reentrancies so it's
// safer to avoid it
- mail_search_full(m_MailStream, NIL, pgm, ccSearchFlags | SE_NOPREFETCH);
+ //
+ // also, as we never reuse the program, we always free it immediately
+ mail_search_full
+ (
+ m_MailStream,
+ NIL, // charset: use the default US-ASCII
+ pgm,
+ (flags & SEARCH_UID ? SE_UID : 0) | SE_FREE | SE_NOPREFETCH
+ );
CHECK( m_SearchMessagesFound, NULL, "who deleted m_SearchMessagesFound?" );
@@ -3899,5 +3909,5 @@
MailFolderCC::SearchAndCountResults(struct search_program *pgm) const
{
- MsgnoArray *searchResults = DoSearch(pgm, SE_FREE);
+ MsgnoArray *searchResults = DoSearch(pgm);
unsigned long count;
@@ -4012,21 +4022,14 @@
}
- return DoSearch(pgm, SE_FREE | (flags & SEARCH_UID ? SE_UID : 0));
+ return DoSearch(pgm, flags);
}
UIdArray *
-MailFolderCC::SearchMessages(const SearchCriterium *crit)
+MailFolderCC::SearchMessages(const SearchCriterium *crit, int flags)
{
- CHECK( !m_SearchMessagesFound, NULL, "SearchMessages reentered" );
CHECK( crit, NULL, "no criterium in SearchMessages" );
- HeaderInfoList_obj hil = GetHeaders();
- CHECK( hil, NULL, "no listing in SearchMessages" );
-
- m_SearchMessagesFound = new UIdArray;
-
// server side searching doesn't support all possible search criteria,
// check if it can do this search first
-
SEARCHPGM *pgm = mail_newsearchpgm();
STRINGLIST **slistMatch;
@@ -4063,6 +4066,10 @@
}
- if ( slistMatch )
+ if ( !slistMatch )
{
+ // can't do server side search, fall back to the generic version
+ return MailFolderCmn::SearchMessages(crit, flags);
+ }
+
*slistMatch = mail_newstringlist();
@@ -4084,125 +4091,5 @@
}
- CHECK( m_MailStream, 0, "SearchMessages: folder is closed" );
-
- // the m_SearchMessagesFound array is filled from mm_searched
- mail_search_full (m_MailStream,
- NIL /* charset: use default (US-ASCII) */,
- pgm,
- SE_UID | SE_FREE | SE_NOPREFETCH);
- }
- else // can't do server side search
- {
- // how many did we find?
- unsigned long countFound = 0;
-
- MProgressDialog *progDlg = NULL;
-
- MsgnoType nMessages = GetMessageCount();
- if ( nMessages > (unsigned long)READ_CONFIG(m_Profile,
- MP_FOLDERPROGRESS_THRESHOLD) )
- {
- String msg;
- msg.Printf(_("Searching in %lu messages..."), nMessages);
- {
- MGuiLocker locker;
- progDlg = new MProgressDialog(GetName(),
- msg,
- nMessages,
- NULL,
- false, true);// open a status window:
- }
- }
-
- String what;
- for ( size_t idx = 0; idx < nMessages; idx++ )
- {
- HeaderInfo *hi = hil->GetItemByIndex(idx);
-
- if ( !hi )
- {
- FAIL_MSG( "SearchMessages: can't get header info" );
-
- continue;
- }
-
- if ( crit->m_What == SearchCriterium::SC_SUBJECT )
- {
- what = hi->GetSubject();
- }
- else if ( crit->m_What == SearchCriterium::SC_FROM )
- {
- what = hi->GetFrom();
- }
- else if ( crit->m_What == SearchCriterium::SC_TO )
- {
- what = hi->GetTo();
- }
- else
- {
- Message *msg = GetMessage(hi->GetUId());
- switch ( crit->m_What )
- {
- case SearchCriterium::SC_FULL:
- case SearchCriterium::SC_BODY:
- // FIXME: wrong for body as it checks the whole message
- // including header
- what = msg->FetchText();
- break;
-
- case SearchCriterium::SC_HEADER:
- what = msg->GetHeader();
- break;
-
- case SearchCriterium::SC_CC:
- msg->GetHeaderLine("CC", what);
- break;
-
- default:
- FAIL_MSG("Unknown search criterium!");
- }
-
- msg->DecRef();
- }
-
- bool found = what.Contains(crit->m_Key);
- if(crit->m_Invert)
- found = !found;
- if(found)
- m_SearchMessagesFound->Add(hil->GetItemByIndex(idx)->GetUId());
-
- if(progDlg)
- {
- String msg;
- msg.Printf(_("Searching in %lu messages..."), nMessages);
- String msg2;
- unsigned long cnt = m_SearchMessagesFound->Count();
- if(cnt != countFound)
- {
- msg2.Printf(_(" - %lu matches found."), cnt);
- msg = msg + msg2;
- if ( ! progDlg->Update(idx, msg ) )
- {
- // abort searching
- break;
- }
-
- countFound = cnt;
- }
- else if( !progDlg->Update(idx) )
- {
- // abort searching
- break;
- }
- }
- }
-
- delete progDlg;
- }
-
- UIdArray *rc = m_SearchMessagesFound; // will get freed by caller!
- m_SearchMessagesFound = NULL;
-
- return rc;
+ return DoSearch(pgm, flags);
}
Index: MailFolderCmn.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/MailFolderCmn.cpp,v
retrieving revision 1.95
retrieving revision 1.96
diff -b -u -2 -r1.95 -r1.96
--- MailFolderCmn.cpp 4 Jul 2002 17:22:38 -0000 1.95
+++ MailFolderCmn.cpp 5 Jul 2002 15:57:06 -0000 1.96
@@ -3,10 +3,12 @@
// File name: mail/MailFolderCmn.cpp: generic MailFolder methods which don't
// use cclient (i.e. don't really work with mail folders)
-// Purpose: handling of mail folders with c-client lib
+// Purpose: functions common to all MailFolder implementations, in
+// particular handling of folder closing (including keep alive
+// logic) and the new mail processing (filtering, collecting, ...)
// Author: Karsten Ball�der
// Modified by:
// Created: 02.04.01 (extracted from mail/MailFolder.cpp)
// CVS-ID: $Id$
-// Copyright: (C) 1997-2000 by Karsten Ball�der ([EMAIL PROTECTED])
+// Copyright: (C) 1997-2002 Mahogany Team
// Licence: M license
///////////////////////////////////////////////////////////////////////////////
@@ -44,4 +46,6 @@
#include "UIdArray.h"
+#include "MSearch.h"
+
#include "MFolder.h"
#include "MFilter.h"
@@ -917,4 +921,133 @@
// ----------------------------------------------------------------------------
+// MailFolderCmn searching
+// ----------------------------------------------------------------------------
+
+UIdArray *MailFolderCmn::SearchMessages(const SearchCriterium *crit, int flags)
+{
+ HeaderInfoList_obj hil = GetHeaders();
+ CHECK( hil, NULL, "no listing in SearchMessages" );
+
+ // the search results
+ UIdArray *results = new UIdArray;
+
+ // how many did we find?
+ unsigned long countFound = 0;
+
+ MProgressDialog *progDlg = NULL;
+
+ MsgnoType nMessages = GetMessageCount();
+
+ // show the progress dialog if the search is going to take a long time
+ if ( nMessages > (unsigned long)READ_CONFIG(GetProfile(),
+ MP_FOLDERPROGRESS_THRESHOLD) )
+ {
+ String msg;
+ msg.Printf(_("Searching in %lu messages..."), nMessages);
+
+ progDlg = new MProgressDialog(GetName(),
+ msg,
+ nMessages,
+ NULL,
+ false /* disable parent only */,
+ true /* allow to abort */);
+ }
+
+ // check all messages
+ bool cont = true;
+ String what;
+ for ( size_t idx = 0; idx < nMessages && cont; idx++ )
+ {
+ HeaderInfo *hi = hil->GetItemByIndex(idx);
+
+ if ( !hi )
+ {
+ FAIL_MSG( "SearchMessages: can't get header info" );
+
+ continue;
+ }
+
+ if ( crit->m_What == SearchCriterium::SC_SUBJECT )
+ {
+ what = hi->GetSubject();
+ }
+ else if ( crit->m_What == SearchCriterium::SC_FROM )
+ {
+ what = hi->GetFrom();
+ }
+ else if ( crit->m_What == SearchCriterium::SC_TO )
+ {
+ what = hi->GetTo();
+ }
+ else
+ {
+ Message_obj msg = GetMessage(hi->GetUId());
+ if ( !msg )
+ {
+ FAIL_MSG( "SearchMessages: can't get message" );
+
+ continue;
+ }
+
+ switch ( crit->m_What )
+ {
+ case SearchCriterium::SC_FULL:
+ case SearchCriterium::SC_BODY:
+ // FIXME: wrong for body as it checks the whole message
+ // including header
+ what = msg->FetchText();
+ break;
+
+ case SearchCriterium::SC_HEADER:
+ what = msg->GetHeader();
+ break;
+
+ case SearchCriterium::SC_CC:
+ msg->GetHeaderLine("CC", what);
+ break;
+
+ default:
+ FAIL_MSG("Unknown search criterium!");
+ }
+
+ msg->DecRef();
+ }
+
+ bool found = strstr(what, crit->m_Key) != NULL;
+ if ( found != crit->m_Invert )
+ {
+ // really found, remember its UID or msgno depending on the flags
+ results->Add(flags & SEARCH_UID ? hi->GetUId() : idx + 1);
+ }
+
+ // update the progress dialog and check for abort
+ if ( progDlg )
+ {
+ String msg;
+ msg.Printf(_("Searching in %lu messages..."), nMessages);
+
+ unsigned long cnt = results->Count();
+ if ( cnt != countFound )
+ {
+ String msg2;
+ msg2.Printf(_(" - %lu matches found."), cnt);
+
+ cont = progDlg->Update(idx, msg + msg2);
+
+ countFound = cnt;
+ }
+ else
+ {
+ cont = progDlg->Update(idx);
+ }
+ }
+ }
+
+ delete progDlg;
+
+ return results;
+}
+
+// ----------------------------------------------------------------------------
// MailFolderCmn sorting
// ----------------------------------------------------------------------------
@@ -1496,5 +1629,10 @@
3. we have new mail in some not opened folder and it wasn't copied there by
us - this is like (2) except that mfNew is also NULL and uidsNew is NULL
- is well but countNew is provided instead
+ as well but countNew is provided instead
+
+ The only difference between this case and (2) is that we can't even give
+ detailed new mail notification (i.e. showing the subjects and senders of
+ the new messages) but we just tersely say that "N new messages" were
+ received.
*/
@@ -1896,76 +2034,4 @@
//else: new mail reported by the Python code
}
-
-// ----------------------------------------------------------------------------
-// eliminating duplicate messages code
-// ----------------------------------------------------------------------------
-
-// VZ: disabling this stuff - it is a workaround for the bug which doesn't exist
-// any more
-#if 0
-struct Dup_MsgInfo
-{
- Dup_MsgInfo(const String &s, UIdType id, unsigned long size)
- { m_Id = s; m_UId = id; m_Size = size; }
- String m_Id;
- UIdType m_UId;
- unsigned long m_Size;
-};
-
-KBLIST_DEFINE(Dup_MsgInfoList, Dup_MsgInfo);
-
-UIdType
-MailFolderCmn::DeleteDuplicates()
-{
- HeaderInfoList *hil = GetHeaders();
- if(! hil)
- return 0;
-
- Dup_MsgInfoList mlist;
-
- UIdArray toDelete;
-
- for(size_t idx = 0; idx < hil->Count(); idx++)
- {
- String id = (*hil)[idx]->GetId();
- UIdType uid = (*hil)[idx]->GetUId();
- size_t size = (*hil)[idx]->GetSize();
- bool found = FALSE;
- for(Dup_MsgInfoList::iterator i = mlist.begin();
- i != mlist.end();
- i++)
- if( (**i).m_Id == id )
- {
- /// if new message is larger, keep it instead
- if( (**i).m_Size < size )
- {
- toDelete.Add((**i).m_UId);
- (**i).m_UId = uid;
- (**i).m_Size = size;
- found = FALSE;
- }
- else
- found = TRUE;
- break;
- }
- if(found)
- toDelete.Add(uid);
- else
- {
- Dup_MsgInfo *mi = new Dup_MsgInfo(id, uid, size);
- mlist.push_back(mi);
- }
- }
- hil->DecRef();
-
- if(toDelete.Count() == 0)
- return 0; // nothing to do
-
- if(DeleteMessages(&toDelete,FALSE))
- return toDelete.Count();
- // else - uncommented or compiler thinks there's return without value
- return UID_ILLEGAL; // an error happened
-}
-#endif // 0
// ----------------------------------------------------------------------------
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Bringing you mounds of caffeinated joy.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates