16 */ |
16 */ |
17 |
17 |
18 #include "qtemailfetcher.h" |
18 #include "qtemailfetcher.h" |
19 #include <csearchdocument.h> |
19 #include <csearchdocument.h> |
20 #include <cpixmaindefs.h> |
20 #include <cpixmaindefs.h> |
|
21 #include <nmapiemailaddress.h> |
|
22 #include <nmapimessagebody.h> |
|
23 #include <nmapimailbox.h> |
|
24 #include <QTimer> |
|
25 #include <QDebug> |
21 //#include <QThread> //If we happen to use QThread::yieldCurrentThread() |
26 //#include <QThread> //If we happen to use QThread::yieldCurrentThread() |
22 |
27 |
23 //Symbian specific details; picked up from cemailplugin.cpp. |
28 //Symbian specific details; picked up from cemailplugin.cpp. |
24 //Refactor it to cpixmaindefs.h |
29 //Refactor it to cpixmaindefs.h |
25 _LIT(KMsgBaseAppClassGeneric, "root msg email"); |
30 _LIT(KMsgBaseAppClassGeneric, "root msg email"); |
26 |
31 |
27 _LIT(KMsgSubject, "Subject"); |
32 _LIT(KMsgSubject, "Subject"); |
28 _LIT(KMsgRecipients, "Recipients"); |
33 _LIT(KMsgRecipients, "Recipients"); |
29 _LIT(KMsgBody, "Body"); |
34 _LIT(KMsgBody, "Body"); |
|
35 _LIT(KMailBoxId, "MailBoxId"); |
|
36 _LIT(KFolderId, "FolderId"); |
|
37 _LIT(KMailBoxName, "MailBoxName"); |
|
38 _LIT(KFolderName, "FolderName"); |
30 _LIT(KMimeTypeField, CPIX_MIMETYPE_FIELD); |
39 _LIT(KMimeTypeField, CPIX_MIMETYPE_FIELD); |
31 _LIT(KMimeTypeMsg, "Messages"); |
40 _LIT(KMimeTypeMsg, "Messages"); |
|
41 |
|
42 |
32 |
43 |
33 //------------------------------------------------------------------------------ |
44 //------------------------------------------------------------------------------ |
34 QEmailFetcher::QEmailFetcher( MEmailItemObserver& aObserver ) |
45 QEmailFetcher::QEmailFetcher( MEmailItemObserver& aObserver ) |
35 :iEmailObserver( aObserver ), |
46 :iEmailObserver( aObserver ), |
36 iEmailEventNotifier( NULL ), |
47 iEmailEventNotifier( NULL ), |
39 iMailFolderList( NULL ), |
50 iMailFolderList( NULL ), |
40 iEnvelopeListing( NULL ), |
51 iEnvelopeListing( NULL ), |
41 iCurrentMailboxIndex( 0 ), |
52 iCurrentMailboxIndex( 0 ), |
42 iCurrentFolderIndex( 0 ) |
53 iCurrentFolderIndex( 0 ) |
43 { |
54 { |
|
55 qDebug() << "QEmailFetcher::QEmailFetcher"; |
44 } |
56 } |
45 |
57 |
46 //------------------------------------------------------------------------------ |
58 //------------------------------------------------------------------------------ |
47 QEmailFetcher::~QEmailFetcher() |
59 QEmailFetcher::~QEmailFetcher() |
48 { |
60 { |
|
61 iEmailEventNotifier->cancel(); |
49 delete iEmailEventNotifier; |
62 delete iEmailEventNotifier; |
50 delete iEmailService; |
63 delete iEmailService; |
51 delete iMailBoxListings; |
64 delete iMailBoxListings; |
52 delete iMailFolderList; |
65 delete iMailFolderList; |
53 } |
66 } |
54 |
67 |
55 //------------------------------------------------------------------------------ |
68 //------------------------------------------------------------------------------ |
56 QEmailFetcher* QEmailFetcher::newInstance( MEmailItemObserver& aObserver ){ |
69 QEmailFetcher* QEmailFetcher::newInstance( MEmailItemObserver& aObserver ){ |
57 QEmailFetcher* emailFetcher = NULL; |
70 QEmailFetcher* emailFetcher = NULL; |
58 |
71 qDebug() << "QEmailFetcher::newInstance :START"; |
59 //Leak free init. |
72 //Leak free init. |
60 try{ |
73 try{ |
61 QEmailFetcher* emailFetcher = new QEmailFetcher( aObserver ); |
74 emailFetcher = new QEmailFetcher( aObserver ); |
62 emailFetcher->iEmailService = new NmEmailService( emailFetcher ); |
75 emailFetcher->iEmailService = new NmApiEmailService( emailFetcher ); |
63 emailFetcher->iEmailEventNotifier = new NmEventNotifier( emailFetcher ); |
76 emailFetcher->iEmailEventNotifier = new NmApiEventNotifier( emailFetcher ); |
64 emailFetcher->iMailBoxListings = new NmMailboxListing( emailFetcher ); |
77 emailFetcher->iMailBoxListings = new NmApiMailboxListing( emailFetcher ); |
|
78 initialize( emailFetcher ); //Do the rest of the init. |
65 }catch(...){ //cleanup. |
79 }catch(...){ //cleanup. |
|
80 qDebug() << "QEmailFetcher::newInstance ( Catch Block)"; |
66 delete emailFetcher; |
81 delete emailFetcher; |
67 delete emailFetcher->iEmailService; |
82 delete emailFetcher->iEmailService; |
68 delete emailFetcher->iEmailEventNotifier; |
83 delete emailFetcher->iEmailEventNotifier; |
69 delete emailFetcher->iMailBoxListings; |
84 delete emailFetcher->iMailBoxListings; |
70 emailFetcher->iEmailService = NULL; |
85 emailFetcher->iEmailService = NULL; |
71 emailFetcher->iEmailEventNotifier = NULL; |
86 emailFetcher->iEmailEventNotifier = NULL; |
72 emailFetcher->iMailBoxListings = NULL; |
87 emailFetcher->iMailBoxListings = NULL; |
73 throw; //rethrow the exception to caller. |
88 throw; //rethrow the exception to caller. |
74 } |
89 } |
75 initialize( emailFetcher ); //Do the rest of the init. |
90 qDebug() << "QEmailFetcher::newInstance :END"; |
76 return emailFetcher; //returns only if not null. |
91 return emailFetcher; //returns only if not null. |
77 } |
92 } |
78 |
93 |
79 //------------------------------------------------------------------------------ |
94 //------------------------------------------------------------------------------ |
80 void QEmailFetcher::initialize( QEmailFetcher* aThis ){ |
95 void QEmailFetcher::initialize( QEmailFetcher* aThis ){ |
81 //The use of 'aThis' is because the current function is static. |
96 //The use of 'aThis' is because the current function is static. |
|
97 qDebug() << "QEmailFetcher::initialize :START"; |
82 connect( aThis->iEmailService, SIGNAL(initialized(bool)), |
98 connect( aThis->iEmailService, SIGNAL(initialized(bool)), |
83 aThis, SLOT(emailServiceIntialized(bool)) ); |
99 aThis, SLOT(emailServiceIntialized(bool)) ); |
84 aThis->iEmailService->initialise(); |
100 aThis->iEmailService->initialise(); |
|
101 //Monitor for Message changes |
85 aThis->connect( aThis->iEmailEventNotifier, |
102 aThis->connect( aThis->iEmailEventNotifier, |
86 SIGNAL(messageEvent(MessageEvent, quint64, quint64, QList<quint64>)), |
103 SIGNAL(messageEvent(MessageEvent, quint64, quint64, QList<quint64>)), |
87 aThis, |
104 aThis, |
88 SLOT(handleMessageEvent(MessageEvent, quint64, quint64, QList<quint64>)) ); |
105 SLOT(handleMessageEvent(MessageEvent, quint64, quint64, QList<quint64>)) ); |
|
106 //Monitor for Mailbox changes |
|
107 aThis->connect( aThis->iEmailEventNotifier, |
|
108 SIGNAL(mailboxEvent(MailboxEvent, QList<quint64>)), |
|
109 aThis, |
|
110 SLOT(handlemailboxEvent(MailboxEvent, QList<quint64>))); |
|
111 //Start the monitoring |
|
112 aThis->iEmailEventNotifier->start(); |
|
113 qDebug() << "QEmailFetcher::initialize :END"; |
89 } |
114 } |
90 |
115 |
91 //------------------------------------------------------------------------------ |
116 //------------------------------------------------------------------------------ |
92 void QEmailFetcher::emailServiceIntialized(bool aAllOk){ |
117 void QEmailFetcher::emailServiceIntialized(bool aAllOk){ |
|
118 qDebug() << "QEmailFetcher::emailServiceIntialized :START aAllOk = " << aAllOk; |
93 if( aAllOk ){ |
119 if( aAllOk ){ |
94 connect( iMailBoxListings, SIGNAL(mailboxesListed(int)), this, SLOT(handleMailboxesListed(int)) ); |
120 connect( iMailBoxListings, SIGNAL(mailboxesListed(qint32)), this, SLOT(handleMailboxesListed(qint32)) ); |
95 } |
121 } |
|
122 qDebug() << "QEmailFetcher::emailServiceIntialized :END"; |
96 } |
123 } |
97 |
124 |
98 //------------------------------------------------------------------------------ |
125 //------------------------------------------------------------------------------ |
99 void QEmailFetcher::StartHarvesting(){ |
126 void QEmailFetcher::StartHarvesting(){ |
100 iMailBoxListings->start(); |
127 qDebug() << "QEmailFetcher::StartHarvesting :START"; |
|
128 bool ret = iMailBoxListings->start(); |
|
129 qDebug() << "QEmailFetcher::StartHarvesting :END return = " << ret; |
101 } |
130 } |
102 |
131 |
103 //------------------------------------------------------------------------------ |
132 //------------------------------------------------------------------------------ |
104 namespace { |
133 namespace { |
105 |
134 |
128 // buffer = q_check_ptr(HBufC::New(ptr.Length())); |
157 // buffer = q_check_ptr(HBufC::New(ptr.Length())); |
129 // buffer->Des().Copy(ptr); |
158 // buffer->Des().Copy(ptr); |
130 // return buffer; |
159 // return buffer; |
131 //} |
160 //} |
132 |
161 |
133 //------------------------------------------------------------------------------ |
162 CSearchDocument* getPartialSearchDocument( const NmApiMessageEnvelope& aEnvelope ) { |
134 //Private free function creates CSearchDocument from EMailMessageEnvelope. |
163 qDebug() << "getPartialSearchDocument :START"; |
135 CSearchDocument* getSearchDocument( const NmMessageEnvelope& aEnvelope ){ |
164 CSearchDocument* doc = 0; |
136 QList<NmEmailAddress> toList; |
165 QT_TRAP_THROWING( |
|
166 //Use qt_Qstring2TPtrC since we are working with <b>const</b> EmailMessageEnvelope. |
|
167 doc = CSearchDocument::NewL( qt_QString2TPtrC( QString().setNum( aEnvelope.id() ) ), |
|
168 KMsgBaseAppClassGeneric ); |
|
169 ); |
|
170 qDebug() << "getPartialSearchDocument :END"; |
|
171 return doc; |
|
172 } |
|
173 } //anonymous namespace |
|
174 //------------------------------------------------------------------------------ |
|
175 |
|
176 CSearchDocument* QEmailFetcher::getSearchDocument( const NmApiMessageEnvelope& aEnvelope ,quint64 aMailboxId, quint64 aFolderId ){ |
|
177 QList<NmApiEmailAddress> toList; |
|
178 qDebug() << "QEmailFetcher::getSearchDocument :START"; |
137 //Need to cast away const-ness since the get method is unfortunately not const. |
179 //Need to cast away const-ness since the get method is unfortunately not const. |
138 const_cast<NmMessageEnvelope&>(aEnvelope).getToRecipients( toList ); |
180 const_cast<NmApiMessageEnvelope&>(aEnvelope).getToRecipients( toList ); |
139 |
181 |
140 //We need ALL the recipients in a SINGLE field. |
182 //We need ALL the recipients in a SINGLE field. |
141 QString recipients = ""; |
183 QString recipients = ""; |
142 for( int i=0; i<toList.length(); i++ ) |
184 for( int i=0; i<toList.length(); i++ ) |
143 recipients += toList.at( i ).displayName() + " "; //or should we get address? |
185 recipients += toList.at( i ).displayName() + " "; //or should we get address? |
144 |
186 |
145 NmMessageBody body; |
187 NmApiMessageBody body; |
146 //Cast away const-ness since the get method is unfortunately not const. |
188 //Cast away const-ness since the get method is unfortunately not const. |
147 //Returns void. Cannot check for success/failure. |
189 //Returns void. Cannot check for success/failure. |
148 const_cast<NmMessageEnvelope&>(aEnvelope).getPlainTextBody( body ); |
190 const_cast<NmApiMessageEnvelope&>(aEnvelope).getPlainTextBody( body ); |
149 QString msgBody = body.content(); |
191 QString msgBody = body.content(); |
150 |
192 |
151 CSearchDocument* doc = 0; |
193 CSearchDocument* doc = 0; |
152 QT_TRAP_THROWING( |
194 QT_TRAP_THROWING( |
153 //Use qt_Qstring2TPtrC since we are working with <b>const</b> EmailMessageEnvelope. |
195 //Use qt_Qstring2TPtrC since we are working with <b>const</b> EmailMessageEnvelope. |
155 KMsgBaseAppClassGeneric ); |
197 KMsgBaseAppClassGeneric ); |
156 doc->AddFieldL( KMimeTypeField, KMimeTypeMsg, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized); |
198 doc->AddFieldL( KMimeTypeField, KMimeTypeMsg, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized); |
157 doc->AddFieldL( KMsgSubject, qt_QString2TPtrC( aEnvelope.subject() ), CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
199 doc->AddFieldL( KMsgSubject, qt_QString2TPtrC( aEnvelope.subject() ), CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
158 doc->AddFieldL( KMsgRecipients, qt_QString2TPtrC( recipients ), CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
200 doc->AddFieldL( KMsgRecipients, qt_QString2TPtrC( recipients ), CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
159 doc->AddFieldL( KMsgBody, qt_QString2TPtrC( msgBody ), CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
201 doc->AddFieldL( KMsgBody, qt_QString2TPtrC( msgBody ), CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
160 //TODO: What should go in here? |
202 doc->AddFieldL( KMailBoxId, qt_QString2TPtrC( QString().setNum( aMailboxId ) ), CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized ); |
161 doc->AddExcerptL( KNullDesC ); |
203 doc->AddFieldL( KFolderId, qt_QString2TPtrC( QString().setNum( aFolderId ) ), CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized ); |
|
204 |
|
205 // NmApiMailbox aMailBox; |
|
206 // iEmailService->getMailbox( aMailboxId, aMailBox ); |
|
207 // doc->AddFieldL( KMailBoxName, qt_QString2TPtrC(aMailBox.name()) , CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized ); |
|
208 //TODO : Add folder name field |
|
209 //_LIT(KFolderName, "FolderName"); |
|
210 //Adding subject and body to the excerpt. |
|
211 QString excerpt ; |
|
212 excerpt = aEnvelope.subject(); |
|
213 excerpt += msgBody ; |
|
214 doc->AddExcerptL( qt_QString2TPtrC(excerpt) ); |
162 ); |
215 ); |
|
216 qDebug() << "QEmailFetcher::getSearchDocument :END"; |
163 return doc; |
217 return doc; |
164 } |
218 } |
165 } //anonymous namespace |
219 |
166 |
220 |
167 //------------------------------------------------------------------------------ |
221 //------------------------------------------------------------------------------ |
168 //Just to avoid duplication of the following two lines. |
222 //Just to avoid duplication of the following two lines. |
169 void QEmailFetcher::NotifyHarvestingComplete(){ |
223 void QEmailFetcher::NotifyHarvestingComplete(){ |
|
224 qDebug() << "QEmailFetcher::NotifyHarvestingComplete :START"; |
170 iCurrentMailboxIndex = iCurrentFolderIndex = 0; |
225 iCurrentMailboxIndex = iCurrentFolderIndex = 0; |
171 QT_TRAP_THROWING( iEmailObserver.HarvestingCompleted() ); |
226 QT_TRAP_THROWING( iEmailObserver.HarvestingCompleted() ); |
|
227 qDebug() << "QEmailFetcher::NotifyHarvestingComplete :END"; |
172 return; |
228 return; |
173 } |
229 } |
174 |
230 |
175 //------------------------------------------------------------------------------ |
231 //------------------------------------------------------------------------------ |
176 void QEmailFetcher::handleMailboxesListed(int aCount){ |
232 void QEmailFetcher::handleMailboxesListed(qint32 aCount){ |
|
233 qDebug() << "QEmailFetcher::handleMailboxesListed :START"; |
177 iCurrentMailboxIndex = 0; |
234 iCurrentMailboxIndex = 0; |
178 if( aCount == NmMailboxListing::MailboxListingFailed ) { |
235 if( aCount == NmApiMailboxListing::MailboxListingFailed ) { |
179 NotifyHarvestingComplete(); |
236 NotifyHarvestingComplete(); |
|
237 qDebug() << "QEmailFetcher::handleMailboxesListed :MailboxListingFailed"; |
180 return; |
238 return; |
181 } |
239 } |
182 if( aCount>0 && iMailBoxListings->getMailboxes( iMailBoxes ) ){ |
240 if( aCount>0 && iMailBoxListings->getMailboxes( iMailBoxes ) ){ |
183 //Already set to NULL in constructor, so safe to call delete first time. |
241 //Already set to NULL in constructor, so safe to call delete first time. |
|
242 qDebug() << "QEmailFetcher::handleMailboxesListed :processNextMailbox"; |
184 processNextMailbox(); |
243 processNextMailbox(); |
185 }else{ |
244 }else{ |
|
245 qDebug() << "QEmailFetcher::handleMailboxesListed :Harvesting Completed"; |
186 NotifyHarvestingComplete(); |
246 NotifyHarvestingComplete(); |
187 return; |
247 return; |
188 } |
248 } |
189 } |
249 } |
190 |
250 |
202 //QTimer::singleShot(nsecs,nmFolderListing,SLOT(start()); |
262 //QTimer::singleShot(nsecs,nmFolderListing,SLOT(start()); |
203 // |
263 // |
204 //Recommendation: Use option 4. |
264 //Recommendation: Use option 4. |
205 |
265 |
206 void QEmailFetcher::processNextMailbox(){ |
266 void QEmailFetcher::processNextMailbox(){ |
|
267 qDebug() << "QEmailFetcher::processNextMailbox :START"; |
207 //No more mailboxes, notify completion. |
268 //No more mailboxes, notify completion. |
208 if( iCurrentMailboxIndex >= iMailBoxes.count() ) { |
269 if( iCurrentMailboxIndex >= iMailBoxes.count() ) { |
209 NotifyHarvestingComplete(); |
270 NotifyHarvestingComplete(); |
|
271 qDebug() << "QEmailFetcher::processNextMailbox :END (harvesting completed)"; |
210 return; |
272 return; |
211 } |
273 } |
212 |
274 |
213 //More mailboxes available. |
275 //More mailboxes available. |
214 delete iMailFolderList; iMailFolderList = NULL; |
276 delete iMailFolderList; iMailFolderList = NULL; |
215 iMailFolderList = new NmFolderListing( this, iMailBoxes.at( iCurrentMailboxIndex++ ).id() ); |
277 iMailFolderList = new NmApiFolderListing( this, iMailBoxes.at( iCurrentMailboxIndex++ ).id() ); |
216 connect( iMailFolderList, SIGNAL(foldersListed()), this, SLOT(handleMailFoldersListed()) ); |
278 connect( iMailFolderList, SIGNAL(foldersListed( qint32 )), this, SLOT(handleMailFoldersListed( qint32)) ); |
217 const int waitForSeconds = 30; //TODO Move this constant out of here if needed elsewhere |
279 const int waitForSeconds = 30; //TODO Move this constant out of here if needed elsewhere |
218 QTimer::singleShot( waitForSeconds, iMailFolderList, SLOT( start()) ); |
280 QTimer::singleShot( waitForSeconds, iMailFolderList, SLOT( start()) ); |
|
281 qDebug() << "QEmailFetcher::processNextMailbox :END (goto next mailbox)"; |
219 } |
282 } |
220 |
283 |
221 //------------------------------------------------------------------------------ |
284 //------------------------------------------------------------------------------ |
222 void QEmailFetcher::handleMailFoldersListed(int aCount){ |
285 void QEmailFetcher::handleMailFoldersListed(int aCount){ |
223 iCurrentFolderIndex = 0; |
286 qDebug() << "QEmailFetcher::handleMailFoldersListed :START"; |
224 if( aCount == NmFolderListing::FolderListingFailed ){ |
287 iCurrentFolderIndex = 0; |
|
288 if( aCount == NmApiFolderListing::FolderListingFailed ){ |
|
289 qDebug() << "QEmailFetcher::handleMailFoldersListed :FolderListingFailed"; |
225 processNextMailbox(); |
290 processNextMailbox(); |
226 return;//Don't proceed futher. |
291 return;//Don't proceed futher. |
227 } |
292 } |
228 if( aCount && iMailFolderList->getFolders( iFolders ) ){ |
293 if( aCount && iMailFolderList->getFolders( iFolders ) ){ |
|
294 qDebug() << "QEmailFetcher::handleMailFoldersListed :processNextFolder"; |
229 processNextFolder(); |
295 processNextFolder(); |
230 }else{ |
296 }else{ |
|
297 qDebug() << "QEmailFetcher::handleMailFoldersListed :processNextMailbox"; |
231 processNextMailbox(); |
298 processNextMailbox(); |
232 return; |
299 return; |
233 } |
300 } |
234 } |
301 } |
235 |
302 |
236 //------------------------------------------------------------------------------ |
303 //------------------------------------------------------------------------------ |
237 void QEmailFetcher::processNextFolder(){ |
304 void QEmailFetcher::processNextFolder(){ |
|
305 qDebug() << "QEmailFetcher::processNextFolder :START"; |
238 //No more folders in current mailbox. |
306 //No more folders in current mailbox. |
239 if( iCurrentFolderIndex >= iFolders.count() ) { |
307 if( iCurrentFolderIndex >= iFolders.count() ) { |
|
308 qDebug() << "QEmailFetcher::processNextFolder :processNextMailbox"; |
240 processNextMailbox(); |
309 processNextMailbox(); |
241 return;//Don't proceed futher. |
310 return;//Don't proceed futher. |
242 } |
311 } |
243 |
312 |
244 //More folders to process. |
313 //More folders to process. |
245 //Already set to NULL in constructor, so safe to call delete first time. |
314 //Already set to NULL in constructor, so safe to call delete first time. |
246 delete iEnvelopeListing; iEnvelopeListing = NULL; |
315 delete iEnvelopeListing; iEnvelopeListing = NULL; |
247 iEnvelopeListing= new NmEnvelopeListing( |
316 iEnvelopeListing= new NmApiEnvelopeListing( |
248 this, |
317 this, |
249 iFolders.at( iCurrentFolderIndex++ ).id(), |
318 iFolders.at( iCurrentFolderIndex++ ).id(), |
250 iMailBoxes.at( iCurrentMailboxIndex-1 ).id() ); //we have already incremented iMailboxIndex. |
319 iMailBoxes.at( iCurrentMailboxIndex-1 ).id() ); //we have already incremented iMailboxIndex. |
251 |
320 |
252 connect(iEnvelopeListing, SIGNAL(envelopesListed(int)),this,SLOT(processMessages(int))); |
321 connect(iEnvelopeListing, SIGNAL(envelopesListed(qint32)),this,SLOT(processMessages(qint32))); |
253 iEnvelopeListing->start(); |
322 iEnvelopeListing->start(); |
254 } |
323 qDebug() << "QEmailFetcher::processNextFolder :processNextFolder"; |
255 |
324 } |
256 //------------------------------------------------------------------------------ |
325 |
257 void QEmailFetcher::processMessages(int aCount){ |
326 //------------------------------------------------------------------------------ |
258 if( aCount == NmEnvelopeListing::EnvelopeListingFailed ) { |
327 void QEmailFetcher::processMessages(qint32 aCount){ |
|
328 qDebug() << "QEmailFetcher::processMessages :START"; |
|
329 if( aCount == NmApiEnvelopeListing::EnvelopeListingFailed ) { |
|
330 qDebug() << "QEmailFetcher::processMessages :EnvelopeListingFailed"; |
259 processNextFolder(); |
331 processNextFolder(); |
260 return;//Don't proceed futher. |
332 return;//Don't proceed futher. |
261 } |
333 } |
262 QList<NmMessageEnvelope> envelopes; |
334 QList<NmApiMessageEnvelope> envelopes; |
263 if ( aCount > 0 && iEnvelopeListing->getEnvelopes(envelopes) ) { |
335 if ( aCount > 0 && iEnvelopeListing->getEnvelopes(envelopes) ) { |
264 for( int i=0; i<envelopes.count(); i++ ) { |
336 for( int i=0; i<envelopes.count(); i++ ) { |
265 const NmMessageEnvelope &envelope = envelopes.at( i ); |
337 const NmApiMessageEnvelope &envelope = envelopes.at( i ); |
266 //Create document and call back observer. |
338 //Create document and call back observer. |
267 QT_TRAP_THROWING( iEmailObserver.HandleDocumentL( getSearchDocument( envelope ), ECPixAddAction ) ); |
339 QT_TRAP_THROWING( iEmailObserver.HandleDocumentL( getSearchDocument( envelope, iFolders.at( iCurrentFolderIndex -1 ).id(), iMailBoxes.at( iCurrentMailboxIndex-1 ).id() ), |
|
340 ECPixAddAction ) ); |
268 } |
341 } |
269 } |
342 } |
270 } |
343 qDebug() << "QEmailFetcher::processMessages :END"; |
271 |
344 } |
272 //------------------------------------------------------------------------------ |
345 |
273 void QEmailFetcher::handleMessageEvent( const MessageEvent aEvent, quint64 aMailboxId, quint64 aFolderId, QList<quint64> aMessageList){ |
346 //------------------------------------------------------------------------------ |
274 NmMessageEnvelope envelope; |
347 void QEmailFetcher::handleMessageEvent( NmApiMessageEvent aEvent, quint64 aMailboxId, quint64 aFolderId, QList<quint64> aMessageList){ |
|
348 NmApiMessageEnvelope envelope; |
|
349 qDebug() << "QEmailFetcher::handleMessageEvent :START"; |
275 const int messageCount = aMessageList.count(); |
350 const int messageCount = aMessageList.count(); |
276 if( messageCount>0 ){ |
351 if( messageCount>0 ){ |
277 if( aEvent == MessageCreated || aEvent == MessageChanged ){ |
352 if( aEvent == MessageCreated || aEvent == MessageChanged ){ |
|
353 qDebug() << "QEmailFetcher::handleMessageEvent :MessageCreated || MessageChanged"; |
278 for( int i=0; i<messageCount; i++ ){ |
354 for( int i=0; i<messageCount; i++ ){ |
279 if( iEmailService->getEnvelope( aMailboxId, aFolderId, aMessageList.at( i ), envelope ) ){ |
355 if( iEmailService->getEnvelope( aMailboxId, aFolderId, aMessageList.at( i ), envelope ) ){ |
|
356 qDebug() << "QEmailFetcher::handleMessageEvent :HandleDocumentL"; |
280 QT_TRAP_THROWING( |
357 QT_TRAP_THROWING( |
281 iEmailObserver.HandleDocumentL( getSearchDocument( envelope ), |
358 iEmailObserver.HandleDocumentL( getSearchDocument( envelope, aMailboxId, aFolderId ), |
282 //Doing this simply avoids *duplicate* code for update action. |
359 //Doing this simply avoids *duplicate* code for update action. |
283 aEvent == MessageCreated ? ECPixAddAction : ECPixUpdateAction ) ); |
360 aEvent == MessageCreated ? ECPixAddAction : ECPixUpdateAction ) ); |
284 } |
361 } |
285 } |
362 } |
286 } |
363 } |
287 else if( aEvent == MessageDeleted ) { |
364 else if( aEvent == MessageDeleted ) { |
|
365 qDebug() << "QEmailFetcher::handleMessageEvent :MessageDeleted"; |
288 //TODO We can do better. For delete, we dont have to create full document. Just the ID should be enough. |
366 //TODO We can do better. For delete, we dont have to create full document. Just the ID should be enough. |
289 //We can have another function called getPartialSearchDocument so deletes will be faster. |
367 //We can have another function called getPartialSearchDocument so deletes will be faster. |
290 for( int i=0; i<messageCount; i++ ){ |
368 for( int i=0; i<messageCount; i++ ){ |
291 if( iEmailService->getEnvelope( aMailboxId, aFolderId, aMessageList.at( i ), envelope ) ){ |
369 if( iEmailService->getEnvelope( aMailboxId, aFolderId, aMessageList.at( i ), envelope ) ){ |
|
370 qDebug() << "QEmailFetcher::handleMessageEvent :MessageDeleted : HandleDocumentL"; |
292 QT_TRAP_THROWING( |
371 QT_TRAP_THROWING( |
293 iEmailObserver.HandleDocumentL( getSearchDocument( envelope ), ECPixRemoveAction ) ); |
372 iEmailObserver.HandleDocumentL( getPartialSearchDocument( envelope ), ECPixRemoveAction ) ); |
294 } |
373 } |
295 } |
374 } |
296 } |
375 } |
297 } |
376 } |
298 } |
377 } |
|
378 |
|
379 //-------------------------------------------------------------------------------------- |
|
380 void QEmailFetcher::handlemailboxEvent( EmailClientApi::NmApiMailboxEvent event, QList<quint64> idlist ){ |
|
381 const int mailboxCount = idlist.count(); |
|
382 if( event == MailboxCreated ) |
|
383 { |
|
384 //New mailbox is created.Harvest the Mailbox name and all the folder names |
|
385 } |
|
386 else |
|
387 { |
|
388 //MailBox is deleted so delete the document related to all the mailbox and folders in the mailbox |
|
389 } |
|
390 } |
|
391 |
|
392 CSearchDocument* QEmailFetcher::getMailboxorfolderSearchDocument( quint64 aMailboxId, quint64 aFolderId, TEmailDocType aDocType, QString aFoldername ){ |
|
393 |
|
394 CSearchDocument* doc = 0; |
|
395 QT_TRAP_THROWING( |
|
396 //Use qt_Qstring2TPtrC since we are working with <b>const</b> EmailMessageEnvelope. |
|
397 if ( aDocType == EEmailTypeFolder) |
|
398 { |
|
399 doc = CSearchDocument::NewL( qt_QString2TPtrC( QString().setNum( aFolderId ) ), |
|
400 KMsgBaseAppClassGeneric ); |
|
401 doc->AddFieldL( KFolderName, qt_QString2TPtrC(aFoldername) , CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized ); |
|
402 doc->AddFieldL( KFolderId, qt_QString2TPtrC( QString().setNum( aFolderId ) ), CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized ); |
|
403 } |
|
404 else if ( aDocType == EEmailTypeMailBox ) |
|
405 { |
|
406 doc = CSearchDocument::NewL( qt_QString2TPtrC( QString().setNum( aMailboxId ) ), |
|
407 KMsgBaseAppClassGeneric ); |
|
408 NmApiMailbox aMailBox; |
|
409 iEmailService->getMailbox( aMailboxId, aMailBox ); |
|
410 doc->AddFieldL( KMailBoxName, qt_QString2TPtrC(aMailBox.name()) , CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized ); |
|
411 } |
|
412 doc->AddFieldL( KMimeTypeField, KMimeTypeMsg, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized); |
|
413 doc->AddFieldL( KMailBoxId, qt_QString2TPtrC( QString().setNum( aMailboxId ) ), CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized ); |
|
414 |
|
415 ); |
|
416 qDebug() << "QEmailFetcher::getSearchDocument :END"; |
|
417 return doc; |
|
418 } |