73c1b69e998f2f7d2df3bd041ecb4689dd01df72
[platform/core/messaging/email-service.git] / email-core / include / email-core-mail.h
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */
21
22
23 /******************************************************************************
24  * File :  email-core-mail.h
25  * Desc :  Mail Operation Header
26  *
27  * Auth : 
28  *
29  * History : 
30  *    2006.08.16  :  created
31  *****************************************************************************/
32 #ifndef __EMAIL_CORE_MESSAGE_H__
33 #define __EMAIL_CORE_MESSAGE_H__
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38
39 #include "email-storage.h"
40
41 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
42
43 #define MAX_SUBSET_STRING_SIZE 260      
44 #define MAX_IMAP_COMMAND_LENGTH 1000
45 #define MAX_TAG_SIZE 16
46
47
48 typedef struct _emf_uid_range_set
49 {
50         char *uid_range;
51         unsigned long lowest_uid;
52         unsigned long highest_uid;
53         
54         struct _emf_uid_range_set *next;
55         
56 } email_uid_range_set;
57
58 #endif
59
60 struct attachment_info
61 {
62         int   type;                 /*  1 : inline 2 : attachment */
63         char *name;                 /*  attachment filename */
64         int   size;                 /*  attachment size */
65         char *save;                 /*  content saving filename */
66         int   drm;                  /*  0 : none 1 : object 2 : rights 3 : dcf */
67         int   drm2;                 /*  0 : none 1 : FL 2 : CD 3 : SSD 4 : SD */
68         char *attachment_mime_type; /*  attachment mime type */
69         char *content_id;           /*  mime content id */
70         int   save_status;
71 #ifdef __ATTACHMENT_OPTI__
72         int   encoding;         /*  encoding  */
73         char *section;          /*  section number */
74 #endif
75         struct attachment_info *next;
76 };
77
78 /*
79         MIME Structure Example
80
81         (part 0)        multipart/mixed
82         (part 1)                multipart/alternative
83         (part 1.1)                      text/plain              <- text message
84         (part 1.2)                      text/html               <- html message
85         (part 2)                text/plain                      <- text attachment
86
87
88         (part 0)        multipart/related
89         (part 1)                multipart/alternative
90         (part 1.1)                      text/plain                      <- text message
91         (part 1.2)                      text/html                       <- html message
92         (part 2)                image/png                               <- inline image
93         (part 2)                image/png                               <- inline image
94
95
96         (part 0)        multipart/mixed
97         (part 1.1)              multipart/related
98         (part 2.1)                      multipart/alternative
99         (part 3.1)                              text/plain(body)  <- text message
100         (part 3.2)                              text/html(body) <- html message
101         (part 2.2)                      image/png(related)      <- inline image
102         (part 1.2)              image/png(attachment)   <- image attachment
103 */
104
105 /*  Text and Attachment Holde */
106 /* struct _m_content_info  */
107 /*      int grab_type;  */              /*  1 :  text and attachment list */
108                                                 /*  2 :  attachmen */
109 /*      int file_no; */                 /*  attachment sequence to be downloaded (min : 1 */
110 /*      struct text_data  */
111 /*              char *plain;    */      /*  body plain tex */
112 /*              char *plain_charset */ /*  charset of plai */
113 /*              char *html; */ /*  body html tex */
114 /*      } text */
115
116 /*      struct attachment_info  */
117 /*              int   type;     */              /*  1 : inline 2 : attachmen */
118 /*              char *name;     */              /*  attachment filenam */
119 /*              int   size;             */      /*  attachment siz */
120 /*              char *save;     */              /*  content saving filenam */
121 /*              struct attachment_info *next */
122 /*      } *file */
123 /* } */
124
125 /* --------------------- MIME Structure --------------------------------- */
126 /*  MIME Header Parameter (Content-Type, Content-Disposition, ... */
127 struct _parameter {
128         char                            *name;                  /*  parameter name */
129         char                            *value;                 /*  parameter value */
130         struct _parameter       *next;                  /*  next paramete */
131 };
132
133 /*  Content-Disposition */
134 struct _disposition {
135         char                            *type;                  /*  "inline" "attachment */
136         struct _parameter       *parameter;             /*  "filename", .. */
137 };
138
139 /*  RFC822 Header */
140 struct _rfc822header {
141         char                            *return_path;   /*  error return path */
142         char                            *received;
143         char                            *date;
144         char                            *from;
145         char                            *subject;
146         char                            *sender;
147         char                            *to;
148         char                            *cc;
149         char                            *bcc;
150         char                            *reply_to;
151         char                            *priority;
152         char                            *ms_priority;
153         char                            *dsp_noti_to;
154         char                            *message_id;
155         char                            *content_type;
156         char                            *others;
157 };
158
159 /*  MIME Part Header */
160 struct _m_part_header {
161         char                            *type;                      /* text, image, audio, video, application, multipart, message */
162         char                            *subtype;                   /* plain, html, jpeg, .. */
163         char                            *encoding;                  /* encoding typ */
164         struct _parameter       *parameter;                 /* content-type parameter  :  "boundary" "charset" .. */
165         char                            *desc;                      /* description */
166         char                            *disp_type;                 /* disposition type  :  "inline" "attachment", */
167         struct _parameter       *disp_parameter;    /* disposition parameter  :  "filename", .. */
168         char                            *content_id;        /* content id  :  it is inline  */
169         char                            *content_location;      /* content location  :  "inline" location  */
170         char                            *priority;              /* Priority : 1, 3, 5 */
171         char                            *ms_priority;           /* MS-Priority : HIGH, NORMAL, LOW */
172 };
173
174 /*  MIME Message Header */
175 struct _m_mesg_header {
176         char                               *version;          /* MIME Version */
177         struct _m_part_header  *part_header;      /* MIME Part Header */
178         /* char                   *message_context; */  /* Message-Context : Voice-message, Video-message, Fax-message... */
179         /* int                     content_duration; */ /* Content-Duration */
180         /* int                     x_content_pages;  */ /* X-Content-Pages */
181         /* char                   *sensitivity; */     /* Sensitivity */
182 };
183
184 /*  MIME Multipart Body linked list */
185 typedef struct _m_body _m_body_t;
186 struct _m_part{
187         _m_body_t              *body;             /* part body */
188         struct _m_part         *next;             /* the next found part */
189 };
190
191 /*  MIME Multipart Body */
192 struct _m_body {
193         struct _m_part_header  *part_header;      /* MIME Part Header */
194         struct _m_part          nested;           /* nested structure if contain multipart */
195         char                   *text;             /* text if not contain multipart */
196         int                     size;             /* text size if not contain multipart */
197         char                   *holdingfile;
198 };
199
200 /*  MIME Message */
201 struct _m_mesg {
202         struct _rfc822header    *rfc822header;    /* RFC822 Header */
203         struct _m_mesg_header   *header;          /* MIME Message Header */
204         struct _m_part           nested;          /* nested structure if contain multipart */
205         char                    *text;            /* text if not contain multipart */
206         int                      size;            /* text size if not contain multipart */
207 };
208
209 struct _m_content_info 
210 {
211         int grab_type;  /*  1 :  download text and get attachment names (no saving attachment) -
212                                                         #define GRAB_TYPE_TEXT retrieve text and attachment names */
213                                         /*  2 :  download attachment - #define GRAB_TYPE_ATTACHMENT retrieve only attachment */
214         int file_no;    /*  attachment no to be download (min : 1) */
215         int report;             /*  0 : Non 1 : DSN mail 2 : MDN mail 3 : mail to require MDN */
216         int total_mail_size;
217         int total_body_size;
218         int total_attachment_size;
219         int attachment_only;
220         int content_type; /* 1 : signed */
221         char *sections;
222
223         struct text_data 
224         {
225                 int   plain_save_status; 
226                 char *plain;             /*  body plain text */
227                 char *plain_charset;     /*  charset of body text */
228                 int   html_save_status;
229                 char *html;              /*  body html text */
230                 char *html_charset;      /*  charset of html text */
231                 char *mime_entity;
232         } text;
233
234         struct attachment_info *file;
235         struct attachment_info *inline_file; /* only used for IMAP partial body download */
236 };
237
238 typedef enum {
239         IMAP4_CMD_EXPUNGE,
240         IMAP4_CMD_NOOP
241 } imap4_cmd_t;
242
243 typedef enum {
244         POP3_CMD_NOOP
245 } pop3_cmd_t;
246
247 /**
248  * Download a email nth-attachment from server.
249  *
250  * @param[in] mailbox           Specifies the mailbox to contain account ID.
251  * @param[in] mail_id                   Specifies the mail ID.
252  * @param[in] nth                               Specifies the buffer that a attachment number been saved. the minimum number is "1".
253  * @param[in] callback          Specifies the callback function for retrieving download status.
254  * @param[in] handle                    Specifies the handle for stopping downloading.
255  * @param[out] err_code Specifies the error code returned.
256  * @remarks This function is used for only IMAP mail.
257  * @return This function returns true on success or false on failure.
258  */
259 INTERNAL_FUNC int emcore_add_attachment(char *multi_user_name, int mail_id, email_attachment_data_t *attachment, int *err_code);        /* TODO : Remove duplicated function */
260 INTERNAL_FUNC int emcore_add_attachment_data(char *multi_user_name, int input_mail_id, email_attachment_data_t *input_attachment_data); /* TODO : Remove duplicated function */
261 INTERNAL_FUNC int emcore_delete_mail_attachment(char *multi_user_name, int attachment_id, int *err_code);
262 INTERNAL_FUNC int emcore_get_attachment_info(char *multi_user_name, int attachment_id, email_attachment_data_t **attachment, int *err_code);
263 INTERNAL_FUNC int emcore_get_attachment_data_list(char *multi_user_name, int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count);
264 INTERNAL_FUNC int emcore_free_attachment_data(email_attachment_data_t **attachment_data_list, int attachment_data_count, int *err_code);
265
266 INTERNAL_FUNC int emcore_gmime_download_attachment(char *multi_user_name, int mail_id, int nth,
267                 int cancellable, int event_handle, int auto_download, int *err_code);
268
269 INTERNAL_FUNC int emcore_gmime_download_body_sections(char *multi_user_name, void *mail_stream,
270                 int account_id, int mail_id, int with_attach, int limited_size,
271                 int event_handle, int cancellable, int auto_download, int *err_code);
272
273 INTERNAL_FUNC int emcore_move_mail(char *multi_user_name, int mail_ids[], int num, int dst_mailbox_id, int noti_param_1, int noti_param_2, int *err_code);
274
275 #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
276 INTERNAL_FUNC int emcore_insert_pbd_activity(email_event_partial_body_thd *local_activity, int *activity_id, int *err_code) ;
277 INTERNAL_FUNC int emcore_delete_pbd_activity(char *multi_user_name, int account_id, int mail_id, int activity_id, int *err_code);
278 #endif 
279
280 INTERNAL_FUNC int emcore_get_mail_contact_info(char *multi_user_name, email_mail_contact_info_t *contact_info, char *full_address, int *err_code);
281 INTERNAL_FUNC int emcore_get_mail_contact_info_with_update(char *multi_user_name, email_mail_contact_info_t *contact_info, char *full_address, int mail_id, int *err_code);
282 INTERNAL_FUNC int emcore_free_contact_info(email_mail_contact_info_t *contact_info, int *err_code);
283 INTERNAL_FUNC int emcore_sync_contact_info(char *multi_user_name, int mail_id, int *err_code);
284 INTERNAL_FUNC GList *emcore_get_recipients_list(char *multi_user_name, GList *old_recipients_list, char *full_address, int *err_code);
285 INTERNAL_FUNC int emcore_get_mail_address_info_list(char *multi_user_name, int mail_id, email_address_info_list_t **address_info_list, int *err_code);
286
287 INTERNAL_FUNC int emcore_set_sent_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data);
288 INTERNAL_FUNC int emcore_set_received_contacts_log(char *multi_user_name, emstorage_mail_tbl_t *input_mail_data);
289 INTERNAL_FUNC int emcore_delete_contacts_log(char *multi_user_name, int input_account_id);
290
291
292 INTERNAL_FUNC int emcore_get_mail_display_name(char *multi_user_name, char *email_address, char **contact_display_name);
293 INTERNAL_FUNC int emcore_get_mail_display_name_internal(char *multi_user_name, char *email_address, char **contact_display_name);
294 INTERNAL_FUNC int emcore_get_mail_data(char *multi_user_name, int input_mail_id, email_mail_data_t **output_mail_data);
295
296 INTERNAL_FUNC int emcore_update_mail(char *multi_user_name, email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int sync_server);
297
298 INTERNAL_FUNC int emcore_delete_mails_from_local_storage(char *multi_user_name, int account_id, int *mail_ids, int num, int noti_param_1, int noti_param_2, int *err_code);
299 INTERNAL_FUNC int emcore_get_mail_msgno_by_uid(email_account_t *account, email_internal_mailbox_t *mailbox, char *uid, int *msgno, int *err_code);
300 INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_local_storage(char *multi_user_name, int input_mailbox_id);
301 INTERNAL_FUNC int emcore_expunge_mails_deleted_flagged_from_remote_server(char *multi_user_name, int input_account_id, int input_mailbox_id);
302
303 /**
304  * Delete mails.
305  *
306  * @param[in] account_id      Specifies the account id.
307  * @param[in] mail_id         Specifies the array for mail id.
308  * @param[in] num             Specifies the number of id.
309  * @param[in] from_server     Specifies whether mails is deleted from server.
310  * @param[in] callback        Specifies the callback function for delivering status during deleting.
311  * @param[in] noti_param_1    Specifies the first parameter for notification.
312  * @param[in] noti_param_2    Specifies the second parameter for notification.
313  * @param[out] err_code       Specifies the error code returned.
314  * @remarks N/A
315  * @return This function returns true on success or false on failure.
316  */
317 INTERNAL_FUNC int emcore_delete_mail(char *multi_user_name, int account_id, int mail_id[], int num, int from_server, int noti_param_1, int noti_param_2, int *err_code);
318
319 /**
320  * Delete mails.
321  *
322  * @param[in] input_mailbox_id  Specifies the id of mailbox.
323  * @param[in] input_from_server Specifies whether mails is also deleted from server.
324  * @param[out] err_code         Specifies the error code returned.
325  * @remarks N/A
326  * @return This function returns true on success or false on failure.
327  */
328 INTERNAL_FUNC int   emcore_delete_all_mails_of_acount(char *multi_user_name, int input_account_id);
329 INTERNAL_FUNC int   emcore_delete_all_mails_of_mailbox(char *multi_user_name, int input_account_id, int input_mailbox_id, int input_from_server, int *err_code);
330
331 INTERNAL_FUNC void  emcore_free_mail_data_list(email_mail_data_t **mail_list, int count);
332 INTERNAL_FUNC void  emcore_free_mail_data(email_mail_data_t *mail);
333 INTERNAL_FUNC void  emcore_free_content_info(struct _m_content_info *cnt_info);
334 INTERNAL_FUNC void  emcore_free_attachment_info(struct attachment_info *attchment);
335
336 INTERNAL_FUNC int   emcore_move_mail_on_server(char *multi_user_name, int account_id, int src_mailbox_id,  int mail_ids[], int num, char *dest_mailbox, int *error_code);
337 INTERNAL_FUNC int   emcore_move_mail_on_server_by_server_mail_id(void *mail_stream, char *server_mail_id, char *dest_mailbox_name);
338 INTERNAL_FUNC int   emcore_move_mail_to_another_account(char *multi_user_name, int input_mail_id, int input_source_mailbox_id, int input_target_mailbox_id, int input_task_id);
339 INTERNAL_FUNC int   emcore_sync_flag_with_server(char *multi_user_name, int mail_id, int event_handle, int *err_code);
340 INTERNAL_FUNC int   emcore_sync_seen_flag_with_server(char *multi_user_name, int mail_ids[], int num, int event_handle, int *err_code);
341
342 INTERNAL_FUNC int   emcore_set_flags_field(char *multi_user_name, int account_id, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code);
343 INTERNAL_FUNC char* emcore_convert_mutf7_to_utf8(char *mailbox_name); 
344 INTERNAL_FUNC int   emcore_convert_string_to_structure(const char *encoded_string, void **struct_var, email_convert_struct_type_e type);
345 INTERNAL_FUNC int   emcore_save_mail_file(char *multi_user_name, int account_id, int mail_id, int attachment_id, char *src_file_path, char *file_name, char *full_path, char *virtual_path, int *err_code);
346
347 #ifdef __FEATURE_BULK_DELETE_MOVE_UPDATE_REQUEST_OPTI__
348 INTERNAL_FUNC int   emcore_sync_flags_field_with_server(char *multi_user_name, int mail_ids[], int num, email_flags_field_type field_type, int value, int *err_code);
349 INTERNAL_FUNC int   emcore_move_mail_on_server_ex(char *multi_user_name, int account_id, int src_mailbox_id,  int mail_ids[], int num, int dest_mailbox_id, int *error_code);
350 #endif
351
352 #ifdef __ATTACHMENT_OPTI__
353 INTERNAL_FUNC int emcore_download_attachment_bulk(/*email_mailbox_t *mailbox, */ int account_id, int mail_id, char *nth, int event_handle, int *err_code);
354 #endif
355 INTERNAL_FUNC int   emcore_mail_filter_by_rule(char *multi_user_name, email_rule_t *filter_info, int *err_code);
356 INTERNAL_FUNC int   emcore_add_rule(char *multi_user_name, email_rule_t *filter_info);
357 INTERNAL_FUNC int   emcore_update_rule(char *multi_user_name, int filter_id, email_rule_t *filter_info);
358 INTERNAL_FUNC int   emcore_delete_rule(char *multi_user_name, int filter_id);
359
360 /**
361  * Search the mails on server
362  *
363  * @param[in] account_id                Specifies the id of account
364  * @param[in] mailbox_id                Specifies the id of mailbox
365  * @param[in] input_search_filter       Specifies the filter list for searching field
366  * @param[in] input_search_filter_count Specifies the filter count
367  * @param[in] handle                    Specifies the handle for searching mails
368  * @remarks N/A
369  * @return EMAIL_ERROR_NONE on success or an error code (refer to EMAIL_ERROR_XXX) on failure 
370  */
371
372 INTERNAL_FUNC int   emcore_search_on_server(char *multi_user_name, int account_id, int mailbox_id, email_search_filter_t *input_search_filter, int input_search_filter_count, int handle_to_be_published);
373 #ifdef __cplusplus
374 }
375 #endif /* __cplusplus */
376
377
378 #define EMAIL_SIGNAL_FILE_DELETED       1
379 #define EMAIL_SIGNAL_DB_DELETED 2
380 INTERNAL_FUNC int *emcore_init_pipe_for_del_account ();
381 INTERNAL_FUNC void emcore_send_signal_for_del_account (int signal);
382
383 #endif
384 /* EOF */