wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Messaging / Email.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17  
18 #include <unistd.h>
19 #include <cstdio>
20 #include <cstddef>
21 #include <cstdlib>
22 #include <ctime>
23 #include <email-types.h>
24 #include <email-api.h>
25 #include <dpl/assert.h>
26 #include <dpl/scoped_fclose.h>
27 #include <dpl/scoped_ptr.h>
28 #include <Commons/Exception.h>
29 #include <Commons/StringUtils.h>
30 #include "MessageFactory.h"
31 #include "Messaging.h"
32 #include "Email.h"
33 #include "EmailService.h"
34 #include "EmailUtils.h"
35 #include "EmailConverter.h"
36 #include "MailSender.h"
37 #include "MailSync.h"
38 #include "MessagingService.h"
39 #include "MessagingServiceManager.h"
40 #include "Attachment.h"
41 #include <Logger.h>
42
43 #define LOG_ENTER LoggerD("---> ENTER");
44 #define LOG_EXIT LoggerD("---> EXIT");
45
46 using namespace std;
47 using namespace WrtDeviceApis::Commons;
48
49 namespace DeviceAPI {
50 namespace Messaging {
51
52 namespace {
53 const char* COMMAND_NAME = "/bin/cp";
54 const char* COMMAND_SWITCH_RECURSIVE = "-r";
55 //const char* COMMAND_SWITCH_FORCE = "-f";
56 }
57
58 Email::Email(const string& id) :
59         IMessage(EMAIL, id) {
60         LOG_ENTER
61
62         try {
63                 if (getIdRef().empty()) {
64                         //exception
65                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, " message id is invalid");
66                 }
67                                 
68                 reload();
69         } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
70                 LoggerE("Exception: " << ex.DumpToString());
71         }
72
73         LOG_EXIT
74 }
75
76 Email::Email(const std::string& id, int accountId) :
77         IMessage(EMAIL, id) 
78 {
79         LOG_ENTER
80
81         try {
82                 if (getIdRef().empty()) {
83                         //exception
84                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, " message id is invalid");
85                 }
86                 
87                 LoggerD("Account ID = " << accountId);
88                 m_accountId = accountId;
89                 reload();
90                 setMessageStatus(MESSAGE_STATUS_LOADED);
91                 
92         } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
93                 LoggerE("Exception: " << ex.DumpToString());
94         }
95
96
97         LOG_EXIT
98 }
99
100 Email::Email(EmailAccountInfo& account) : IMessage(EMAIL)
101 {
102     LOG_ENTER
103
104     try {
105          if (getIdRef().empty()) {
106                 create(account);
107          }
108         
109         reload();
110     }
111     catch (const WrtDeviceApis::Commons::PlatformException& ex) {
112         LoggerE("Exception: " << ex.DumpToString());
113     }
114
115     LOG_EXIT
116 }
117
118 Email::Email(const FolderType folder) : IMessage(EMAIL)
119 {
120     LOG_ENTER
121
122     try {
123          if (folder == TEMP_FOLDER) {
124                 create();
125          }
126            else {
127               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Folder Type is miss-matched");
128            }
129     }
130     catch (const WrtDeviceApis::Commons::PlatformException& ex) {
131         LoggerE("Exception: " << ex.DumpToString());
132     }
133
134     LOG_EXIT
135 }
136
137 Email::~Email()
138 {
139     LoggerD("ENTER");
140 }
141
142 int Email::send()
143 {
144     LOG_ENTER
145
146 //    update();
147
148     int handle = MailSender::getInstance().send(
149         MessageFactory::convertToEmail(SharedFromThis())
150         );
151
152     return handle;
153     LOG_EXIT
154 }
155
156 void Email::sendCancel(int handle)
157 {
158     LOG_ENTER
159
160     MailSender::getInstance().cancel(handle);
161
162     LOG_EXIT
163 }
164
165 int Email::downloadBody()
166 {
167         LOG_ENTER
168         return MailSync::getInstance().downloadBody( MessageFactory::convertToEmail(SharedFromThis()) );
169         LOG_EXIT
170 }
171
172 void Email::downloadBodyCancel( int handle)
173 {       
174         return MailSync::getInstance().cancelDownloadBody(handle);
175 }
176
177 int Email::downloadAttachment( const IAttachmentPtr& attachment)
178 {
179         LOG_ENTER
180         return MailSync::getInstance().downloadAttachment( MessageFactory::convertToEmail(SharedFromThis()), attachment );
181         LOG_EXIT
182 }
183
184 void Email::downloadAttachmentCancel( int handle)
185 {       
186         LOG_ENTER
187         return MailSync::getInstance().cancelDownloadAttachment(handle);
188         LOG_EXIT
189 }
190
191 void Email::update(bool draftsOnly)
192 {
193     LOG_ENTER
194
195     DPL::Mutex::ScopedLock mx(&m_updateMutex);
196
197     if (!m_mail) {
198         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
199     }
200
201     updateSubject();
202     updateBody();
203     updateRecipients();
204     updateAttachments();
205     updateReadStatus();
206
207     email_attachment_data_t* attachment=NULL;
208     int attachmentCount = 0;
209     int error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);
210     if (EMAIL_ERROR_NONE != error) {
211           LoggerW("Nothing to update or error. [" << error << "]");
212     }
213
214     error = email_update_mail( m_mail.Get(), attachment, attachmentCount, NULL, 0);
215     if (EMAIL_ERROR_NONE != error) {
216           LoggerW("Nothing to update or error. [" << error << "]");
217     }
218
219     if (attachment)
220     {
221             error = email_free_attachment_data(&attachment, attachmentCount);
222             if (EMAIL_ERROR_NONE != error) {
223                   LoggerW("Nothing to update or error. [" << error << "]");
224             }
225     }
226
227     LOG_EXIT
228 }
229
230 int Email::getAccountID()
231 {
232         LOG_ENTER
233
234         if ( m_mail )
235                 return m_mail->account_id;
236         else
237                 return -1;
238         
239         LOG_EXIT
240 }
241
242 int Email::getUID()
243 {
244         LOG_ENTER
245         
246         if (m_mail)
247                 return m_mail->mail_id;
248         else
249                 return -1;
250
251         LOG_EXIT
252 }
253
254 int Email::isBodyDownloaded()
255 {
256
257         if (m_mail)
258                 if ( m_mail->body_download_status == 1 )        // 1 is fully downloaded body.
259                         return true;
260                 else
261                         return false;
262         else
263                 return false;
264
265 }
266
267 bool Email::hasAttachment()
268 {       
269         std::size_t attachmentSize = getAttachmentsCount();
270         if ( attachmentSize > 0)
271                         return true;
272                 else
273                         return false;
274 }
275
276 void Email::readAllData()
277 {
278     reload();
279 }
280
281 void Email::moveToFolder(const FolderType newFolder)
282 {
283 /*
284
285     LOG_ENTER
286     moveToFolder(EmailConverter::toMailboxType(newFolder));
287     LOG_EXIT
288 */
289 }
290
291 void Email::moveToFolder(const string& newFolder)
292 {
293 /*
294         Assert(m_mail && "mail is NULL.");
295         
296         update();
297
298         int accountId = m_mail->account_id;
299         int mailId = getIntId();
300
301         emf_mailbox_t* mailbox = EmailService::alloc<emf_mailbox_t>();
302         mailbox->account_id = accountId;
303         mailbox->name = (NULL != newFolder.c_str() ? strdup(newFolder.c_str()) : NULL);
304
305         int error = email_move_mail_to_mailbox(&mailId, 1, mailbox);
306         if (EMF_ERROR_NONE != error) {
307         ThrowMsg(
308             WrtDeviceApis::Commons::PlatformException,
309             "Couldn't move mail to folder: " << newFolder << ". [" <<
310             error << "]");
311         }
312         
313         error = email_free_mailbox(&mailbox, 1);        //free
314         if (EMF_ERROR_NONE != error) {
315             LoggerE("Failed to destroy mailbox: " << error);
316         }
317 */
318 }
319
320 void Email::copyToFolder(const FolderType newFolder)
321 {
322     LOG_ENTER
323
324     copyToFolder(EmailConverter::toMailboxName(newFolder));
325
326     LOG_EXIT
327 }
328
329 void Email::copyToFolder(const string& newFolder)
330 {
331         LOG_ENTER
332 /*              
333         Assert(m_mail && "mail is NULL.");
334
335         update();
336
337         int accountId = m_mail->account_id;
338         ScopedMail mail(EmailService::cloneMail(m_mail.Get())); //clone
339         mail->mailbox_name = (NULL != newFolder.c_str() ? strdup(newFolder.c_str()) : NULL);
340         mail->account_id = accountId;
341         
342         //Attachment
343         email_attachment_data_t* attachment = NULL;
344         int attachmentCount = 0;
345         int error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);    //get Attachment list
346         if (EMAIL_ERROR_NONE != error) {
347                 ThrowMsg( WrtDeviceApis::Commons::PlatformException,
348                         "Couldn't get attachment list: " << newFolder << ". [" << error << "]");
349         }
350         
351         int mailId = EmailService::addMail( mail.Get(), attachment );
352         if (0 == mailId) {
353             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cloned mail didn't get new id.");
354         }
355 */      
356     LOG_EXIT
357 }
358
359 void Email::remove()
360 {
361     EmailService::deleteMail(m_accountId, getIntId());
362 }
363
364 #if 0
365 void Email::create()
366 {
367     LOG_ENTER
368
369     EmailAccountInfo account = IMessaging::getInstance().getCurrentEmailAccount();
370     m_accountId = account.getIntId();
371     ScopedMail mail(EmailService::createMail(account));
372     ScopedMailbox mailbox(
373         EmailService::getMailboxByType(account.getIntId(),
374                                        EMAIL_MAILBOX_TYPE_DRAFT)
375         );
376     setId(convertId(EmailService::addMailToMailbox(mail.Get(), mailbox.Get())));
377     setFolderType(DRAFTBOX);
378     setMessageStatus(MESSAGE_STATUS_DRAFT);
379
380     LOG_EXIT
381 }
382 #endif
383
384 void Email::create()
385 {
386     LOG_ENTER
387     setFolderType(TEMP_FOLDER);
388     setMessageStatus(MESSAGE_STATUS_CREATED);
389     LOG_EXIT
390 }
391
392 void Email::create( EmailAccountInfo& account )
393 {
394         LOG_ENTER
395
396         m_accountId = account.getIntId();
397         //MailSender::getInstance();
398         
399       LoggerD("account ID : " << m_accountId);
400         ScopedMail mail(EmailService::createMailData(account));
401         
402         setEmailAccount(account);       //save account
403
404         mail->mailbox_type = EMAIL_MAILBOX_TYPE_DRAFT;
405         
406         setId(convertId(EmailService::addMail(mail.Get(), NULL)));
407         setFolderType(DRAFTBOX);
408         setMessageStatus(MESSAGE_STATUS_DRAFT);
409         
410     LOG_EXIT
411 }
412
413 void Email::reload()
414 {
415     LOG_ENTER
416
417     LoggerD("mail ID :" << getIntId());
418     m_mail.Reset(EmailService::readMail(getIntId()));           //reset Mail Data
419
420     readHeader();
421     readBody();
422     readInfo();
423
424     //if (m_mail->head) { readHeader(); }
425     //if (m_mail->body) { readBody(); }
426     //if (m_mail->info) { readInfo(); }
427
428     //m_mailbox.Reset(EmailService::getMailboxByMailId(m_accountId, getIntId()) );
429     //setFolderType(EmailConverter::toFolderType(m_mailbox->mailbox_type));
430     
431     setFolderType(EmailConverter::toFolderType(m_mail->mailbox_type));
432
433     LOG_EXIT
434 }
435
436 void Email::readHeader()
437 {
438     LOG_ENTER
439
440     Assert(m_mail && "Header is NULL.");
441
442     if (m_mail->subject) {
443         setSubject(m_mail->subject);
444     }
445
446     if (m_mail->full_address_to) {
447         appendToRecipients(EmailUtils::stripAddressLine(m_mail->full_address_to));
448     }
449
450     if (m_mail->full_address_cc) {
451         appendCcRecipients(EmailUtils::stripAddressLine(m_mail->full_address_cc));
452     }
453
454     if (m_mail->full_address_bcc) {
455         appendBccRecipients(EmailUtils::stripAddressLine(m_mail->full_address_bcc));
456     }
457
458 #if 1
459     struct tm *t = NULL;
460     t = localtime(&m_mail->date_time);
461     struct tm timeinfo;
462         memset(&timeinfo, 0, sizeof(timeinfo));
463     memcpy(t, &timeinfo, sizeof(struct tm));
464     setDateTime(timeinfo); 
465
466 #else
467
468         if (m_mail->datetime[0] != '\0')
469         {
470                 char buf[MAX_DATETIME_STRING_LENGTH];
471                 char *targetBuf = m_mail->datetime;
472                 struct tm timeinfo;
473
474                 memset(buf, 0x00, sizeof(buf));
475                 targetBuf += snprintf(buf, sizeof(buf), "%.4s", targetBuf);
476                 timeinfo.tm_year = atoi(buf) - 1900;
477
478                 memset(buf, 0x00, sizeof(buf));
479                 targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
480                 timeinfo.tm_mon =  atoi(buf) - 1;
481
482                 memset(buf, 0x00, sizeof(buf));
483                 targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
484                 timeinfo.tm_mday =      atoi(buf);
485
486                 memset(buf, 0x00, sizeof(buf));
487                 targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
488                 timeinfo.tm_hour = atoi(buf);
489
490                 memset(buf, 0x00, sizeof(buf));
491                 targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
492                 timeinfo.tm_min = atoi(buf);
493
494                 memset(buf, 0x00, sizeof(buf));
495                 targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
496                 timeinfo.tm_sec = atoi(buf);
497                 
498                 setDateTime(timeinfo);
499         }
500
501 #endif
502         
503 #if 0
504     time_t rawtime;
505     time(&rawtime);
506     struct tm tmpTime = *(localtime(&rawtime));
507
508     tmpTime.tm_year = m_mail->head->datetime.year;
509     tmpTime.tm_mon = m_mail->head->datetime.month;
510     tmpTime.tm_mday = m_mail->head->datetime.day;
511     tmpTime.tm_hour = m_mail->head->datetime.hour;
512     tmpTime.tm_min = m_mail->head->datetime.minute;
513     tmpTime.tm_sec = m_mail->head->datetime.second;
514     mktime(&tmpTime);
515     setDateTime(tmpTime);
516 #endif
517
518     if (m_mail->full_address_from) {
519         Recipients from;
520         from.setRecipients(m_mail->full_address_from);
521         setSourceAddress(from);
522         setSourceAddressValidity(true); //not needed to update in platform
523     }
524
525     LOG_EXIT
526 }
527
528 void Email::readBody() {
529         LOG_ENTER
530
531         Assert(m_mail && "Body is NULL.");
532
533         if (m_mail->file_path_plain) {
534                 LoggerD("m_mail->file_path_plain : " << m_mail->file_path_plain);
535                 DPL::ScopedFClose file(::fopen(m_mail->file_path_plain, "r"));
536                 if (!file) {
537                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
538                                         "Cannot read body file: " << m_mail->file_path_plain);
539                 }
540                 fseek(file.Get(), 0, SEEK_END);
541                 long int size = ftell(file.Get());
542
543                 if (size < 0) {
544                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
545                                         "Cannot read plain body size");
546                 }
547                 
548                 fseek(file.Get(), 0, SEEK_SET);
549                 DPL::ScopedPtr<char> data(new char[size + 1]);
550                 memset(data.Get(), 0, size + 1);
551         TEMP_FAILURE_RETRY(fread(data.Get(), 1, size, file.Get()) &&
552                            ferror(file.Get()) == 0 ? -1 : 0);
553                 setBody(data.Get());
554         }
555
556         //html body.
557         if (m_mail->file_path_html) {
558                 LoggerD("m_mail->file_path_html : " << m_mail->file_path_html);
559                 DPL::ScopedFClose file(::fopen(m_mail->file_path_html, "r")); //auto close, scopedFClose
560                 if (!file) {
561                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
562                                         "Cannot read html body file: " << m_mail->file_path_html);
563                 }
564
565                 fseek(file.Get(), 0, SEEK_END);
566                 long int size = ftell(file.Get());
567
568                 if (size < 0) {
569                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
570                                         "Cannot read html body size");
571                 }
572                 
573                 fseek(file.Get(), 0, SEEK_SET);
574                 DPL::ScopedPtr<char> data(new char[size + 1]);
575                 memset(data.Get(), 0, size + 1);
576         TEMP_FAILURE_RETRY(fread(data.Get(), 1, size, file.Get()) &&
577                            ferror(file.Get()) == 0 ? -1 : 0);
578                 setHtmlBody(data.Get()); //setHtmlBody declarate in Email Calss.
579         }
580
581         //Attachment
582         //email_attachment_info_t* attachment = NULL;
583         email_attachment_data_t* attachment = NULL;
584         int attachmentCount = 0;
585         
586         int error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);    //get Attachment list
587         if (EMAIL_ERROR_NONE != error) {
588                 ThrowMsg( WrtDeviceApis::Commons::PlatformException, "Couldn't get attachment list: ");
589         }
590         
591         if ( attachment && attachmentCount > 0)
592         {
593                 LoggerD("reading attachments , attahcment count = " << attachmentCount);
594                 int i = 0;
595
596                 for ( i = 0; i < attachmentCount; i++)
597                 {
598                         Try {
599                                 LoggerD("attachment ID :" << attachment[i].attachment_id << " name :" << attachment[i].attachment_name << " download :" << attachment[i].save_status << "savefile :" << attachment[i].attachment_path);
600                                 LoggerD("attachment inline status :" << attachment[i].inline_content_status);
601                                 IAttachmentPtr tmpAtt(new Attachment());
602                                 if (attachment[i].attachment_path)
603                                         tmpAtt->init(attachment[i].attachment_path, false);
604                         
605                                 if (tmpAtt)
606                                 {
607                                         LoggerD("attachment[i].inline_content_status : " << attachment[i].inline_content_status);
608                                         tmpAtt->rename(std::string(attachment[i].attachment_name));
609                                         tmpAtt->setAttachmentID(attachment[i].attachment_id);
610                                         tmpAtt->setDownloaded(attachment[i].save_status);
611                                         tmpAtt->setIsInlineAttachment((bool)attachment[i].inline_content_status);
612                                         tmpAtt->setNth(i+1);
613                                         LoggerD(" setNth(i+1) : " << i+1);
614                                         if(attachment[i].inline_content_status == 0)
615                                         {
616                                         appendAttachment(tmpAtt);
617                                         }
618                                         else
619                                         {
620                                                 appendInlineAttachment(tmpAtt);
621                                         }
622                                 }
623                                 LoggerD(" append Attachment complete");
624
625                         
626                         }
627                         catch ( const WrtDeviceApis::Commons::Exception& ex )
628                         {
629                                 LoggerE("Error while trying to append attachment " << attachment[i].attachment_path << ": " << ex.DumpToString());
630                         }
631                         
632                 }
633
634         }
635         
636         if (attachment)
637         {
638                 error = email_free_attachment_data(&attachment, attachmentCount);
639                 if (EMAIL_ERROR_NONE != error) {
640                         ThrowMsg( WrtDeviceApis::Commons::PlatformException, " attachment_data free error! ");
641                 }
642         }
643
644         LOG_EXIT
645 }
646
647 void Email::readInfo()
648 {
649         LOG_ENTER
650
651         if (!m_mail)
652         {
653                 LoggerD("m_mail is NULL");
654                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Info is NULL.");
655         }
656
657         setReadStatus(m_mail->flags_seen_field == 1);
658
659         m_accountId = m_mail->account_id;
660         setConvId(m_mail->thread_id);
661         setPriority( EmailConverter::toMessagePriority( m_mail->priority ) );
662         setSize(m_mail->mail_size);
663
664         LOG_EXIT
665 }
666
667 void Email::updateBody()
668 {
669         LOG_ENTER
670  
671         int error = 0;
672         bool locationChecker = false;
673  
674         if (isBodyValid()) { return; }
675  
676         if (!m_mail) {
677                 LoggerD("m_mail is NULL");
678                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
679         }
680         if (!m_mail->file_path_plain) {
681                 LoggerD("file_path_plain is NULL");
682                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Plain Body is NULL.");
683         }
684
685         // For Plain Body
686         locationChecker = EmailUtils::isFrameworkEmailData(m_mail->file_path_plain);
687         if(locationChecker == true)     // already exist palin body file on email frame work, we can not update that file so make new temp file
688         {
689                 LoggerD("create new plain body");
690                 char buf[] = "XXXXXX";
691                 mode_t mask = umask(S_IWGRP | S_IWOTH);
692                 error = mkstemp(buf);
693                 umask(mask);
694                 std::string bodyFile = buf;
695                 bodyFile = EmailUtils::TMP_DIR_PREFIX+bodyFile;
696                 LoggerD("bodyFile : " << bodyFile);
697
698                 FILE* f = fopen(bodyFile.c_str(), "w");
699                 if (NULL != f) {
700                         fclose(f);
701                 }
702
703                 m_mail->file_path_plain = strdup(bodyFile.c_str());
704         }
705
706         FILE* f = fopen(m_mail->file_path_plain, "w");
707         if (NULL != f) {
708                 fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
709                 fclose(f);
710         }
711         else
712         {
713                 LoggerD("Plain Body file open fail : " << m_mail->file_path_plain);
714                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Plain Body File Open Error");
715         }
716
717
718         // For Html Body
719         locationChecker = EmailUtils::isFrameworkEmailData(m_mail->file_path_html);
720         if((locationChecker == true) || (!m_mail->file_path_html))      // html file is not exist or exist on email frame work then create tmp html file
721         {
722                 LoggerD("create new html body");
723                 char buf[] = "XXXXXX";
724                 mode_t mask = umask(S_IWGRP | S_IWOTH);
725                 error = mkstemp(buf);
726                 umask(mask);
727                 std::string htmlFile = buf;
728                 htmlFile = EmailUtils::TMP_DIR_PREFIX+htmlFile;
729                 LoggerD("htmlFile : " << htmlFile);
730
731                 FILE* f = fopen(htmlFile.c_str(), "w");
732                 if (NULL != f) {
733                         fclose(f);
734                 }
735                 m_mail->file_path_html = strdup(htmlFile.c_str());
736
737                 if(!m_mail->file_path_html)
738                 {
739                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Html Body file is NULL.");
740                 }
741         }
742
743         f = fopen(m_mail->file_path_html, "w");
744         if (NULL != f) {
745                 if(strlen(getHtmlBody().c_str()) > 0)   // check html data is exist if not exist copy plain body to html body
746                 {
747                         fwrite(getHtmlBody().c_str(), strlen(getHtmlBody().c_str()), 1, f);
748                 }
749                 else
750                 {
751                         // htmlBody is empty.
752                 }
753                 fclose(f);
754         }
755         else
756         {
757                 LoggerD("html Body file open fail : " << m_mail->file_path_html);
758                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "html Body File Open Error");
759         }
760
761         m_mail->body_download_status = true;
762
763         setBodyValidity(true);
764
765         LOG_EXIT
766
767 }
768
769 void Email::updateSubject()
770 {
771     LOG_ENTER
772
773     if (isSubjectValid()) { return; }
774
775     LoggerD("update subject, msgId=" << getIdRef());
776
777     if (!m_mail) {
778         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail not allocated.");
779     }
780     
781     m_mail->subject = String::strdup(getSubjectRef());
782     setSubjectValidity(true);
783
784     LOG_EXIT
785 }
786
787 void Email::updateReadStatus()
788 {
789     LOG_ENTER
790
791     if (isReadStatusValid()) { return; }
792
793     LoggerD("update read, msgId=" << getIdRef());
794
795     if (!m_mail) {
796         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail not allocated.");
797     }
798
799     m_mail->flags_seen_field = isRead();
800     setReadStatusValidity(true);
801
802     LOG_EXIT
803 }
804
805 void Email::updateIsRead()
806 {
807     LOG_ENTER
808     if (isReadChangeStatusValid()) {
809         // do not update if not changed
810         return;
811     }
812
813     EmailService::updateSeenFlag(getAccountID(), getIntId(), isReadChangeStatus());
814     setisReadChangeStatusValidity(true);
815     LOG_EXIT
816 }
817
818 void Email::updateMessage()
819 {
820         LOG_ENTER
821         email_meeting_request_t *meeting_req = NULL;
822
823         DPL::Mutex::ScopedLock mx(&m_updateMutex);
824
825         if (!m_mail) {
826                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
827         }
828
829         LoggerD("getCurrentFolder() = " << getCurrentFolder() );
830         LoggerD("m_mail->mail_id = " << m_mail->mail_id );
831         LoggerD("m_mail->file_path_plain = " << m_mail->file_path_plain );
832         LoggerD("m_mail->file_path_html = " << m_mail->file_path_html );
833
834         if(getCurrentFolder() == DRAFTBOX)
835         {
836                 updateBody();
837                 updateSubject();
838                 updateRecipients();
839                 updateFrom();
840                 updateAttachments();
841                 updatePriority();
842         }
843         updateReadStatus();
844
845         //get attachment
846         email_attachment_data_t* attachment=NULL;
847         int attachmentCount = 0;
848         int error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);
849         if (EMAIL_ERROR_NONE != error) {
850                 LoggerW("email_get_attachment_data_list [" << error << "]");
851         }
852
853         error = email_get_meeting_request(m_mail->mail_id, &meeting_req);
854         if (EMAIL_ERROR_NONE != error) {
855                 LoggerW("email_get_meeting_request() failed [%d]\n" << error);
856         }
857
858         error = email_update_mail( m_mail.Get(), attachment, attachmentCount, meeting_req, 0);
859         if (EMAIL_ERROR_NONE != error) {
860                 LoggerW("Nothing to update or error. [" << error << "]");
861         }
862
863         if(meeting_req) {
864                 email_free_meeting_request(&meeting_req, 1);
865         }
866
867         if (attachment)
868         {
869                 error = email_free_attachment_data(&attachment, attachmentCount);
870                 if (EMAIL_ERROR_NONE != error) {
871                         LoggerW("email_free_attachment_data [" << error << "]");
872                 }               
873         }
874
875         LOG_EXIT
876 }
877
878 void Email::createSendMessage()
879 {
880         LOG_ENTER
881
882     MailSender::getInstance(); //start email service
883         LoggerD("getUID:  " << getUID());
884         if ( getUID() > 0 && m_accountId > 0)
885         {       
886                 update();
887         }
888         else
889         {       
890         DPL::Mutex::ScopedLock mx(&m_updateMutex);
891                 
892                 EmailAccountInfo account = getEmailAccount();
893                 m_accountId = account.getIntId();       //set account ID
894                 LoggerD("account ID : " << m_accountId);
895                 m_mail.Reset(EmailService::createMailData(account));
896                 
897                 updateSubject();
898                 updateBody();
899                 updateRecipients();
900                 updatePriority();
901                 updateReadStatus();
902                 
903                 email_mailbox_t* mailbox;
904                 int error = email_get_mailbox_by_mailbox_type(m_accountId, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox );
905                 if (EMAIL_ERROR_NONE != error) {
906                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
907                         "Couldn't add message to mailbox. [" << error << "]");
908                 }
909                 if ( mailbox->mailbox_id )
910                         m_mail->mailbox_id = mailbox->mailbox_id;
911                 LoggerD("mail MailBox id :" << m_mail->mailbox_id);
912
913                 error = email_add_mail(m_mail.Get(), NULL, 0, NULL, 0);
914                 if (EMAIL_ERROR_NONE != error) {
915                        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
916                                 "Couldn't add message to mailbox. [" << error << "]");
917                 }
918                 
919                 LoggerD("m_mail->mail_id =" << m_mail->mail_id);
920                 
921                 setId(convertId(m_mail->mail_id));
922                 setFolderType(OUTBOX);
923                 setMessageStatus(MESSAGE_STATUS_SENDING);
924
925                 updateAttachments();    //update Attachment.
926                 
927                 error = email_free_mailbox(&mailbox, 1);
928                 if (EMAIL_ERROR_NONE != error) {
929                         LoggerE("Failed to destroy mailbox: " << error);
930                 }
931
932                 LoggerD("m_mail->from" << m_mail->full_address_from);
933
934                 email_mail_data_t* result = NULL;
935
936                 error = email_get_mail_data(m_mail->mail_id, &result);
937                 if (EMAIL_ERROR_NONE != error) {
938                     ThrowMsg(WrtDeviceApis::Commons::PlatformException,
939                              "Couldn't find message " << m_mail->mail_id << ". [" << error << "]");
940                 }
941
942
943                 if (m_mail->file_path_plain)
944                         free(m_mail->file_path_plain);
945                 m_mail->file_path_plain = strdup(result->file_path_plain);
946                 
947                 if ( m_mail->file_path_html)
948                 {
949                         free(m_mail->file_path_html);
950                 }
951
952                 if(result->file_path_html)
953                 {
954                         m_mail->file_path_html = strdup(result->file_path_html);
955                 }
956                 
957                 error = email_free_mail_data(&result, 1);
958                 if (EMAIL_ERROR_NONE != error) {
959                     ThrowMsg(WrtDeviceApis::Commons::PlatformException,
960                              "Couldn't find message " << m_mail->mail_id << ". [" << error << "]");
961                 }               
962
963     }
964         LOG_EXIT
965 }
966
967
968 void Email::addMessageToDraft()
969 {
970     LOG_ENTER
971
972     MailSender::getInstance(); //start email service
973         
974         LoggerD("getUID:  " << getUID());
975     if ( getUID() > 0 && m_accountId > 0)
976     {   
977                 update();
978     }
979     else
980     {   
981                 DPL::Mutex::ScopedLock mx(&m_updateMutex);
982                 
983                 EmailAccountInfo account = getEmailAccount();
984                 m_accountId = account.getIntId();       //set account ID
985                 LoggerD("account ID : " << m_accountId);
986                 m_mail.Reset(EmailService::createMailData(account));
987                 
988                 updateSubject();
989                 updateBody();
990                 updateRecipients();
991                 updatePriority();
992                 updateReadStatus();
993                 
994                 email_mailbox_t* mailbox;
995                 int error = email_get_mailbox_by_mailbox_type(m_accountId, EMAIL_MAILBOX_TYPE_DRAFT, &mailbox );
996                 if (EMAIL_ERROR_NONE != error) {
997                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
998                         "Couldn't add message to mailbox. [" << error << "]");
999                 }
1000                 if ( mailbox->mailbox_id )
1001                         m_mail->mailbox_id = mailbox->mailbox_id;
1002                 LoggerD("mail MailBox id :" << m_mail->mailbox_id);
1003
1004                 error = email_add_mail(m_mail.Get(), NULL, 0, NULL, 0);
1005                 if (EMAIL_ERROR_NONE != error) {
1006                        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1007                                 "Couldn't add message to mailbox. [" << error << "]");
1008                 }
1009                 
1010                 LoggerD("message id =" << m_mail->mail_id);
1011                 
1012                 setId(convertId(m_mail->mail_id));
1013                 setFolderType(DRAFTBOX);
1014                 setMessageStatus(MESSAGE_STATUS_DRAFT);
1015
1016                 updateAttachments();    //update Attachment.
1017                 
1018                 error = email_free_mailbox(&mailbox, 1);
1019                 if (EMAIL_ERROR_NONE != error) {
1020                         LoggerE("Failed to destroy mailbox: " << error);
1021                 }
1022
1023                 LoggerD("m_mail->from" << m_mail->full_address_from);
1024
1025                 email_mail_data_t* result = NULL;
1026
1027                 error = email_get_mail_data(m_mail->mail_id, &result);
1028                 if (EMAIL_ERROR_NONE != error) {
1029                     ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1030                              "Couldn't find message " << m_mail->mail_id << ". [" << error << "]");
1031                 }
1032
1033                 if (m_mail->file_path_plain)
1034                         free(m_mail->file_path_plain);
1035                 m_mail->file_path_plain = strdup(result->file_path_plain);
1036                 
1037                 if ( m_mail->file_path_html)
1038                 {
1039                         free(m_mail->file_path_html);
1040                 }
1041
1042                 if(result->file_path_html)
1043                 {
1044                         m_mail->file_path_html = strdup(result->file_path_html);
1045                 }
1046                 
1047                 error = email_free_mail_data(&result, 1);
1048                 if (EMAIL_ERROR_NONE != error) {
1049                     ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1050                              "Couldn't find message " << m_mail->mail_id << ". [" << error << "]");
1051                 }               
1052
1053     }
1054
1055     LOG_EXIT
1056 }
1057
1058 void Email::updateRecipients()
1059 {
1060     LOG_ENTER
1061
1062     if (getToValidity() && getCcValidity() && getBccValidity()) { return; }
1063
1064     if (!m_mail) {
1065         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
1066     }
1067
1068     if (!getToValidity()) {
1069         std::string addressLine = EmailUtils::formatAddressLine(getToRecipients());
1070         if (m_mail->full_address_to) {
1071             free(m_mail->full_address_to);
1072         }
1073         m_mail->full_address_to = String::strdup(addressLine);
1074         setToValidity(true);
1075     }
1076
1077     if (!getCcValidity()) {
1078         std::string addressLine = EmailUtils::formatAddressLine(getCcRecipients());
1079         if (m_mail->full_address_cc) {
1080             free(m_mail->full_address_cc);
1081         }
1082         m_mail->full_address_cc = String::strdup(addressLine);
1083         setCcValidity(true);
1084     }
1085
1086     if (!getBccValidity()) {
1087         std::string addressLine = EmailUtils::formatAddressLine(getBccRecipients());
1088         if (m_mail->full_address_bcc) {
1089             free(m_mail->full_address_bcc);
1090         }
1091         m_mail->full_address_bcc = String::strdup(addressLine);
1092         setBccValidity(true);
1093     }
1094
1095     LOG_EXIT
1096 }
1097
1098 void Email::updateFrom()
1099 {
1100     LOG_ENTER
1101
1102     if (getFromValidity()) { return; }
1103
1104     if (!m_mail) {
1105         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
1106     }
1107
1108     m_mail->account_id = m_accountId;
1109
1110     if (m_mail->full_address_from) {
1111           free(m_mail->full_address_from);
1112     }
1113     m_mail->full_address_from = String::strdup(getFrom());
1114
1115     setFromValidity(true);
1116
1117     LOG_EXIT
1118 }
1119
1120 void Email::updateAttachments()
1121 {
1122     LOG_ENTER
1123
1124     if (isAttachmentsValid()) { return; }
1125
1126     if (!m_mail) {
1127         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
1128     }
1129
1130     email_attachment_data_t* attachment = NULL;
1131     int attachmentCount = 0;            
1132     email_mailbox_t* mailBox = NULL;
1133     int error = 0;
1134
1135     Try {
1136                  //clean attachment
1137                 LoggerD("update attachments, msgId=" << getIdRef());
1138                 LoggerD("m_mail->mail_id=" << m_mail->mail_id);
1139                 error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);        //get Attachment list
1140                 if (EMAIL_ERROR_NONE != error) {
1141                         ThrowMsg( WrtDeviceApis::Commons::PlatformException, "Couldn't get attachment list: ");
1142                 }
1143                 error = email_get_mailbox_by_mailbox_id(m_mail->mailbox_id, &mailBox);
1144                 
1145                 if (EMAIL_ERROR_NONE != error) {
1146                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1147                         "Couldn't get mailbox. [" << error << "]");
1148                 }       
1149                  
1150                 if ( attachmentCount > 0 )
1151                 {
1152                         LoggerD("attachmentCount=" << attachmentCount);
1153                         int i = 0;
1154                         std::stringstream stream;
1155                         for ( i = 0; i < attachmentCount; i++)
1156                         {
1157                                 LoggerD("file name:" << attachment[i].attachment_name << " file path :" << attachment[i].attachment_path);
1158                                 int attachmentId = attachment[i].attachment_id;
1159
1160                                 int error = email_delete_attachment(attachmentId);
1161                                 if (EMAIL_ERROR_NONE != error) {
1162                                     LoggerD("Error Num = " << error);
1163                                     ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1164                                              "Error while adding attachment. [" << error << "]");
1165                                 }
1166                                 stream.str("");
1167                         }
1168
1169                         if ( attachment )
1170                         {
1171                                 error = email_free_attachment_data(&attachment, attachmentCount);
1172                                 if (EMAIL_ERROR_NONE != error) {
1173                                         ThrowMsg( WrtDeviceApis::Commons::PlatformException, " attachment_data free error! ");
1174                                 }
1175                         }
1176
1177                 }
1178                 
1179                 //set Attachment
1180                 std::size_t attachmentSize = getAttachmentsCount();
1181                 std::size_t inlineAttachmentSize = getInlineAttachmentsCount();
1182                 
1183                 LoggerD("update attachments, attachmentSize=" << attachmentSize);
1184                 if (attachmentSize > 0)
1185                 {
1186                         email_attachment_data_t* attachment_info = NULL;
1187                         for (std::size_t i = 0; i < attachmentSize; ++i)
1188                         {
1189                                 IAttachmentPtr att = getAttachment(i);
1190                                 if (!att) {
1191                                         LoggerD("skip att" << i);
1192                                         continue;
1193                                 }
1194
1195                                 //copy attachment file
1196                                 std::stringstream cp_cmd;
1197                                 char buf[] = "/tmp/XXXXXX";
1198                                 mode_t mask = umask(S_IWGRP | S_IWOTH);
1199                                 error = mkstemp(buf);
1200                                 umask(mask);
1201
1202                                 cp_cmd << COMMAND_NAME;
1203                                 cp_cmd << " " << COMMAND_SWITCH_RECURSIVE;
1204                                 cp_cmd << " \"" << att->getFullPath() << "\"";
1205                                 cp_cmd << " \"" << buf << "\"";
1206
1207                                 attachment_info = EmailService::alloc<email_attachment_data_t>();                                       
1208                                 attachment_info->attachment_name = String::strdup(att->getShortName());
1209                                 attachment_info->attachment_path = String::strdup( buf );
1210                                 attachment_info->save_status = true;
1211                                 attachment_info->inline_content_status = 0;
1212
1213                                 LoggerD("attachment_info->attachment_name=" << attachment_info->attachment_name);
1214                                 LoggerD("attachment_info->attachment_path=" << attachment_info->attachment_path);
1215                                 LoggerD("attachment_info->save_status=" << attachment_info->save_status);
1216                                 LoggerD("attachment_info->inline_content_status=" << attachment_info->inline_content_status);
1217
1218                                 LoggerD("Copy Command=" << cp_cmd.str());
1219                                 if (EINA_TRUE != ecore_file_is_dir(att->getFullPath().c_str())) {
1220                                         LoggerD("att->getFullPath().c_str()=" << att->getFullPath().c_str());
1221                                         if (EINA_TRUE != ecore_file_cp(att->getFullPath().c_str(), buf)) {
1222                                                 LoggerD("buf=" << buf);
1223                                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to copy file");
1224                                         }
1225                                 }
1226
1227 /*
1228                                 int result = system(cp_cmd.str().c_str());
1229                                 if (-1 != result) {
1230                                         if (0 != WIFEXITED(result)) {
1231                                                 if (0 != WEXITSTATUS(result)) {
1232                                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Command failed.");
1233                                                 }
1234                                         } else {
1235                                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1236                                                 "Command terminated abnormally.");
1237                                         }
1238                                 } else {
1239                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't launch command.");
1240                                 }
1241 */
1242
1243                                 LoggerD("add Attachment");
1244                                 int error = email_add_attachment(m_mail->mail_id, attachment_info);
1245                                 if (EMAIL_ERROR_NONE != error) {
1246                                         LoggerD("error :" << error);
1247                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error while adding attachment. [" << error << "]");
1248                                 }
1249                                 else 
1250                                 {       
1251                                         LoggerD(" attachment id : " << attachment_info->attachment_id);
1252                                         LoggerD(" attachment inline : " << attachment_info->inline_content_status);
1253                                         LoggerD(" setNth(i+1) : " << i+1);
1254                                         att->setDownloaded(true);
1255                                         att->setIsInlineAttachment(FALSE);
1256                                         att->setAttachmentID(attachment_info->attachment_id);
1257                                         att->setMessage(SharedFromThis());
1258                                         att->setNth(i+1);
1259                                 }
1260                                 
1261                                 if (attachment_info)
1262                                         EmailService::freeAttachment(attachment_info);
1263                         }       
1264                         
1265                 }
1266                 LoggerD("update attachments, inlineAttachmentSize=" << inlineAttachmentSize);
1267                 if (inlineAttachmentSize > 0) 
1268                 {
1269                         email_attachment_data_t* attachment_info = NULL;
1270                         for (std::size_t i = 0; i < inlineAttachmentSize; ++i) 
1271                         {
1272                                 IAttachmentPtr att = getInlineAttachment(i);
1273                                 if (!att) {
1274                                         continue;
1275                                 }
1276
1277                                 //copy attachment file
1278                                 std::stringstream cp_cmd;
1279                                 char buf[] = "/tmp/XXXXXX";
1280                                 mode_t mask = umask(S_IWGRP | S_IWOTH);
1281                                 error = mkstemp(buf);
1282                                 umask(mask);
1283
1284                                 cp_cmd << COMMAND_NAME;
1285                                 cp_cmd << " " << COMMAND_SWITCH_RECURSIVE;
1286                                 cp_cmd << " \"" << att->getFullPath() << "\"";
1287                                 cp_cmd << " \"" << buf << "\"";
1288
1289                                 attachment_info = EmailService::alloc<email_attachment_data_t>();                                       
1290                                 attachment_info->attachment_name = String::strdup(att->getShortName());
1291                                 attachment_info->attachment_path = String::strdup( buf );
1292                                 attachment_info->save_status = true;
1293                                 attachment_info->inline_content_status = 1;
1294                                 LoggerD("attachment_info->inline_content_status=" << attachment_info->inline_content_status);
1295
1296                                 LoggerD("Copy Command=" << cp_cmd.str());
1297                                 if (EINA_TRUE != ecore_file_is_dir(att->getFullPath().c_str())) {
1298                                         LoggerD("att->getFullPath().c_str()=" << att->getFullPath().c_str());
1299                                         if (EINA_TRUE != ecore_file_cp(att->getFullPath().c_str(), buf)) {
1300                                                 LoggerD("buf=" << buf);
1301                                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to copy file");
1302                                         }
1303                                 }
1304
1305 /*
1306                                 int result = system(cp_cmd.str().c_str());
1307                                 if (-1 != result) {
1308                                         if (0 != WIFEXITED(result)) {
1309                                                 if (0 != WEXITSTATUS(result)) {
1310                                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Command failed.");
1311                                                 }
1312                                         } else {
1313                                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1314                                                 "Command terminated abnormally.");
1315                                         }
1316                                 } else {
1317                                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't launch command.");
1318                                 }
1319 */
1320
1321
1322                                 LoggerD("add Attachment");
1323                                 int error = email_add_attachment(m_mail->mail_id, attachment_info);
1324                                 if (EMAIL_ERROR_NONE != error) {
1325                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1326                                      "Error while adding attachment. [" << error << "]");
1327                                 }
1328                                 else 
1329                                 {       
1330                                         LoggerD(" attachment id : " << attachment_info->attachment_id);                         
1331                                         LoggerD(" attachment inline : " << attachment_info->inline_content_status);
1332                                         LoggerD(" setNth(i+(int)attachmentSize+1) : " << i+(int)attachmentSize+1);
1333                                         att->setDownloaded(true);
1334                                         att->setIsInlineAttachment(TRUE);
1335                                         att->setAttachmentID(attachment_info->attachment_id);
1336                                         att->setMessage(SharedFromThis());
1337 //                                      att->setNth(i+1);
1338                                         att->setNth(i + (int)attachmentSize + 1);
1339                                 }
1340                                 
1341                                 if (attachment_info)
1342                                         EmailService::freeAttachment(attachment_info);
1343                         }       
1344                         
1345                 }
1346         
1347
1348         
1349         } 
1350         Catch(WrtDeviceApis::Commons::PlatformException) {
1351            if (attachment) 
1352            {
1353                 int error = email_free_attachment_data(&attachment, attachmentCount);
1354                 if (EMAIL_ERROR_NONE != error) {
1355                         ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1356                                      "Error while adding attachment data [" << error << "]");
1357                 }
1358
1359                 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1360                                      "Error attachment Update");
1361            }
1362         }
1363
1364     LOG_EXIT
1365 }
1366
1367 void Email::updatePriority()
1368 {
1369     LOG_ENTER
1370
1371     if (isPriorityValid()) { return; }
1372
1373     if (!m_mail) {
1374         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail not allocated.");
1375     }
1376
1377     m_mail->priority = EmailConverter::toMailPriority( getPriority());
1378     setPriorityValid(true);
1379
1380     LOG_EXIT
1381 }
1382
1383 int Email::getIntId() const
1384 {
1385     return convertId(getIdRef());
1386 }
1387
1388 }
1389 }