|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
12 <task id="GUID-222C2B18-F348-4B16-BB00-E5FAC11AE528" xml:lang="en"><title>Searching |
|
13 Email Messages</title><shortdesc>This section describes how to search for a given string in the |
|
14 email messages.</shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
15 <prereq id="GUID-FBBFDDA9-2462-4B2C-90FF-C9F8BC0B1BF2"><p>Perform the steps |
|
16 described in <xref href="GUID-1DCB0B64-0B70-4F34-81A7-E00A996AD626.dita">Listing, |
|
17 Accessing and Launching Mailboxes</xref>.</p></prereq> |
|
18 <context id="GUID-F089C9E7-E597-40E9-99E5-883553F63EC8"> <p>Email Client |
|
19 provides <xref href="GUID-88C7C842-73DA-3E6C-8EB9-F098F1E13703.dita"><apiname>MEmailSearchObserver</apiname></xref> class for handling email |
|
20 search results and <xref href="GUID-DF759001-8469-37B5-9E3B-53FEB295946F.dita"><apiname>MEmailMessageSearchAsync</apiname></xref> class for initiating |
|
21 the asynchronous search.</p><p>For a specific mailbox, the search function |
|
22 searches for a given string in all the fields of the messages.</p><p>The search |
|
23 client is notified of each found message and the <xref href="GUID-88C7C842-73DA-3E6C-8EB9-F098F1E13703.dita#GUID-88C7C842-73DA-3E6C-8EB9-F098F1E13703/GUID-B05D1394-EF24-3D04-B8AE-6B02D5F9F1A9"><apiname>MEmailSearchObserver::SearchCompletedL()</apiname></xref> method |
|
24 notifies when the search is completed.</p><note> Only one search can be performed |
|
25 at a time. If a search is already in progress, returns <codeph>KErrNotReady</codeph>.</note> |
|
26 </context> |
|
27 <steps id="GUID-4DD07DEC-6017-4237-BE46-1D69E5FBD744-GENID-1-10-1-7-1-1-4-1-3-1-5-1-6-1-3-3"> |
|
28 <step id="GUID-A7151932-CABC-443B-8A6A-8C0E130ABC35"><cmd>Implement the <xref href="GUID-88C7C842-73DA-3E6C-8EB9-F098F1E13703.dita"><apiname>MEmailSearchObserver</apiname></xref> class |
|
29 and initiate the search using <xref href="GUID-FCDFA4A7-2C82-3FE7-8C0B-2035C6602290.dita#GUID-FCDFA4A7-2C82-3FE7-8C0B-2035C6602290/GUID-1E592410-A37E-3F53-9A89-EF248A67F0BE"><apiname>MEmailMailbox::MessageSearchL()</apiname></xref>.</cmd> |
|
30 <info><p><codeblock xml:space="preserve">MEmailMailbox* mailbox = mailboxes[i]; |
|
31 MEmailMessageSearchAsync* search = mailbox->MessageSearchL(); |
|
32 CleanupReleasePushL( *search ); |
|
33 search->StartSearchL( *this ); // this implements MEmailSearchObserver |
|
34 </codeblock></p></info> |
|
35 </step> |
|
36 <step id="GUID-B22C450B-5135-41E5-9113-4958F7E031E4"><cmd>To cancel the search |
|
37 use <xref href="GUID-DF759001-8469-37B5-9E3B-53FEB295946F.dita#GUID-DF759001-8469-37B5-9E3B-53FEB295946F/GUID-2D775D93-1C2C-3D4B-8730-4ED5BE2C9579"><apiname>MEmailMessageSearchAsync::Cancel()</apiname></xref> method.</cmd> |
|
38 </step> |
|
39 </steps> |
|
40 <example><p>The following code snippet shows an example of how to search for |
|
41 a given string on all the mailboxes that are found.</p><codeblock xml:space="preserve">TInt CEmailClientApiTester::SearchWithResultsL( CItemParser& /* aItem */) |
|
42 { |
|
43 TInt ret(KErrNone); |
|
44 MEmailClientApi* mailClient = CreateFactoryAndClientApiLC(); // Factory, client |
|
45 RMailboxPtrArray mailboxes; |
|
46 CleanupResetAndRelease<MEmailMailbox>::PushL( mailboxes ); // Mailboxes |
|
47 mailClient->GetMailboxesL( mailboxes ); |
|
48 if (mailboxes.Count() > 0) |
|
49 { |
|
50 MEmailMailbox* mailbox = mailboxes[0]; // Do the test with the first found mailbox |
|
51 MEmailMessageSearchAsync* searchAPI; |
|
52 searchAPI = mailbox->MessageSearchL(); |
|
53 searchAPI->AddSearchKeyL(_L("Test1")); |
|
54 searchAPI->AddSearchKeyL(_L("Test2")); |
|
55 TEmailSortCriteria criteria; |
|
56 criteria.iAscending = ETrue; |
|
57 criteria.iField = TEmailSortCriteria::EByDate; |
|
58 searchAPI->SetSortCriteriaL(criteria); |
|
59 CSearchObserver* obs = CSearchObserver::NewL(this); |
|
60 CleanupStack::PushL( obs ); |
|
61 searchAPI->StartSearchL(*obs); |
|
62 TInt status = searchAPI->Status(); |
|
63 iLog->Log( _L( "Search started, ascending=true, status=%d"), status); |
|
64 obs->Wait(); |
|
65 searchAPI->Reset(); |
|
66 searchAPI->AddSearchKeyL(_L("Test1")); |
|
67 searchAPI->AddSearchKeyL(_L("Test2")); |
|
68 criteria.iAscending = EFalse; |
|
69 criteria.iField = TEmailSortCriteria::EByDate; |
|
70 searchAPI->SetSortCriteriaL(criteria); |
|
71 searchAPI->StartSearchL(*obs); |
|
72 status = searchAPI->Status(); |
|
73 obs->Wait(); |
|
74 searchAPI->Release(); |
|
75 } |
|
76 else |
|
77 { |
|
78 ret = KErrNotFound; |
|
79 } |
|
80 CleanupStack::PopAndDestroy(4); // factory, mailClient, mailboxes, observer return ret; |
|
81 } |
|
82 </codeblock></example> |
|
83 </taskbody><related-links> |
|
84 <link href="GUID-B87B9E01-F5EB-40F6-A580-A7E46869AE39.dita"><linktext>Email Client |
|
85 API Overview</linktext></link> |
|
86 <link href="GUID-1DCB0B64-0B70-4F34-81A7-E00A996AD626.dita"><linktext>Listing, |
|
87 Accessing and Launching Mailboxes</linktext></link> |
|
88 <link href="GUID-FC308B84-E109-48F3-90F1-78F0C837CC56.dita"><linktext>Creating, |
|
89 Replying and Forwarding Email Messages</linktext></link> |
|
90 </related-links></task> |