Deprecating Tizen.Messaging.Email APIs (#5596)
[platform/core/csapi/tizenfx.git] / src / Tizen.Messaging / Tizen.Messaging.Email / EmailMessage.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Collections.ObjectModel;
20
21 namespace Tizen.Messaging.Email
22 {
23     /// <summary>
24     /// This class contains the Messaging API to support sending email messages.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     [Obsolete("Deprecated since API11. Might be removed in API13")]
28     public class EmailMessage : IDisposable
29     {
30         internal IntPtr _emailHandle = IntPtr.Zero;
31         private bool _disposed = false;
32         private String _subject;
33         private String _body;
34         private IList<EmailAttachment> _attachments = new List<EmailAttachment>();
35         private ICollection<EmailRecipient> _to = new Collection<EmailRecipient>();
36         private ICollection<EmailRecipient> _cc = new Collection<EmailRecipient>();
37         private ICollection<EmailRecipient> _bcc = new Collection<EmailRecipient>();
38
39         /// <summary>
40         /// The constructor.
41         /// </summary>
42         /// <since_tizen> 3 </since_tizen>
43         [Obsolete("Deprecated since API11. Might be removed in API13")]
44         public EmailMessage()
45         {
46             int ret = Interop.Email.CreateEmail(out _emailHandle);
47             if (ret != (int)EmailError.None)
48             {
49                 Log.Error(EmailErrorFactory.LogTag, "Failed to create message handle, Error code: " + (EmailError)ret);
50                 throw EmailErrorFactory.GetException(ret);
51             }
52         }
53
54         /// <summary>
55         /// The subject of the email message.
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         [Obsolete("Deprecated since API11. Might be removed in API13")]
59         public string Subject
60         {
61             set
62             {
63                 _subject = value;
64                 int ret = Interop.Email.SetSubject(_emailHandle, _subject);
65                 if (ret != (int)EmailError.None)
66                 {
67                     Log.Error(EmailErrorFactory.LogTag, "Failed to set subject, Error code: " + (EmailError)ret);
68                     throw EmailErrorFactory.GetException(ret);
69                 }
70             }
71             get
72             {
73                 return _subject;
74             }
75
76         }
77
78         /// <summary>
79         /// The body of the email message.
80         /// </summary>
81         /// <since_tizen> 3 </since_tizen>
82         [Obsolete("Deprecated since API11. Might be removed in API13")]
83         public string Body
84         {
85             set
86             {
87                 _body = value;
88                 int ret = Interop.Email.SetBody(_emailHandle, _body);
89                 if (ret != (int)EmailError.None)
90                 {
91                     Log.Error(EmailErrorFactory.LogTag, "Failed to set body, Error code: " + (EmailError)ret);
92                     throw EmailErrorFactory.GetException(ret);
93                 }
94             }
95             get
96             {
97                 return _body;
98             }
99         }
100
101         /// <summary>
102         /// The list of file attachments.
103         /// </summary>
104         /// <since_tizen> 3 </since_tizen>
105 [Obsolete("Deprecated since API11. Might be removed in API13")]
106         public IList<EmailAttachment> Attachments
107         {
108             get
109             {
110                 return _attachments;
111             }
112         }
113
114         /// <summary>
115         /// The collection of normal email recipients.
116         /// </summary>
117         /// <remarks>
118         /// The email address should be in the standard format (as described in the Internet standards RFC 5321 and RFC 5322).
119         /// </remarks>
120         /// <since_tizen> 3 </since_tizen>
121         [Obsolete("Deprecated since API11. Might be removed in API13")]
122         public ICollection<EmailRecipient> To
123         {
124             get
125             {
126                 return _to;
127             }
128         }
129
130         /// <summary>
131         /// The collection of CC (carbon copy) email recipients.
132         /// </summary>
133         /// <remarks>
134         /// The email address should be in the standard format (as described in the Internet standards RFC 5321 and RFC 5322).
135         /// </remarks>
136         /// <since_tizen> 3 </since_tizen>
137         [Obsolete("Deprecated since API11. Might be removed in API13")]
138         public ICollection<EmailRecipient> Cc
139         {
140             get
141             {
142                 return _cc;
143             }
144         }
145
146         /// <summary>
147         /// The collection of BCC (blind carbon copy) email recipients.
148         /// </summary>
149         /// <remarks>
150         /// The email address should be in the standard format (as described in the Internet standards RFC 5321 and RFC 5322).
151         /// </remarks>
152         /// <since_tizen> 3 </since_tizen>
153         [Obsolete("Deprecated since API11. Might be removed in API13")]
154         public ICollection<EmailRecipient> Bcc
155         {
156             get
157             {
158                 return _bcc;
159             }
160         }
161
162
163         internal void Save()
164         {
165             int ret;
166             FillHandle();
167
168             ret = Interop.Email.SaveEmail(_emailHandle);
169             if (ret != (int)EmailError.None)
170             {
171                 Log.Error(EmailErrorFactory.LogTag, "Failed to save email, Error code: " + (EmailError)ret);
172                 throw EmailErrorFactory.GetException(ret);
173             }
174         }
175
176         /// <summary>
177         /// Releases all resources used by the EmailMessage.
178         /// </summary>
179         /// <since_tizen> 3 </since_tizen>
180         [Obsolete("Deprecated since API11. Might be removed in API13")]
181         public void Dispose()
182         {
183             Dispose(true);
184             GC.SuppressFinalize(this);
185         }
186
187         /// <summary>
188         /// Releases all resources used by the EmailMessage.
189         /// </summary>
190         /// <param name="disposing">Disposing by User</param>
191         /// <since_tizen> 3 </since_tizen>
192         [Obsolete("Deprecated since API11. Might be removed in API13")]
193         protected virtual void Dispose(bool disposing)
194         {
195             if (_disposed)
196                 return;
197
198             if (disposing)
199             {
200
201             }
202
203             if (_emailHandle != IntPtr.Zero)
204             {
205                 Interop.Email.DestroyEmail(_emailHandle);
206                 _emailHandle = IntPtr.Zero;
207             }
208             _disposed = true;
209         }
210
211         internal void FillHandle()
212         {
213             int ret = (int)EmailError.None;
214             foreach (EmailAttachment it in Attachments)
215             {
216                 Console.WriteLine(it.FilePath);
217                 ret = Interop.Email.AddAttachment(_emailHandle, it.FilePath);
218                 if (ret != (int)EmailError.None)
219                 {
220                     Log.Error(EmailErrorFactory.LogTag, "Failed to add attachment, Error code: " + (EmailError)ret);
221                     throw EmailErrorFactory.GetException(ret);
222                 }
223             }
224
225             foreach (EmailRecipient it in To)
226             {
227                 ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.To, it.Address);
228                 if (ret != (int)EmailError.None)
229                 {
230                     Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret);
231                     throw EmailErrorFactory.GetException(ret);
232                 }
233             }
234
235             foreach (EmailRecipient it in Cc)
236             {
237                 ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.Cc, it.Address);
238                 if (ret != (int)EmailError.None)
239                 {
240                     Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret);
241                     throw EmailErrorFactory.GetException(ret);
242                 }
243             }
244
245             foreach (EmailRecipient it in Bcc)
246             {
247                 ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.Bcc, it.Address);
248                 if (ret != (int)EmailError.None)
249                 {
250                     Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret);
251                     throw EmailErrorFactory.GetException(ret);
252                 }
253             }
254         }
255     }
256 }