64
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: common email object
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "emailtrace.h"
|
|
19 |
#include <apgcli.h>
|
|
20 |
#include <apmrec.h>
|
|
21 |
#include <mmf/common/mmfcontrollerpluginresolver.h> // CleanupResetAndDestroy
|
|
22 |
|
|
23 |
#include "cfsmailmessage.h"
|
|
24 |
#include "cfsmailplugin.h"
|
|
25 |
#include "cfsmailrequesthandler.h"
|
|
26 |
|
|
27 |
// ================= MEMBER FUNCTIONS ==========================================
|
|
28 |
|
|
29 |
// -----------------------------------------------------------------------------
|
|
30 |
// CFSMailMessage::NewLC
|
|
31 |
// -----------------------------------------------------------------------------
|
|
32 |
EXPORT_C CFSMailMessage * CFSMailMessage::NewLC(TFSMailMsgId aMessageId)
|
|
33 |
{
|
|
34 |
FUNC_LOG;
|
|
35 |
CFSMailMessage* message = new (ELeave) CFSMailMessage();
|
|
36 |
CleanupStack:: PushL(message);
|
|
37 |
message->ConstructL( aMessageId );
|
|
38 |
return message;
|
|
39 |
}
|
|
40 |
|
|
41 |
// -----------------------------------------------------------------------------
|
|
42 |
// CFSMailMessage::NewL
|
|
43 |
// -----------------------------------------------------------------------------
|
|
44 |
EXPORT_C CFSMailMessage * CFSMailMessage::NewL(TFSMailMsgId aMessageId)
|
|
45 |
{
|
|
46 |
FUNC_LOG;
|
|
47 |
CFSMailMessage* message = CFSMailMessage::NewLC(aMessageId);
|
|
48 |
CleanupStack:: Pop(message);
|
|
49 |
return message;
|
|
50 |
}
|
|
51 |
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
// CFSMailMessage::ConstructL
|
|
54 |
// -----------------------------------------------------------------------------
|
|
55 |
void CFSMailMessage::ConstructL( TFSMailMsgId aMessageId )
|
|
56 |
{
|
|
57 |
FUNC_LOG;
|
|
58 |
iMessageId = aMessageId;
|
|
59 |
}
|
|
60 |
|
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
// CFSMailMessage::CFSMailMessage
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
CFSMailMessage::CFSMailMessage() : CFSMailMessagePart()
|
|
65 |
{
|
|
66 |
FUNC_LOG;
|
|
67 |
}
|
|
68 |
|
|
69 |
// -----------------------------------------------------------------------------
|
|
70 |
// CFSMailMessage::~CFSMailMessage
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
EXPORT_C CFSMailMessage::~CFSMailMessage()
|
|
73 |
{
|
|
74 |
FUNC_LOG;
|
|
75 |
|
|
76 |
}
|
|
77 |
|
|
78 |
// -----------------------------------------------------------------------------
|
|
79 |
// CFSMailMessage::SaveMessageL
|
|
80 |
// -----------------------------------------------------------------------------
|
|
81 |
EXPORT_C void CFSMailMessage::SaveMessageL()
|
|
82 |
{
|
|
83 |
FUNC_LOG;
|
|
84 |
if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
|
|
85 |
{
|
|
86 |
plugin->StoreMessageL(GetMailBoxId(),*this);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
// -----------------------------------------------------------------------------
|
|
91 |
// CFSMailMessage::AddNewAttachmentL
|
|
92 |
// -----------------------------------------------------------------------------
|
|
93 |
EXPORT_C CFSMailMessagePart* CFSMailMessage::AddNewAttachmentL( RFile& aFile,
|
|
94 |
const TDesC8& aMimeType )
|
|
95 |
{
|
|
96 |
FUNC_LOG;
|
|
97 |
|
|
98 |
CFSMailMessagePart* newPart = NULL;
|
|
99 |
if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
|
|
100 |
{
|
|
101 |
TBuf<KMaxDataTypeLength> contentType;
|
|
102 |
if(aMimeType.Length() > 0)
|
|
103 |
{
|
|
104 |
// use user given content type
|
|
105 |
contentType.Copy(aMimeType);
|
|
106 |
}
|
|
107 |
else
|
|
108 |
{
|
|
109 |
// try to find out content type using recognizers
|
|
110 |
RApaLsSession apaSession;
|
|
111 |
TDataRecognitionResult dataType;
|
|
112 |
User::LeaveIfError(apaSession.Connect());
|
|
113 |
User::LeaveIfError(apaSession.RecognizeData(aFile, dataType));
|
|
114 |
apaSession.Close();
|
|
115 |
contentType.Copy(dataType.iDataType.Des());
|
|
116 |
}
|
|
117 |
|
|
118 |
// get file name
|
|
119 |
TFileName fileName;
|
|
120 |
aFile.FullName( fileName );
|
|
121 |
|
|
122 |
// get new part from plugin
|
|
123 |
newPart = plugin->NewChildPartFromFileL( GetMailBoxId(),
|
|
124 |
GetFolderId(),
|
|
125 |
GetMessageId(),
|
|
126 |
GetPartId(),
|
|
127 |
contentType,
|
|
128 |
aFile );
|
|
129 |
// set attachment name
|
|
130 |
newPart->SetAttachmentNameL(fileName);
|
|
131 |
|
|
132 |
// store new message part
|
|
133 |
newPart->SaveL();
|
|
134 |
|
|
135 |
// set flag
|
|
136 |
SetFlag(EFSMsgFlag_Attachments);
|
|
137 |
}
|
|
138 |
return newPart;
|
|
139 |
}
|
|
140 |
// -----------------------------------------------------------------------------
|
|
141 |
// CFSMailMessage::AddNewAttachmentL
|
|
142 |
// -----------------------------------------------------------------------------
|
|
143 |
EXPORT_C CFSMailMessagePart* CFSMailMessage::AddNewAttachmentL( const TDesC& aFilePath,
|
|
144 |
const TFSMailMsgId /*aInsertBefore*/ )
|
|
145 |
{
|
|
146 |
FUNC_LOG;
|
|
147 |
|
|
148 |
CFSMailMessagePart* newPart = NULL;
|
|
149 |
|
|
150 |
if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
|
|
151 |
{
|
|
152 |
// use recognizer to find out ContentType
|
|
153 |
RApaLsSession apaSession;
|
|
154 |
TDataRecognitionResult dataType;
|
|
155 |
TBufC8<KMaxDataTypeLength> buf;
|
|
156 |
User::LeaveIfError(apaSession.Connect());
|
|
157 |
User::LeaveIfError(apaSession.RecognizeData(aFilePath, buf, dataType));
|
|
158 |
apaSession.Close();
|
|
159 |
|
|
160 |
// Create new message part with correct Content-Type
|
|
161 |
TBuf<KMaxDataTypeLength> contentType;
|
|
162 |
contentType.Copy(dataType.iDataType.Des());
|
|
163 |
newPart = plugin->NewChildPartFromFileL( GetMailBoxId(),
|
|
164 |
GetFolderId(),
|
|
165 |
GetMessageId(),
|
|
166 |
GetPartId(),
|
|
167 |
contentType,
|
|
168 |
aFilePath );
|
|
169 |
|
|
170 |
|
|
171 |
// Set attachment name
|
|
172 |
newPart->SetAttachmentNameL(aFilePath);
|
|
173 |
|
|
174 |
// store message part
|
|
175 |
newPart->SaveL();
|
|
176 |
|
|
177 |
// set flag
|
|
178 |
SetFlag(EFSMsgFlag_Attachments);
|
|
179 |
}
|
|
180 |
|
|
181 |
return newPart;
|
|
182 |
}
|
|
183 |
|
|
184 |
// -----------------------------------------------------------------------------
|
|
185 |
// CFSMailMessage::AttachmentListL
|
|
186 |
// -----------------------------------------------------------------------------
|
|
187 |
EXPORT_C void CFSMailMessage::AttachmentListL(
|
|
188 |
RPointerArray<CFSMailMessagePart>& aParts )
|
|
189 |
{
|
|
190 |
FUNC_LOG;
|
|
191 |
// First list all message parts
|
|
192 |
AppendAttachmentsL( aParts );
|
|
193 |
|
|
194 |
// special case, if single part content type is not given,
|
|
195 |
// default type is text/plain
|
|
196 |
if ( aParts.Count() == 1 && aParts[0]->GetContentType().Length() == 0)
|
|
197 |
{
|
|
198 |
aParts.ResetAndDestroy();
|
|
199 |
}
|
|
200 |
else
|
|
201 |
{
|
|
202 |
// find plain text body part from the list
|
|
203 |
CFSMailMessagePart* txtPart = FindBodyPartL(KFSMailContentTypeTextPlain);
|
|
204 |
CleanupStack::PushL( txtPart );
|
|
205 |
if ( txtPart
|
|
206 |
&& txtPart->AttachmentNameL().Length() == 0 ) // real attachments have names
|
|
207 |
{
|
|
208 |
// remove plain text body part from attachment list
|
|
209 |
for ( TInt ii = aParts.Count() - 1; ii >= 0; --ii )
|
|
210 |
{
|
|
211 |
if ( aParts[ii]->GetPartId() == txtPart->GetPartId() )
|
|
212 |
{
|
|
213 |
delete aParts[ii];
|
|
214 |
aParts.Remove(ii);
|
|
215 |
break;
|
|
216 |
}
|
|
217 |
}
|
|
218 |
}
|
|
219 |
CleanupStack::PopAndDestroy( txtPart );
|
|
220 |
|
|
221 |
// find html body part from the list
|
|
222 |
CFSMailMessagePart* htmlPart = FindBodyPartL(KFSMailContentTypeTextHtml);
|
|
223 |
CleanupStack::PushL( htmlPart );
|
|
224 |
if ( htmlPart
|
|
225 |
&& htmlPart->AttachmentNameL().Length() == 0 ) // real attachments have names
|
|
226 |
{
|
|
227 |
// remove html body part from attachment list
|
|
228 |
for ( TInt ii = aParts.Count() - 1; ii >= 0; --ii )
|
|
229 |
{
|
|
230 |
if ( aParts[ii]->GetPartId() == htmlPart->GetPartId() )
|
|
231 |
{
|
|
232 |
delete aParts[ii];
|
|
233 |
aParts.Remove(ii);
|
|
234 |
break;
|
|
235 |
}
|
|
236 |
}
|
|
237 |
}
|
|
238 |
CleanupStack::PopAndDestroy( htmlPart );
|
|
239 |
}
|
|
240 |
|
|
241 |
iMessageParts.ResetAndDestroy();
|
|
242 |
iReadMessageParts = ETrue;
|
|
243 |
}
|
|
244 |
|
|
245 |
// -----------------------------------------------------------------------------
|
|
246 |
// CFSMailMessage::PlainTextBodyPartL
|
|
247 |
// -----------------------------------------------------------------------------
|
|
248 |
EXPORT_C CFSMailMessagePart* CFSMailMessage::PlainTextBodyPartL()
|
|
249 |
{
|
|
250 |
FUNC_LOG;
|
|
251 |
CFSMailMessagePart* part = FindBodyPartL(KFSMailContentTypeTextPlain);
|
|
252 |
|
|
253 |
// special case, single part content type is not given
|
|
254 |
if(part == NULL && iMessageParts.Count() == 1 && iMessageParts[0]->GetContentType().Length() == 0)
|
|
255 |
{
|
|
256 |
part = iMessageParts[0];
|
|
257 |
iMessageParts.Remove(0);
|
|
258 |
}
|
|
259 |
iMessageParts.ResetAndDestroy();
|
|
260 |
iReadMessageParts = ETrue;
|
|
261 |
return part;
|
|
262 |
}
|
|
263 |
|
|
264 |
// -----------------------------------------------------------------------------
|
|
265 |
// CFSMailMessage::HtmlBodyPartL
|
|
266 |
// -----------------------------------------------------------------------------
|
|
267 |
EXPORT_C CFSMailMessagePart* CFSMailMessage::HtmlBodyPartL()
|
|
268 |
{
|
|
269 |
FUNC_LOG;
|
|
270 |
CFSMailMessagePart* part = FindBodyPartL(KFSMailContentTypeTextHtml);
|
|
271 |
iMessageParts.ResetAndDestroy();
|
|
272 |
iReadMessageParts = ETrue;
|
|
273 |
return part;
|
|
274 |
}
|
|
275 |
|
|
276 |
// -----------------------------------------------------------------------------
|
|
277 |
// CFSMailMessage::IsMessageL
|
|
278 |
// -----------------------------------------------------------------------------
|
|
279 |
EXPORT_C TBool CFSMailMessage::IsMessageL() const
|
|
280 |
{
|
|
281 |
FUNC_LOG;
|
|
282 |
|
|
283 |
TBuf<KMaxDataTypeLength> ptr;
|
|
284 |
if ( iContentType )
|
|
285 |
{
|
|
286 |
ptr.Copy(iContentType->Des());
|
|
287 |
TInt length = ptr.Locate(';');
|
|
288 |
if(length >= 0)
|
|
289 |
{
|
|
290 |
ptr.SetLength(length);
|
|
291 |
}
|
|
292 |
|
|
293 |
if( !ptr.Compare(KFSMailContentTypeMessage) )
|
|
294 |
{
|
|
295 |
return ETrue;
|
|
296 |
}
|
|
297 |
}
|
|
298 |
return EFalse;
|
|
299 |
}
|
|
300 |
|
|
301 |
// -----------------------------------------------------------------------------
|
|
302 |
// CFSMailMessage::ContentTypeParameters()
|
|
303 |
// -----------------------------------------------------------------------------
|
|
304 |
CDesCArray& CFSMailMessage::ContentTypeParameters()
|
|
305 |
{
|
|
306 |
FUNC_LOG;
|
|
307 |
CDesCArray* faked = NULL;
|
|
308 |
return *faked;
|
|
309 |
}
|
|
310 |
|
|
311 |
// -----------------------------------------------------------------------------
|
|
312 |
// CFSMailMessage::DoAttachmentListL
|
|
313 |
// -----------------------------------------------------------------------------
|
|
314 |
void CFSMailMessage::DoAttachmentListL( RPointerArray<CFSMailMessagePart>& aParts )
|
|
315 |
{
|
|
316 |
FUNC_LOG;
|
|
317 |
AttachmentListL(aParts);
|
|
318 |
}
|
|
319 |
|