function saveImapMessage($data, $folder = null)
 {
     global $osC_Session;
     require_once DIR_FS_CATALOG . 'ext/phpmailer/class.phpmailer.php';
     $mailer = new PHPMailer();
     $mailer->IsSMTP();
     $mailer->CharSet = "utf-8";
     $mailer->Host = $this->getSmtpHost();
     $mailer->Port = $this->getSmtpPort();
     $mailer->SMTPAuth = true;
     $mailer->Username = $this->getSmtpUsername();
     $mailer->Password = $this->getSmtpPassword();
     $mailer->FromName = $data['from'];
     $mailer->From = $data['sender'];
     if ($data['notification'] == 'true') {
         $mailer->ConfirmReadingTo = $this->getAccountEmail();
     }
     $mailer->Subject = $data['subject'];
     $mailer->Body = $data['body'];
     $mailer->AltBody = "This is the body in plain text for non-HTML mail clients";
     $mailer->Priority = $data['priority'];
     $mailer->IsHTML($data['content_type'] == 'html' ? true : false);
     foreach ($data['to'] as $to) {
         $mailer->AddAddress($to['email'], $to['name']);
     }
     if ($data['cc'] != null) {
         foreach ($data['cc'] as $cc) {
             $mailer->AddCC($cc['email'], $cc['name']);
         }
     }
     if ($data['bcc'] != null) {
         foreach ($data['bcc'] as $bcc) {
             $mailer->AddBCC($bcc['email'], $bcc['name']);
         }
     }
     $path = DIR_FS_CACHE_ADMIN . 'emails/attachments/' . $osC_Session->getID();
     $osC_DirectoryListing = new osC_DirectoryListing($path);
     foreach ($osC_DirectoryListing->getFiles() as $file) {
         $mailer->AddAttachment($path . '/' . $file['name']);
     }
     $mailer->SetMessageType();
     $raw_text = $mailer->CreateHeader() . "\r\n" . $mailer->CreateBody() . "\r\n";
     if ($this->connectMailServer($folder)) {
         if ($this->_inbox->append_message(imap::utf7_imap_encode($folder), $raw_text)) {
             $this->closeMailServer();
             return true;
         }
     }
     $this->closeMailServer();
     return false;
 }