blob: 3a828c3b03f9e7a46fb0c2b74ac35823f1844ca5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMsgAttachment.h"
#include "nsIFile.h"
#include "nsNetUtil.h"
NS_IMPL_ISUPPORTS(nsMsgAttachment, nsIMsgAttachment)
nsMsgAttachment::nsMsgAttachment()
{
mTemporary = false;
mSendViaCloud = false;
mSize = -1;
}
nsMsgAttachment::~nsMsgAttachment()
{
if (mTemporary && !mSendViaCloud)
(void)DeleteAttachment();
}
/* attribute wstring name; */
NS_IMETHODIMP nsMsgAttachment::GetName(nsAString & aName)
{
aName = mName;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::SetName(const nsAString & aName)
{
mName = aName;
return NS_OK;
}
/* attribute string url; */
NS_IMETHODIMP nsMsgAttachment::GetUrl(nsACString & aUrl)
{
aUrl = mUrl;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::SetUrl(const nsACString & aUrl)
{
mUrl = aUrl;
return NS_OK;
}
/* attribute string urlCharset; */
NS_IMETHODIMP nsMsgAttachment::GetUrlCharset(nsACString & aUrlCharset)
{
aUrlCharset = mUrlCharset;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::SetUrlCharset(const nsACString & aUrlCharset)
{
mUrlCharset = aUrlCharset;
return NS_OK;
}
/* attribute boolean temporary; */
NS_IMETHODIMP nsMsgAttachment::GetTemporary(bool *aTemporary)
{
NS_ENSURE_ARG_POINTER(aTemporary);
*aTemporary = mTemporary;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::SetTemporary(bool aTemporary)
{
mTemporary = aTemporary;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::GetSendViaCloud(bool *aSendViaCloud)
{
NS_ENSURE_ARG_POINTER(aSendViaCloud);
*aSendViaCloud = mSendViaCloud;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::SetSendViaCloud(bool aSendViaCloud)
{
mSendViaCloud = aSendViaCloud;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::SetHtmlAnnotation(const nsAString &aAnnotation)
{
mHtmlAnnotation = aAnnotation;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::GetHtmlAnnotation(nsAString &aAnnotation)
{
aAnnotation = mHtmlAnnotation;
return NS_OK;
}
NS_IMETHODIMP
nsMsgAttachment::SetCloudProviderKey(const nsACString &aCloudProviderKey)
{
mCloudProviderKey = aCloudProviderKey;
return NS_OK;
}
NS_IMETHODIMP
nsMsgAttachment::GetCloudProviderKey(nsACString &aCloudProviderKey)
{
aCloudProviderKey = mCloudProviderKey;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::GetContentLocation(nsACString &aContentLocation)
{
aContentLocation = mContentLocation;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::SetContentLocation(const nsACString &aContentLocation)
{
mContentLocation = aContentLocation;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::GetContentType(char * *aContentType)
{
NS_ENSURE_ARG_POINTER(aContentType);
*aContentType = ToNewCString(mContentType);
return (*aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
}
NS_IMETHODIMP nsMsgAttachment::SetContentType(const char * aContentType)
{
mContentType = aContentType;
/* a full content type could also contains parameters but we need to
keep only the content type alone. Therefore we need to cleanup it.
*/
int32_t offset = mContentType.FindChar(';');
if (offset >= 0)
mContentType.SetLength(offset);
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::GetContentTypeParam(char * *aContentTypeParam)
{
NS_ENSURE_ARG_POINTER(aContentTypeParam);
*aContentTypeParam = ToNewCString(mContentTypeParam);
return (*aContentTypeParam ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
}
NS_IMETHODIMP nsMsgAttachment::SetContentTypeParam(const char * aContentTypeParam)
{
if (aContentTypeParam)
while (*aContentTypeParam == ';' || *aContentTypeParam == ' ')
aContentTypeParam ++;
mContentTypeParam = aContentTypeParam;
return NS_OK;
}
/* attribute string charset; */
NS_IMETHODIMP nsMsgAttachment::GetCharset(char * *aCharset)
{
NS_ENSURE_ARG_POINTER(aCharset);
*aCharset = ToNewCString(mCharset);
return (*aCharset ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
}
NS_IMETHODIMP nsMsgAttachment::SetCharset(const char * aCharset)
{
mCharset = aCharset;
return NS_OK;
}
/* attribute string macType; */
NS_IMETHODIMP nsMsgAttachment::GetMacType(char * *aMacType)
{
NS_ENSURE_ARG_POINTER(aMacType);
*aMacType = ToNewCString(mMacType);
return (*aMacType ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
}
NS_IMETHODIMP nsMsgAttachment::SetMacType(const char * aMacType)
{
mMacType = aMacType;
return NS_OK;
}
/* attribute string macCreator; */
NS_IMETHODIMP nsMsgAttachment::GetMacCreator(char * *aMacCreator)
{
NS_ENSURE_ARG_POINTER(aMacCreator);
*aMacCreator = ToNewCString(mMacCreator);
return (*aMacCreator ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
}
NS_IMETHODIMP nsMsgAttachment::SetMacCreator(const char * aMacCreator)
{
mMacCreator = aMacCreator;
return NS_OK;
}
/* attribute int64_t size; */
NS_IMETHODIMP nsMsgAttachment::GetSize(int64_t *aSize)
{
NS_ENSURE_ARG_POINTER(aSize);
*aSize = mSize;
return NS_OK;
}
NS_IMETHODIMP nsMsgAttachment::SetSize(int64_t aSize)
{
mSize = aSize;
return NS_OK;
}
/* boolean equalsUrl (in nsIMsgAttachment attachment); */
NS_IMETHODIMP nsMsgAttachment::EqualsUrl(nsIMsgAttachment *attachment, bool *_retval)
{
NS_ENSURE_ARG_POINTER(attachment);
NS_ENSURE_ARG_POINTER(_retval);
nsAutoCString url;
attachment->GetUrl(url);
*_retval = mUrl.Equals(url);
return NS_OK;
}
nsresult nsMsgAttachment::DeleteAttachment()
{
nsresult rv;
bool isAFile = false;
nsCOMPtr<nsIFile> urlFile;
rv = NS_GetFileFromURLSpec(mUrl, getter_AddRefs(urlFile));
NS_ASSERTION(NS_SUCCEEDED(rv), "Can't nsIFile from URL string");
if (NS_SUCCEEDED(rv))
{
bool bExists = false;
rv = urlFile->Exists(&bExists);
NS_ASSERTION(NS_SUCCEEDED(rv), "Exists() call failed!");
if (NS_SUCCEEDED(rv) && bExists)
{
rv = urlFile->IsFile(&isAFile);
NS_ASSERTION(NS_SUCCEEDED(rv), "IsFile() call failed!");
}
}
// remove it if it's a valid file
if (isAFile)
rv = urlFile->Remove(false);
return rv;
}
|