/** * Returns the mail content. If it is in repository returns the file content, * else tries to get the content from database (if column content exists). * @access public * @param void * @return string */ function getContent() { if (FileRepository::isInRepository($this->getContentFileId())) { return FileRepository::getFileContent($this->getContentFileId()); //return FileRepository::getFileContent($this->getContentFileId(), config_option('file_storage_adapter')); } else if ($this->getMailData()->columnExists('content')) { return $this->getMailData()->getContent(); } }
/** * Return content of this file * * @param void * @return string */ function getFileContent() { return FileRepository::getFileContent($this->getRepositoryId()); }
function generateAllSizePictures($repository_id, $save = true) { try { if (!FileRepository::isInRepository($repository_id)) { return; } $result = array(); $temp_file_name = CACHE_DIR . "/contact-" . $this->getId() . ".png"; $content = FileRepository::getFileContent($repository_id); file_put_contents($temp_file_name, $content); // generate large image $rep_id = $this->generatePictureFile($temp_file_name, 600, str_replace('.png', '-large.png', $temp_file_name)); if (is_null($rep_id)) { $rep_id = $repository_id; } $result['large'] = $rep_id; // generate medium image $rep_id = $this->generatePictureFile($temp_file_name, 200, str_replace('.png', '-medium.png', $temp_file_name)); if (is_null($rep_id)) { $rep_id = $repository_id; } $result['medium'] = $rep_id; // generate small image $rep_id = $this->generatePictureFile($temp_file_name, 60, str_replace('.png', '-small.png', $temp_file_name)); if (is_null($rep_id)) { $rep_id = $repository_id; } $result['small'] = $rep_id; $this->setPictureFile($result['large']); $this->setPictureFileMedium($result['medium']); $this->setPictureFileSmall($result['small']); if ($save) { $this->save(); } return $result; } catch (Exception $e) { Logger::log_r("Error in Contact::generateAllSizePictures('{$repository_id}'): " . $e->getMessage()); Logger::log_r($e->getTraceAsString()); } }
private function build_vcard($contacts) { $vcard = ""; foreach($contacts as $contact) { $vcard .= "BEGIN:VCARD\nVERSION:3.0\n"; $vcard .= "N:" . $contact->getSurname() . ";" . $contact->getFirstname() . "\n"; $vcard .= "FN:" . $contact->getFirstname() . " " . $contact->getSurname() . "\n"; if ($contact->getCompany() instanceof Contact) $vcard .= "ORG:" . $contact->getCompany()->getObjectName() . "\n"; if ($contact->getJobTitle()) $vcard .= "TITLE:" . $contact->getJobTitle() . "\n"; if ($contact->getDepartment()) $vcard .= "X-DEPARTMENT:" . $contact->getDepartment() . "\n"; if ($contact->getBirthday() instanceof DateTimeValue) $vcard .= "BDAY:" . $contact->getBirthday()->format("Y-m-d") . "\n"; //HOME if ($contact->getPhoneNumber('home',true)) $vcard .= "TEL;TYPE=HOME,VOICE:" . $contact->getPhoneNumber('home',true) . "\n"; if ($contact->getPhoneNumber('home')) $vcard .= "TEL;TYPE=HOME,VOICE:" . $contact->getPhoneNumber('home') . "\n"; if ($contact->getPhoneNumber('fax')) $vcard .= "TEL;TYPE=HOME,FAX:" . $contact->getPhoneNumber('fax') . "\n"; if ($contact->getPhoneNumber('mobile')) $vcard .= "TEL;TYPE=CELL,VOICE:" . $contact->getPhoneNumber('mobile') . "\n"; if ($contact->getPhoneNumber('pager')) $vcard .= "TEL;TYPE=PAGER:" . $contact->getPhoneNumber('pager') . "\n"; $haddress = $contact->getAddress('home'); if ($haddress) $vcard .= "ADR;TYPE=HOME:" . $haddress->getStreet() .";". $haddress->getCity() .";". $haddress->getState() .";". $haddress->getZipcode() .";". $haddress->getCountryName() . "\n"; if ($contact->getWebpageUrl('personal')) $vcard .= "URL;TYPE=HOME:" . $contact->getWebpageUrl('personal') . "\n"; //WORK if ($contact->getPhoneNumber('work',true)) $vcard .= "TEL;TYPE=WORK,VOICE:" . $contact->getPhoneNumber('work',true) . "\n"; if ($contact->getPhoneNumber('work')) $vcard .= "TEL;TYPE=WORK,VOICE:" . $contact->getPhoneNumber('work') . "\n"; if ($contact->getPhoneNumber('fax', true)) $vcard .= "TEL;TYPE=WORK,FAX:" . $contact->getPhoneNumber('fax', true) . "\n"; $waddress = $contact->getAddress('work'); if ($waddress) $vcard .= "ADR;TYPE=WORK:" . $waddress->getStreet() .";". $waddress->getCity() .";". $waddress->getState() .";". $waddress->getZipcode() .";". $waddress->getCountryName() . "\n"; if ($contact->getPhoneNumber('assistant')) $vcard .= "TEL;TYPE=X-ASSISTANT,VOICE:" . $contact->getPhoneNumber('assistant') . "\n"; if ($contact->getPhoneNumber('callback')) $vcard .= "TEL;TYPE=X-CALLBACK,VOICE:" . $contact->getPhoneNumber('callback') . "\n"; if ($contact->getWebpageUrl('work')) $vcard .= "URL;TYPE=WORK:" . $contact->getWebpageUrl('work') . "\n"; //OTHER if ($contact->getPhoneNumber('other',true)) $vcard .= "TEL;TYPE=VOICE:" . $contact->getPhoneNumber('other',true) . "\n"; if ($contact->getPhoneNumber('other')) $vcard .= "TEL;TYPE=VOICE:" . $contact->getPhoneNumber('other') . "\n"; $oaddress = $contact->getAddress('other'); if ($oaddress) $vcard .= "ADR;TYPE=INTL:" . $oaddress->getStreet() .";". $oaddress->getCity() .";". $oaddress->getState() .";". $oaddress->getZipcode() .";". $oaddress->getCountryName() . "\n"; if ($contact->getWebpageUrl('other')) $vcard .= "URL:" . $contact->getWebpageUrl('other') . "\n"; if ($contact->getEmailAddress('personal')) $vcard .= "EMAIL;TYPE=PREF,INTERNET:" . $contact->getEmailAddress() . "\n"; $personal_emails = $contact->getContactEmails('personal'); if (!is_null($personal_emails) && isset($personal_emails[0])) $vcard .= "EMAIL;TYPE=INTERNET:" . $personal_emails[0]->getEmailAddress() . "\n"; if (!is_null($personal_emails) && isset($personal_emails[1])) $vcard .= "EMAIL;TYPE=INTERNET:" . $personal_emails[1]->getEmailAddress() . "\n"; if ($contact->hasPicture()) { $data = FileRepository::getFileContent($contact->getPictureFile()); $chunklen = 62; $pre = "PHOTO;ENCODING=BASE64;TYPE=PNG:"; $b64 = base64_encode($data); $enc_data = substr($b64, 0, $chunklen + 1 - strlen($pre)) . "\n "; $enc_data .= chunk_split(substr($b64, $chunklen + 1 - strlen($pre)), $chunklen, "\n "); $vcard .= $pre . $enc_data . "\n"; } $vcard .= "END:VCARD\n"; } return $vcard; }
private function readAttachmentsFromFileSystem(MailContent $mail, &$att_version) { $att_version = 2; if ($mail->getHasAttachments() && FileRepository::isInRepository($mail->getContentFileId())) { $attachments = array(); $content = FileRepository::getFileContent($mail->getContentFileId()); if (str_starts_with($content, "--")) { $att_version = 1; } else { if (str_starts_with($content, "#att_ver")) { $att_version = trim(str_replace("#att_ver", "", substr($content, 0, strpos($content, "\n")))); } } if ($att_version < 2) { $i = 0; $offset = 0; while ($offset < strlen($content)) { $delim = "--000000000000000000000000000{$i}"; if (strpos($content, $delim, $offset) !== FALSE) { $offset = strpos($content, $delim) + strlen($delim); $endline = strpos($content, ";", $offset); $name = substr($content, $offset + 1, $endline - $offset - 1); $pos = strpos($name, ":"); $name = trim(substr($name, $pos + 1, strlen($name) - $pos - 1)); $offset = $endline + 1; $endline = strpos($content, ";", $offset); $type = substr($content, $offset + 1, $endline - $offset - 1); $pos = strpos($type, ":"); $type = trim(substr($type, $pos + 1, strlen($type) - $pos - 1)); $offset = $endline + 1; $endline = strpos($content, "{$delim}--"); $attachments[] = array('name' => $name, 'type' => $type, 'data' => base64_decode(trim(substr($content, $offset, $endline - $offset - 1)))); $offset = strpos($content, "{$delim}--") + strlen("{$delim}--") + 1; } else { break; } $i++; } } else { $lines = explode("\n", $content); foreach ($lines as $line) { if (!str_starts_with($line, "#") && trim($line) !== "") { $data = explode(",", $line); if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) { $path = FileRepository::getBackend()->getFilePath($data[2]); } else { $path = ROOT . "/tmp/" . gen_id(); file_put_contents($path, FileRepository::getFileContent($data[2])); } $attachments[] = array('name' => $data[0], 'type' => $data[1], 'path' => $path, 'repo_id' => $data[2]); } } } } else { $attachments = null; } return $attachments; }
/** * Return content of this file * * @param void * @return string */ function getFileContent() { try { return FileRepository::getFileContent($this->getRepositoryId()); } catch (Exception $e) { return ''; } }
/** * Returns the mail content. If it is in repository returns the file content, * else tries to get the content from database (if column content exists). * * @access public * @param void * @return string */ function getContent() { if (FileRepository::isInRepository($this->getContentFileId())) { return FileRepository::getFileContent($this->getContentFileId()); } else { if ($this->getMailData()->columnExists('content')) { return $this->getMailData()->getContent(); } } }
function classifyFile($classification_data, $email, $parsedEmail, $members, $remove_prev, $use_transaction) { if (!is_array($classification_data)) { $classification_data = array(); } if (!isset($parsedEmail["Attachments"])) { return; //throw new Exception(lang('no attachments found for email')); } $account_owner = logged_user() instanceof contact ? logged_user() : Contacts::findById($email->getAccount()->getContactId()); for ($c = 0; $c < count($classification_data); $c++) { if (isset($classification_data["att_" . $c]) && $classification_data["att_" . $c] && isset($parsedEmail["Attachments"][$c])) { // dont classify inline images if (array_var($parsedEmail["Attachments"][$c], 'FileDisposition') == 'attachment') { $att = $parsedEmail["Attachments"][$c]; $fName = str_starts_with($att["FileName"], "=?") ? iconv_mime_decode($att["FileName"], 0, "UTF-8") : utf8_safe($att["FileName"]); if (trim($fName) == "" && strlen($att["FileName"]) > 0) { $fName = utf8_encode($att["FileName"]); } $extension = get_file_extension(basename($fName)); $type_file_allow = FileTypes::getByExtension($extension); if (!$type_file_allow instanceof FileType || $type_file_allow->getIsAllow() == 1) { try { $remove_previous_members = $remove_prev; // check for file name and size, if there are some then compare the contents, if content is equal do not classify the attachment. $file_exists = 0; $possible_equal_file_rows = DB::executeAll("SELECT * FROM " . TABLE_PREFIX . "project_file_revisions r \r\n\t\t\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "objects o ON o.id=r.file_id \r\n\t\t\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "project_files f ON f.object_id=r.file_id\r\n\t\t\t\t\t\t\t\tWHERE o.name=" . DB::escape($fName) . " AND r.filesize='" . strlen($att["Data"]) . "' \r\n\t\t\t\t\t\t\t\tAND r.revision_number=(SELECT max(r2.revision_number) FROM " . TABLE_PREFIX . "project_file_revisions r2 WHERE r2.file_id=r.file_id)"); if (is_array($possible_equal_file_rows)) { foreach ($possible_equal_file_rows as $row) { $content = FileRepository::getFileContent($row['repository_id']); if ($content == $att['Data']) { // file already exists $file_exists = $row['file_id']; //Logger::log($email->getId()." - ".$row['mail_id']." - $fName"); if ($remove_previous_members && $row['mail_id'] != $email->getId()) { $remove_previous_members = false; } break; } } } if ($file_exists > 0) { $file = ProjectFiles::findById($file_exists); } else { $file = ProjectFiles::findOne(array('conditions' => "mail_id = " . $email->getId() . " AND o.name = " . DB::escape($fName) . "")); } if ($use_transaction) { DB::beginWork(); } if ($file == null) { $fileIsNew = true; $file = new ProjectFile(); $file->setFilename($fName); $file->setIsVisible(true); $file->setMailId($email->getId()); $file->setCreatedById($account_owner->getId()); $file->save(); } else { $fileIsNew = false; } if ($remove_previous_members) { $dim_ids = array(0); foreach ($members as $m) { $dim_ids[$m->getDimensionId()] = $m->getDimensionId(); } ObjectMembers::delete('`object_id` = ' . $file->getId() . ' AND `member_id` IN (SELECT `m`.`id` FROM `' . TABLE_PREFIX . 'members` `m` WHERE `m`.`dimension_id` IN (' . implode(',', $dim_ids) . '))'); } $file->addToMembers($members); // fill sharing table in background add_object_to_sharing_table($file, $account_owner); //$file->addToSharingTable(); $enc = array_var($parsedMail, 'Encoding', 'UTF-8'); $ext = utf8_substr($fName, strrpos($fName, '.') + 1, utf8_strlen($fName, $enc), $enc); $mime_type = ''; if (Mime_Types::instance()->has_type($att["content-type"])) { $mime_type = $att["content-type"]; //mime type is listed & valid } else { $mime_type = Mime_Types::instance()->get_type($ext); //Attempt to infer mime type } $userid = logged_user() ? logged_user()->getId() : "0"; $tempFileName = ROOT . "/tmp/" . $userid . "x" . gen_id(); $fh = fopen($tempFileName, 'w') or die("Can't open file"); fwrite($fh, $att["Data"]); fclose($fh); $fileToSave = array("name" => $fName, "type" => $mime_type, "tmp_name" => $tempFileName, "error" => 0, "size" => filesize($tempFileName)); if ($fileIsNew || !$file->getLastRevision() instanceof ProjectFileRevision) { $revision = $file->handleUploadedFile($fileToSave, true, lang('attachment from email', $email->getSubject())); // handle uploaded file $revision->setCreatedById($account_owner->getId()); $revision->save(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD); /* }else{ $revision = $file->getLastRevision(); $new_hash = hash_file("sha256", $tempFileName); if ($revision->getHash() != $new_hash) { $revision = $file->handleUploadedFile($fileToSave, true, lang('attachment from email', $email->getSubject())); // handle uploaded file ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD); }*/ } if ($use_transaction) { DB::commit(); } // Error... } catch (Exception $e) { if ($use_transaction) { DB::rollback(); } flash_error($e->getMessage()); ajx_current("empty"); } } else { flash_error(lang('file extension no allow classify', $fName)); } if (isset($tempFileName) && is_file($tempFileName)) { unlink($tempFileName); } } } } }
private function build_vcard($contacts) { $vcard = ""; foreach ($contacts as $contact) { $vcard .= "BEGIN:VCARD\nVERSION:3.0\n"; $vcard .= "N:" . $contact->getLastname() . ";" . $contact->getFirstname() . "\n"; $vcard .= "FN:" . $contact->getFirstname() . " " . $contact->getLastname() . "\n"; if ($contact->getCompany() instanceof Company) { $vcard .= "ORG:" . $contact->getCompany()->getName() . "\n"; } if ($contact->getJobTitle()) { $vcard .= "TITLE:" . $contact->getJobTitle() . "\n"; } if ($contact->getOBirthday() instanceof DateTimeValue) { $vcard .= "BDAY:" . $contact->getOBirthday()->format("Y-m-d") . "\n"; } if ($contact->getHAddress()) { $vcard .= "ADR;TYPE=HOME:;;" . $contact->getHAddress() . ";" . $contact->getHCity() . ";" . $contact->getHState() . ";" . $contact->getHZipcode() . ";" . $contact->getHCountryName() . "\n"; } if ($contact->getWAddress()) { $vcard .= "ADR;TYPE=WORK:;;" . $contact->getWAddress() . ";" . $contact->getWCity() . ";" . $contact->getWState() . ";" . $contact->getWZipcode() . ";" . $contact->getWCountryName() . "\n"; } if ($contact->getOAddress()) { $vcard .= "ADR;TYPE=INTL:;;" . $contact->getOAddress() . ";" . $contact->getOCity() . ";" . $contact->getOState() . ";" . $contact->getOZipcode() . ";" . $contact->getOCountryName() . "\n"; } if ($contact->getHPhoneNumber()) { $vcard .= "TEL;TYPE=HOME,VOICE:" . $contact->getHPhoneNumber() . "\n"; } if ($contact->getWPhoneNumber()) { $vcard .= "TEL;TYPE=WORK,VOICE:" . $contact->getWPhoneNumber() . "\n"; } if ($contact->getOPhoneNumber()) { $vcard .= "TEL;TYPE=VOICE:" . $contact->getOPhoneNumber() . "\n"; } if ($contact->getHFaxNumber()) { $vcard .= "TEL;TYPE=HOME,FAX:" . $contact->getHFaxNumber() . "\n"; } if ($contact->getWFaxNumber()) { $vcard .= "TEL;TYPE=WORK,FAX:" . $contact->getWFaxNumber() . "\n"; } if ($contact->getOFaxNumber()) { $vcard .= "TEL;TYPE=FAX:" . $contact->getOFaxNumber() . "\n"; } if ($contact->getHMobileNumber()) { $vcard .= "TEL;TYPE=CELL,VOICE:" . $contact->getHMobileNumber() . "\n"; } if ($contact->getHWebPage()) { $vcard .= "URL;TYPE=HOME:" . $contact->getHWebPage() . "\n"; } if ($contact->getWWebPage()) { $vcard .= "URL;TYPE=WORK:" . $contact->getWWebPage() . "\n"; } if ($contact->getOWebPage()) { $vcard .= "URL:" . $contact->getOWebPage() . "\n"; } if ($contact->getEmail()) { $vcard .= "EMAIL;TYPE=PREF,INTERNET:" . $contact->getEmail() . "\n"; } if ($contact->getEmail2()) { $vcard .= "EMAIL;TYPE=INTERNET:" . $contact->getEmail2() . "\n"; } if ($contact->getEmail3()) { $vcard .= "EMAIL;TYPE=INTERNET:" . $contact->getEmail3() . "\n"; } if ($contact->getNotes()) { $vcard .= "NOTE:" . $contact->getNotes() . "\n"; } if ($contact->hasPicture()) { $data = FileRepository::getFileContent($contact->getPictureFile()); $chunklen = 62; $pre = "PHOTO;ENCODING=BASE64;TYPE=PNG:"; $b64 = base64_encode($data); $enc_data = substr($b64, 0, $chunklen + 1 - strlen($pre)) . "\n "; $enc_data .= chunk_split(substr($b64, $chunklen + 1 - strlen($pre)), $chunklen, "\n "); $vcard .= $pre . $enc_data . "\n"; } $vcard .= "END:VCARD\n"; } return $vcard; }