|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // POPSTRAN.H |
|
15 // |
|
16 // |
|
17 |
|
18 #include "popstran.h" |
|
19 #include "msventry.h" // CMsvServerEntry |
|
20 #include <txtetext.h> |
|
21 #include <txtrich.h> |
|
22 #include <miuthdr.h> |
|
23 #include <msvutils.h> |
|
24 #include <msvapi.h> |
|
25 |
|
26 _LIT(KPop3DriveSeparator, ":"); |
|
27 |
|
28 CImPop3TransferMessage* CImPop3TransferMessage::NewL(CMsvServerEntry& aEntry) |
|
29 { |
|
30 CImPop3TransferMessage* self = new (ELeave) CImPop3TransferMessage(aEntry); |
|
31 CActiveScheduler::Add(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 void CImPop3TransferMessage::StartL(TMsvId aSourceMessage, TMsvId aDestFolder, TImPop3TransferMethod aTransferMethod, TRequestStatus& aStatus) |
|
36 { |
|
37 iSourceMessage = aSourceMessage; |
|
38 iDestFolder = aDestFolder; |
|
39 iTransferMethod = aTransferMethod; |
|
40 iReportStatus = &aStatus; |
|
41 |
|
42 User::LeaveIfError(iEntry.SetEntry(aSourceMessage)); |
|
43 TMsvEntry entry = iEntry.Entry(); |
|
44 |
|
45 HBufC* details = HBufC::NewLC(entry.iDetails.Size()); |
|
46 (*details) = entry.iDetails; |
|
47 HBufC* description = HBufC::NewLC(entry.iDescription.Size()); |
|
48 (*description) = entry.iDescription; |
|
49 |
|
50 TFileName mailDirectory; |
|
51 mailDirectory.Append('a' + MessageServer::CurrentDriveL(iEntry.FileSession())); |
|
52 mailDirectory.Append(KPop3DriveSeparator); |
|
53 mailDirectory.Append(KMsvDefaultFolder2); |
|
54 |
|
55 // Get the store filename from the source message |
|
56 TFileName sourceStoreFilename = mailDirectory; |
|
57 User::LeaveIfError(iEntry.SetEntry(aSourceMessage)); |
|
58 |
|
59 TBool storeFound = iEntry.HasStoreL(); |
|
60 if (storeFound) |
|
61 { |
|
62 MsvUtils::ConstructEntryName(iEntry.Entry().iServiceId, iEntry.Entry().Id(), sourceStoreFilename, MsvUtils::EStore); |
|
63 } |
|
64 |
|
65 // Create a message entry in the destination folder |
|
66 iEntry.SetEntry(aDestFolder); |
|
67 TMsvEmailEntry emailEntry(entry); |
|
68 emailEntry.SetVisible(ETrue); |
|
69 emailEntry.iDetails.Set(details->Des()); |
|
70 emailEntry.iDescription.Set(description->Des()); |
|
71 emailEntry.SetDisconnectedOperation(ENoDisconnectedOperations); |
|
72 |
|
73 User::LeaveIfError(iEntry.CreateEntry(emailEntry)); |
|
74 iCopiedMessageId = emailEntry.Id(); |
|
75 |
|
76 User::LeaveIfError(iEntry.SetEntry(emailEntry.Id())); |
|
77 TMsvId newEntry = emailEntry.Id(); |
|
78 |
|
79 // Get the serviceId of the service the destination ID is located in. |
|
80 TMsvId destinationServiceId = iEntry.OwningService(); |
|
81 |
|
82 if (storeFound) |
|
83 { |
|
84 // Get the name that the destination file should be copied to |
|
85 TFileName destinationStoreFilename = mailDirectory; |
|
86 MsvUtils::ConstructEntryName(destinationServiceId, iEntry.Entry().Id(), destinationStoreFilename, MsvUtils::EStore); |
|
87 CFileMan* fileMan = CFileMan::NewL(iEntry.FileSession()); |
|
88 CleanupStack::PushL(fileMan); |
|
89 User::LeaveIfError(fileMan->Copy(sourceStoreFilename, destinationStoreFilename, CFileMan::ERecurse|CFileMan::EOverWrite)); |
|
90 CleanupStack::PopAndDestroy(); // fileMan |
|
91 |
|
92 // This change entry isn't actually changing anything. |
|
93 // However the store contains a hidden stream created by the Message Server. |
|
94 // This is used to rebuild the index if it's corrupted |
|
95 // Calling ChangeEntry will make sure the stream is updated correctly |
|
96 iEntry.ChangeEntry(iEntry.Entry()); |
|
97 } |
|
98 |
|
99 // Move all child entries from under the remote entry to the new entry |
|
100 User::LeaveIfError(iEntry.SetEntry(aSourceMessage)); |
|
101 CMsvEntrySelection* childEntries = new (ELeave) CMsvEntrySelection; |
|
102 CleanupStack::PushL(childEntries); |
|
103 User::LeaveIfError(iEntry.GetChildren(*childEntries)); |
|
104 if (childEntries->Count() > 0) |
|
105 { |
|
106 if (iTransferMethod == EImPop3CopyTransfer) |
|
107 // If we are in disconnected mode then we really want to copy the |
|
108 // entries, however if we are not then we want to move them. |
|
109 // This is because the only reason there are entries under the |
|
110 // service is because the remote server does not support the TOP |
|
111 // command. |
|
112 { |
|
113 iStatus = KRequestPending; |
|
114 iEntry.CopyEntriesL(*childEntries, newEntry, iStatus); |
|
115 SetActive(); |
|
116 } |
|
117 else |
|
118 { |
|
119 iStatus = KRequestPending; |
|
120 iEntry.MoveEntriesL(*childEntries, newEntry, iStatus); |
|
121 SetActive(); |
|
122 } |
|
123 } |
|
124 else |
|
125 { |
|
126 iStatus = KRequestPending; |
|
127 SetActive(); |
|
128 TRequestStatus* status = &iStatus; |
|
129 User::RequestComplete(status, KErrNone); |
|
130 } |
|
131 |
|
132 CleanupStack::PopAndDestroy(); // childEntries |
|
133 |
|
134 CleanupStack::PopAndDestroy(2); // description, details |
|
135 |
|
136 } |
|
137 |
|
138 void CImPop3TransferMessage::DoCancel() |
|
139 { |
|
140 iEntry.Cancel(); |
|
141 |
|
142 if (iEntry.SetEntry(iDestFolder) == KErrNone) |
|
143 { |
|
144 iEntry.DeleteEntry(iCopiedMessageId); |
|
145 } |
|
146 |
|
147 User::RequestComplete(iReportStatus, KErrCancel); |
|
148 } |
|
149 |
|
150 void CImPop3TransferMessage::RunL() |
|
151 { |
|
152 if (iStatus == KErrNone) |
|
153 { |
|
154 if (iTransferMethod == EImPop3MoveTransfer) |
|
155 // If the data under the message entry has been moved then mark it as incomplete |
|
156 { |
|
157 TInt err; |
|
158 err = iEntry.SetEntry(iSourceMessage); |
|
159 if (err == KErrNone) |
|
160 { |
|
161 TMsvEntry entry = iEntry.Entry(); |
|
162 entry.SetComplete(EFalse); |
|
163 err = iEntry.ChangeEntry(entry); |
|
164 if (err != KErrNone) |
|
165 iStatus = err; |
|
166 } |
|
167 } |
|
168 } |
|
169 else |
|
170 // If the message hasn't been copied or moved correctly then |
|
171 // delete the new message. |
|
172 // The old source message is still in a valid state. |
|
173 { |
|
174 TInt err; |
|
175 err = iEntry.SetEntry(iDestFolder); |
|
176 if (err == KErrNone) |
|
177 { |
|
178 err = iEntry.DeleteEntry(iCopiedMessageId); |
|
179 if (err != KErrNone) |
|
180 iStatus = err; |
|
181 } |
|
182 } |
|
183 |
|
184 User::RequestComplete(iReportStatus, iStatus.Int()); |
|
185 } |
|
186 |
|
187 CImPop3TransferMessage::~CImPop3TransferMessage() |
|
188 { |
|
189 } |
|
190 |
|
191 CImPop3TransferMessage::CImPop3TransferMessage(CMsvServerEntry& aEntry) : CActive(EPriorityStandard), iEntry(aEntry) |
|
192 { |
|
193 } |