Update change log and spec for wrt-plugins-tizen_0.2.73
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Messaging / EmailConverter.cpp
1 /*
2 * Copyright (c) 2011 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 /**
18  * @author          Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  */
20 #include <dpl/log/log.h>
21
22 #include <Commons/Exception.h>
23
24 #include "EmailConverter.h"
25
26 #define LOG_ENTER LogDebug("---> ENTER");
27 #define LOG_EXIT LogDebug("---> EXIT");
28
29 namespace TizenApis {
30 namespace Platform {
31 namespace Messaging {
32 namespace EmailConverter {
33 email_mail_priority_t toMailPriority(Api::Messaging::MessagePriority::Priority priority)
34 {
35     LOG_ENTER
36     switch (priority) {
37     case Api::Messaging::MessagePriority::LOW: return EMAIL_MAIL_PRIORITY_LOW;
38     case Api::Messaging::MessagePriority::NORMAL: return EMAIL_MAIL_PRIORITY_NORMAL;
39     case Api::Messaging::MessagePriority::HIGH: return EMAIL_MAIL_PRIORITY_HIGH;
40     default:
41         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
42                  "Unsupported priority: " << priority);
43     }
44 }
45
46 Api::Messaging::MessagePriority::Priority toMessagePriority(email_mail_priority_t priority)
47 {
48     LOG_ENTER
49     switch (priority) {
50     case EMAIL_MAIL_PRIORITY_LOW: return Api::Messaging::MessagePriority::LOW;
51     case EMAIL_MAIL_PRIORITY_NORMAL: return Api::Messaging::MessagePriority::NORMAL;
52     case EMAIL_MAIL_PRIORITY_HIGH: return Api::Messaging::MessagePriority::HIGH;
53     default:{
54         // TODO Think it through, log is enough or exception should be thrown.
55         //            ThrowMsg(WrtDeviceApis::Commons::PlatformException,
56         //                     "Unsupported platform priority: " << priority);
57         LogWarning("Unsupported platform priority");
58     }
59     }
60
61     // TODO Fix this. What to return if non-existing priority returned by platform.
62     return Api::Messaging::MessagePriority::NORMAL;
63 }
64
65 Api::Messaging::MessagePriority::Priority toMessagePriority(unsigned char priority)
66 {
67     return toMessagePriority(static_cast<email_mail_priority_t>(priority));
68 }
69
70 email_mailbox_type_e toMailboxType(Api::Messaging::FolderType folder)
71 {
72     LOG_ENTER
73     switch (folder) {
74     case Api::Messaging::INBOX: return EMAIL_MAILBOX_TYPE_INBOX;
75     case Api::Messaging::OUTBOX: return EMAIL_MAILBOX_TYPE_OUTBOX;
76     case Api::Messaging::SENTBOX: return EMAIL_MAILBOX_TYPE_SENTBOX;
77     case Api::Messaging::DRAFTBOX: return EMAIL_MAILBOX_TYPE_DRAFT;
78     case Api::Messaging::SPAMBOX: return EMAIL_MAILBOX_TYPE_SPAMBOX;
79     case Api::Messaging::ALL_FOLDERS: return EMAIL_MAILBOX_TYPE_ALL_EMAILS;
80     case Api::Messaging::USERDEFINED_FOLDER: return EMAIL_MAILBOX_TYPE_USER_DEFINED;
81     default:
82         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Conversion failed.");
83     }
84 }
85
86 const char* toMailboxName(Api::Messaging::FolderType folder)
87 {
88     LOG_ENTER
89     switch (folder) {
90     case Api::Messaging::INBOX: return EMAIL_INBOX_NAME;
91     case Api::Messaging::OUTBOX: return EMAIL_OUTBOX_NAME;
92     case Api::Messaging::SENTBOX: return EMAIL_SENTBOX_NAME;
93     case Api::Messaging::DRAFTBOX: return EMAIL_DRAFTBOX_NAME;
94     case Api::Messaging::SPAMBOX: return EMAIL_SPAMBOX_NAME;
95     default:
96         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
97                  "Mailbox not found. Folder: " << folder);
98     }
99 }
100
101 Api::Messaging::FolderType toFolderType(email_mailbox_type_e mailboxType)
102 {
103     LOG_ENTER
104     switch (mailboxType) {
105     case EMAIL_MAILBOX_TYPE_INBOX: return Api::Messaging::INBOX;
106     case EMAIL_MAILBOX_TYPE_OUTBOX: return Api::Messaging::OUTBOX;
107     case EMAIL_MAILBOX_TYPE_SENTBOX: return Api::Messaging::SENTBOX;
108     case EMAIL_MAILBOX_TYPE_DRAFT: return Api::Messaging::DRAFTBOX;
109     case EMAIL_MAILBOX_TYPE_SPAMBOX: return Api::Messaging::SPAMBOX;
110     case EMAIL_MAILBOX_TYPE_ALL_EMAILS: return Api::Messaging::ALL_FOLDERS;
111     case EMAIL_MAILBOX_TYPE_USER_DEFINED: return Api::Messaging::USERDEFINED_FOLDER;
112     default:
113         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Conversion failed.");
114     }
115 }
116
117 Api::Messaging::FolderType toFolderType(int mailboxType)
118 {
119     LOG_ENTER
120     switch (mailboxType) {
121     case EMAIL_MAILBOX_TYPE_INBOX: return Api::Messaging::INBOX;
122     case EMAIL_MAILBOX_TYPE_OUTBOX: return Api::Messaging::OUTBOX;
123     case EMAIL_MAILBOX_TYPE_SENTBOX: return Api::Messaging::SENTBOX;
124     case EMAIL_MAILBOX_TYPE_DRAFT: return Api::Messaging::DRAFTBOX;
125     case EMAIL_MAILBOX_TYPE_SPAMBOX: return Api::Messaging::SPAMBOX;
126     case EMAIL_MAILBOX_TYPE_ALL_EMAILS: return Api::Messaging::ALL_FOLDERS;
127     case EMAIL_MAILBOX_TYPE_USER_DEFINED: return Api::Messaging::USERDEFINED_FOLDER;
128     default:
129         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Conversion failed.");
130     }
131 }
132
133
134 }
135 }
136 }
137 }