function hasMailAccounts(){ if (Plugins::instance()->isActivePlugin('mail')) { if(is_null($this->mail_accounts)) $this->mail_accounts = MailAccounts::getMailAccountsByUser(logged_user()); return is_array($this->mail_accounts) && count($this->mail_accounts) > 0; } return false; }
/** * Gets the owner mail account * * @return MailAccount */ function getAccount() { if (is_null($this->account)) { $this->account = MailAccounts::findById($this->getAccountId()); } //if return $this->account; }
function getAccountById($account_id) { if(isset($this) && instance_of($this, 'MailAccounts')) { if (!isset($this->accounts_cache[$account_id])) { $this->accounts_cache[$account_id] = $this->findById($account_id); } return array_var($this->accounts_cache, $account_id); } else { return MailAccounts::instance()->getAccountById($account_id); } }
/** * Return Mail accounts by user * * @param user * @return array */ function getMailAccountsByUser(Contact $user) { return MailAccounts::findAll(array("conditions" => "contact_id = " . logged_user()->getId())); /*$accounts = array(); $accountUsers = MailAccountContacts::getByContact($user); foreach ($accountUsers as $au) { $account = $au->getAccount(); if ($account instanceof MailAccount) { $accounts[] = $account; } } return $accounts;*/ }
function mail_on_page_load() { //check if have outbox mails $usu = logged_user(); $accounts = MailAccounts::instance()->getMailAccountsByUser($usu); $account_ids = array(); foreach ($accounts as $acc) { $account_ids[] = $acc->getId(); } if (count($account_ids) == 0) { return; } $accounts_sql = " AND account_id IN (" . implode(',', $account_ids) . ")"; $user_pg_ids = $usu->getPermissionGroupIds(); if (count($user_pg_ids) == 0) { return; } $permissions_sql = " AND EXISTS (SELECT sh.group_id FROM " . TABLE_PREFIX . "sharing_table sh WHERE sh.object_id=o.id AND sh.group_id IN (" . implode(',', $user_pg_ids) . "))"; $conditions = array("conditions" => array("`state` >= 200 AND (`state`%2 = 0) AND `archived_on`=0 AND `trashed_on`=0 {$accounts_sql} {$permissions_sql} AND `created_by_id` =" . $usu->getId())); $outbox_mails = MailContents::findAll($conditions); if ($outbox_mails != null) { if (count($outbox_mails) >= 1) { $arguments = array("conditions" => array("`context` LIKE 'mails_in_outbox%' AND `contact_id` = " . $usu->getId() . ";")); $exist_reminder = ObjectReminders::find($arguments); if (!(count($exist_reminder) > 0)) { $reminder = new ObjectReminder(); $minutes = 0; $reminder->setMinutesBefore($minutes); $reminder->setType("reminder_popup"); $reminder->setContext("mails_in_outbox " . count($outbox_mails)); $reminder->setObject($usu); $reminder->setUserId($usu->getId()); $reminder->setDate(DateTimeValueLib::now()); $reminder->save(); } } } }
else{ $email_address = array_var($_GET, 'email'); $user_name = array_var($_GET, 'username'); if (isset ($email_address) && isset ($user_name)){ $user_conditions = array("conditions" => array("`username`='".$user_name."'")); $user = Users::findOne($user_conditions); if (!isset ($user)){ echo(lang('cant find user')); ?><br><a href="<?php echo ROOT_URL?>/index.php?c=access&a=index" target="_top">Go back to Feng Office</a><?php return; } $account_conditions = array("conditions" => array("`email_addr`='".$email_address."' AND `user_id`='".$user->getId()."'")); $account = MailAccounts::findOne($account_conditions); if (!isset ($account)){ echo(lang('cant find account')); ?><br><a href="<?php echo ROOT_URL?>/index.php?c=access&a=index" target="_top">Go back to Feng Office</a><?php return; } } } if(!($account instanceof MailAccount)) { echo(lang('mailAccount dnx')); return; } $pass = $account->getSyncPass(); $server = $account->getSyncServer();
function mail_accounts() { if (!can_manage_security(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } if (Plugins::instance()->isActivePlugin('mail')) { //$my_accounts = MailAccounts::getMailAccountsByUser(logged_user()); $all_accounts = MailAccounts::findAll(); } //tpl_assign('my_accounts', $my_accounts); tpl_assign('all_accounts', $all_accounts); }
function deleteMailsFromServerAllAccounts() { $accounts = MailAccounts::findAll(); $count = 0; foreach ($accounts as $account) { try { $count += self::deleteMailsFromServer($account); } catch (Exception $e) { Logger::log($e->getMessage()); } } return $count; }
/** * Edit email * * @param void * @return null */ function edit_mail() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $this->setTemplate('add_mail'); if (array_var($_GET, 'id', '') == '') { flash_error('Invalid parameter.'); ajx_current("empty"); } $original_mail = MailContents::findById(get_id('id', $_GET)); if (!$original_mail) { flash_error('Invalid parameter.'); ajx_current("empty"); } $mail_accounts = MailAccounts::getMailAccountsByUser(logged_user()); if (count($mail_accounts) < 1) { flash_error(lang('no mail accounts set')); ajx_current("empty"); return; } $mail_data = array_var($_POST, 'mail', null); if (!is_array($mail_data)) { $body = $original_mail->getBodyHtml() == '' ? $original_mail->getBodyPlain() : $original_mail->getBodyHtml(); //Attachs $attachs = array(); if ($original_mail->getHasAttachments()) { $attachments = self::readAttachmentsFromFileSystem($original_mail, $att_version); foreach ($attachments as $att) { $fName = $att["name"]; $fileType = $att["type"]; $fid = gen_id(); $attachs[] = "FwdMailAttach:{$fName}:{$fileType}:{$fid}"; if ($att_version >= 2) { @copy($att['path'], ROOT . "/tmp/" . logged_user()->getId() . "_" . $original_mail->getAccountId() . "_FwdMailAttach_{$fid}"); } else { file_put_contents(ROOT . "/tmp/" . logged_user()->getId() . "_" . $original_mail->getAccountId() . "_FwdMailAttach_{$fid}", $att['data']); } } } $mail_data = array('to' => $original_mail->getTo(), 'cc' => $original_mail->getCc(), 'bcc' => $original_mail->getBcc(), 'subject' => $original_mail->getSubject(), 'body' => $body, 'type' => $original_mail->getBodyHtml() != '' ? 'html' : 'plain', 'account_id' => $original_mail->getAccountId(), 'conversation_id' => $original_mail->getConversationId(), 'in_reply_to_id' => $original_mail->getMessageId(), 'original_id' => $original_mail->getId(), 'last_mail_in_conversation' => MailContents::getLastMailIdInConversation($original_mail->getConversationId(), true), 'id' => $original_mail->getId(), 'draft_edit' => 1, 'attachs' => $attachs); // array } // if tpl_assign('mail', $original_mail); tpl_assign('mail_data', $mail_data); tpl_assign('mail_accounts', $mail_accounts); }
/** * Return true is $user has $access_level (R/W) over $object * * @param User $user * @param ApplicationDataObject $object * @param int $access_level // 1 = read ; 2 = write * @return unknown */ function can_access(User $user, ApplicationDataObject $object, $access_level) { try { if (!$object instanceof ApplicationDataObject) { throw new Exception(lang('object dnx')); } $hookargs = array("user" => $user, "object" => $object, "access_level" => $access_level); $ret = null; Hook::fire('can_access', $hookargs, $ret); if (is_bool($ret)) { return $ret; } if ($object instanceof Comment) { return can_access($user, $object->getObject(), $access_level); } if ($user->isGuest() && $access_level == ACCESS_LEVEL_WRITE) { return false; } if ($object instanceof ProjectFileRevision) { return can_access($user, $object->getFile(), $access_level); } if ($object->columnExists('project_id')) { $user_id = $user->getId(); if (!$object instanceof ProjectContact && $object->getCreatedById() == $user_id) { return true; } // the user is the creator of the object if ($object instanceof ProjectDataObject && $object->getProject() instanceof Project && $object->getProject()->getId() == $user->getPersonalProjectId()) { return true; } // The object belongs to the user's personal project $perms = ObjectUserPermissions::getAllPermissionsByObject($object, $user->getId()); if ($perms && is_array($perms)) { //if the permissions for the user in the object are specially set return has_access_level($perms[0], $access_level); } $group_ids = GroupUsers::getGroupsCSVsByUser($user_id); if ($group_ids && $group_ids != '') { //user belongs to at least one group $perms = ObjectUserPermissions::getAllPermissionsByObject($object, $group_ids); if ($perms) { foreach ($perms as $perm) { if (has_access_level($perm, $access_level)) { return true; } //there is one group permission that allows the user to access } } } if ($object instanceof ProjectDataObject && $object->getProject()) { //if the object has a project assigned to it $proj_perm = ProjectUsers::findOne(array('conditions' => array('user_id = ? AND project_id = ? ', $user_id, $object->getProject()->getId()))); if ($proj_perm && can_manage_type(get_class($object->manager()), $proj_perm, $access_level)) { return true; // if user has permissions over type of object in the project } if ($group_ids && $group_ids != '') { //user belongs to at least one group $proj_perms = ProjectUsers::findAll(array('conditions' => array('project_id = ' . $object->getProject()->getId() . ' AND user_id in (' . $group_ids . ')'))); if ($proj_perms) { foreach ($proj_perms as $perm) { if (can_manage_type(get_class($object->manager()), $perm, $access_level)) { return true; } // if any group has permissions over type of object in the project } } } } } else { // handle object in multiple workspaces $user_id = $user->getId(); if ($object->getCreatedById() == $user_id) { return true; // the user is the creator of the object } if ($object instanceof MailContent) { $acc = MailAccounts::findById($object->getAccountId()); if (!$acc instanceof MailAccount) { return false; // it's an email with no account and not created by the user } else { if ($access_level == ACCESS_LEVEL_READ && $acc->canView($user) || $access_level == ACCESS_LEVEL_WRITE && $acc->canDelete($user)) { return true; } } } $perms = ObjectUserPermissions::getAllPermissionsByObject($object, $user->getId()); if ($perms && is_array($perms)) { //if the permissions for the user in the object are specially set return has_access_level($perms[0], $access_level); } $group_ids = GroupUsers::getGroupsCSVsByUser($user_id); if ($group_ids && $group_ids != '') { //user belongs to at least one group $perms = ObjectUserPermissions::getAllPermissionsByObject($object, $group_ids); if ($perms) { foreach ($perms as $perm) { if (has_access_level($perm, $access_level)) { return true; //there is one group permission that allows the user to access } } } } if ($object instanceof ProjectDataObject) { $ws = $object->getWorkspaces(); foreach ($ws as $w) { // if the object has a project assigned to it $proj_perm = ProjectUsers::findOne(array('conditions' => array('user_id = ? AND project_id = ? ', $user_id, $w->getId()))); if ($proj_perm && can_manage_type(get_class($object->manager()), $proj_perm, $access_level)) { return true; // if user has permissions over type of object in the project } if ($group_ids && $group_ids != '') { //user belongs to at least one group $proj_perms = ProjectUsers::findAll(array('conditions' => array('project_id = ' . $w->getId() . ' AND user_id in (' . $group_ids . ')'))); if ($proj_perms) { foreach ($proj_perms as $perm) { if (can_manage_type(get_class($object->manager()), $perm, $access_level)) { return true; } // if any group has permissions over type of object in the project } } } } } } } catch (Exception $e) { tpl_assign('error', $e); return false; } return false; }
function getAccount() { return MailAccounts::findById($this->getAccountId()); }
/** * Return manager instance * * @access protected * @param void * @return MailAccounts */ function manager() { if(!($this->manager instanceof MailAccounts)) $this->manager = MailAccounts::instance(); return $this->manager; } // manager
echo $genid; ?> ')"> <?php echo lang("fetch imap folders"); ?> </a> </th> </tr> </table> <div class="mail-account-item"> <?php $options = array(); if (isset($mail_acc_id) && config_option('sent_mails_sync')) { $mail_acc = MailAccounts::findById($mail_acc_id); $selected_folder = $mail_acc->getSyncFolder(); } foreach ($imap_folders as $folder) { if (isset($selected_folder) && $folder->getFolderName() == $selected_folder) { $options[] = option_tag($folder->getFolderName(), null, array('selected' => "selected")); } else { $options[] = option_tag($folder->getFolderName(), null, null); } } $outbox_select_box_attrib = array('id' => $genid . 'outbox_select_box'); echo select_box('outbox_select_box', $options, $outbox_select_box_attrib); ?> </div>
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'MailAccounts')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return MailAccounts::instance()->paginate($arguments, $items_per_page, $current_page); //$instance =& MailAccounts::instance(); //return $instance->paginate($arguments, $items_per_page, $current_page); } // if }
function hasMailAccounts() { if (is_null($this->mail_accounts)) { $this->mail_accounts = MailAccounts::getMailAccountsByUser(logged_user()); } return is_array($this->mail_accounts) && count($this->mail_accounts) > 0; }
static function prepareTrashAndArchivedConditions($trashed, $archived) { $trashed_cond = "`o`.`trashed_on` " . ($trashed ? ">" : "=") . " " . DB::escape(EMPTY_DATETIME); if ($trashed) { $archived_cond = ""; } else { $archived_cond = "AND `o`.`archived_on` " . ($archived ? ">" : "=") . " " . DB::escape(EMPTY_DATETIME); } if ($trashed && Plugins::instance()->isActivePlugin('mail')) { $mail_accounts = MailAccounts::getMailAccountsByUser(logged_user()); $mail_account_ids = array(); foreach ($mail_accounts as $account) { $mail_account_ids[] = $account->getId(); } $mcot_id = MailContents::instance()->getObjectTypeId(); if (empty($mail_account_ids)) { $trashed_cond .= " AND IF(o.object_type_id={$mcot_id}, 0, 1)"; } else { $trashed_cond .= " AND IF(o.object_type_id={$mcot_id}, NOT (SELECT mcx.is_deleted FROM " . TABLE_PREFIX . "mail_contents mcx WHERE mcx.object_id=o.id) AND EXISTS (SELECT mct.object_id FROM " . TABLE_PREFIX . "mail_contents mct WHERE mct.object_id=o.id AND mct.account_id IN(" . implode(',', $mail_account_ids) . ")), 1)"; } } return array($trashed_cond, $archived_cond); }
/** * Return manager instance * * @access protected * @param void * @return MailAccounts */ function manager() { if (!$this->manager instanceof MailAccounts) { $this->manager = MailAccounts::instance(); } return $this->manager; }
; og.emailFilters = {}; og.emailFilters.classif = '<?php echo user_config_option('mails classification filter'); ?> '; og.emailFilters.read = '<?php echo user_config_option('mails read filter'); ?> '; og.emailFilters.account = '<?php echo user_config_option('mails account filter'); ?> '; if (og.emailFilters.account != 0 && og.emailFilters.account != '') { og.emailFilters.accountName = '<?php $acc_id = user_config_option('mails account filter'); $acc = $acc_id > 0 ? MailAccounts::findById($acc_id) : null; echo $acc instanceof MailAccount ? mysql_real_escape_string($acc->getName()) : ''; ?> '; } else og.emailFilters.accountName = ''; og.lastSelectedRow = {messages:0, mails:0, contacts:0, documents:0, weblinks:0, overview:0, linkedobjs:0, archived:0}; </script> <?php include_once Env::getLayoutPath("listeners"); ?> </body> </html>