adamjakab /
SuiteCRM
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
||
| 3 | /********************************************************************************* |
||
| 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
||
| 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
||
| 6 | |||
| 7 | * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
||
| 8 | * Copyright (C) 2011 - 2014 Salesagility Ltd. |
||
| 9 | * |
||
| 10 | * This program is free software; you can redistribute it and/or modify it under |
||
| 11 | * the terms of the GNU Affero General Public License version 3 as published by the |
||
| 12 | * Free Software Foundation with the addition of the following permission added |
||
| 13 | * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
||
| 14 | * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
||
| 15 | * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
||
| 16 | * |
||
| 17 | * This program is distributed in the hope that it will be useful, but WITHOUT |
||
| 18 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
||
| 19 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
||
| 20 | * details. |
||
| 21 | * |
||
| 22 | * You should have received a copy of the GNU Affero General Public License along with |
||
| 23 | * this program; if not, see http://www.gnu.org/licenses or write to the Free |
||
| 24 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
||
| 25 | * 02110-1301 USA. |
||
| 26 | * |
||
| 27 | * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
||
| 28 | * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
||
| 29 | * |
||
| 30 | * The interactive user interfaces in modified source and object code versions |
||
| 31 | * of this program must display Appropriate Legal Notices, as required under |
||
| 32 | * Section 5 of the GNU Affero General Public License version 3. |
||
| 33 | * |
||
| 34 | * In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
||
| 35 | * these Appropriate Legal Notices must retain the display of the "Powered by |
||
| 36 | * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
||
| 37 | * reasonably feasible for technical reasons, the Appropriate Legal Notices must |
||
| 38 | * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
||
| 39 | ********************************************************************************/ |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Outbuound email management |
||
| 43 | * @api |
||
| 44 | */ |
||
| 45 | class OutboundEmail { |
||
| 46 | /** |
||
| 47 | * Necessary |
||
| 48 | */ |
||
| 49 | var $db; |
||
| 50 | var $field_defs = array( |
||
| 51 | 'id', |
||
| 52 | 'name', |
||
| 53 | 'type', |
||
| 54 | 'user_id', |
||
| 55 | 'mail_sendtype', |
||
| 56 | 'mail_smtptype', |
||
| 57 | 'mail_smtpserver', |
||
| 58 | 'mail_smtpport', |
||
| 59 | 'mail_smtpuser', |
||
| 60 | 'mail_smtppass', |
||
| 61 | 'mail_smtpauth_req', |
||
| 62 | 'mail_smtpssl', |
||
| 63 | ); |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Columns |
||
| 67 | */ |
||
| 68 | var $id; |
||
| 69 | var $name; |
||
| 70 | var $type; // user or system |
||
| 71 | var $user_id; // owner |
||
| 72 | var $mail_sendtype; // smtp |
||
| 73 | var $mail_smtptype; |
||
| 74 | var $mail_smtpserver; |
||
| 75 | var $mail_smtpport = 25; |
||
| 76 | var $mail_smtpuser; |
||
| 77 | var $mail_smtppass; |
||
| 78 | var $mail_smtpauth_req; // bool |
||
| 79 | var $mail_smtpssl; // bool |
||
| 80 | var $mail_smtpdisplay; // calculated value, not in DB |
||
| 81 | var $new_with_id = FALSE; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Sole constructor |
||
| 85 | */ |
||
| 86 | 56 | public function __construct() { |
|
| 87 | 56 | $this->db = DBManagerFactory::getInstance(); |
|
| 88 | 56 | } |
|
| 89 | |||
| 90 | /** |
||
| 91 | * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead |
||
| 92 | */ |
||
| 93 | public function OutboundEmail(){ |
||
| 94 | $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code'; |
||
| 95 | if(isset($GLOBALS['log'])) { |
||
| 96 | $GLOBALS['log']->deprecated($deprecatedMessage); |
||
| 97 | } |
||
| 98 | else { |
||
| 99 | trigger_error($deprecatedMessage, E_USER_DEPRECATED); |
||
| 100 | } |
||
| 101 | self::__construct(); |
||
| 102 | } |
||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * Retrieves the mailer for a user if they have overriden the username |
||
| 107 | * and password for the default system account. |
||
| 108 | * |
||
| 109 | * @param String $user_id |
||
| 110 | */ |
||
| 111 | function getUsersMailerForSystemOverride($user_id) |
||
| 112 | { |
||
| 113 | $query = "SELECT id FROM outbound_email WHERE user_id = '{$user_id}' AND type = 'system-override' ORDER BY name"; |
||
| 114 | $rs = $this->db->query($query); |
||
| 115 | $row = $this->db->fetchByAssoc($rs); |
||
| 116 | if(!empty($row['id'])) |
||
| 117 | { |
||
| 118 | $oe = new OutboundEmail(); |
||
| 119 | $oe->retrieve($row['id']); |
||
| 120 | return $oe; |
||
| 121 | } |
||
| 122 | else |
||
| 123 | return null; |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Duplicate the system account for a user, setting new parameters specific to the user. |
||
| 128 | * |
||
| 129 | * @param string $user_id |
||
| 130 | * @param string $user_name |
||
| 131 | * @param string $user_pass |
||
| 132 | */ |
||
| 133 | function createUserSystemOverrideAccount($user_id,$user_name = "",$user_pass = "") |
||
| 134 | { |
||
| 135 | $ob = $this->getSystemMailerSettings(); |
||
| 136 | $ob->id = create_guid(); |
||
| 137 | $ob->new_with_id = TRUE; |
||
| 138 | $ob->user_id = $user_id; |
||
| 139 | $ob->type = 'system-override'; |
||
| 140 | $ob->mail_smtpuser = $user_name; |
||
| 141 | $ob->mail_smtppass = $user_pass; |
||
| 142 | $ob->save(); |
||
| 143 | |||
| 144 | return $ob; |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Determines if a user needs to set their user name/password for their system |
||
| 149 | * override account. |
||
| 150 | * |
||
| 151 | * @param unknown_type $user_id |
||
| 152 | * @return unknown |
||
| 153 | */ |
||
| 154 | function doesUserOverrideAccountRequireCredentials($user_id) |
||
| 155 | { |
||
| 156 | $userCredentialsReq = FALSE; |
||
| 157 | $sys = new OutboundEmail(); |
||
| 158 | $ob = $sys->getSystemMailerSettings(); //Dirties '$this' |
||
| 159 | |||
| 160 | //If auth for system account is disabled or user can use system outbound account return false. |
||
| 161 | if($ob->mail_smtpauth_req == 0 || $this->isAllowUserAccessToSystemDefaultOutbound() || $this->mail_sendtype == 'sendmail') |
||
| 162 | return $userCredentialsReq; |
||
| 163 | |||
| 164 | $userOverideAccount = $this->getUsersMailerForSystemOverride($user_id); |
||
| 165 | if( $userOverideAccount == null || empty($userOverideAccount->mail_smtpuser) || empty($userOverideAccount->mail_smtpuser) ) |
||
| 166 | $userCredentialsReq = TRUE; |
||
| 167 | |||
| 168 | return $userCredentialsReq; |
||
| 169 | |||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Retrieves name value pairs for opts lists |
||
| 174 | */ |
||
| 175 | function getUserMailers($user) { |
||
| 176 | global $app_strings; |
||
| 177 | |||
| 178 | $q = "SELECT * FROM outbound_email WHERE user_id = '{$user->id}' AND type = 'user' ORDER BY name"; |
||
| 179 | $r = $this->db->query($q); |
||
| 180 | |||
| 181 | $ret = array(); |
||
| 182 | |||
| 183 | $system = $this->getSystemMailerSettings(); |
||
| 184 | |||
| 185 | //Now add the system default or user override default to the response. |
||
| 186 | if(!empty($system->id) ) |
||
| 187 | { |
||
| 188 | if ($system->mail_sendtype == 'SMTP') |
||
| 189 | { |
||
| 190 | $systemErrors = ""; |
||
| 191 | $userSystemOverride = $this->getUsersMailerForSystemOverride($user->id); |
||
| 192 | |||
| 193 | //If the user is required to to provide a username and password but they have not done so yet, |
||
| 194 | //create the account for them. |
||
| 195 | $autoCreateUserSystemOverride = FALSE; |
||
| 196 | if( $this->doesUserOverrideAccountRequireCredentials($user->id) ) |
||
| 197 | { |
||
| 198 | $systemErrors = $app_strings['LBL_EMAIL_WARNING_MISSING_USER_CREDS']; |
||
| 199 | $autoCreateUserSystemOverride = TRUE; |
||
| 200 | } |
||
| 201 | |||
| 202 | //Substitute in the users system override if its available. |
||
| 203 | if($userSystemOverride != null) |
||
| 204 | $system = $userSystemOverride; |
||
| 205 | else if ($autoCreateUserSystemOverride) |
||
| 206 | $system = $this->createUserSystemOverrideAccount($user->id,"",""); |
||
| 207 | |||
| 208 | $isEditable = ($system->type == 'system') ? FALSE : TRUE; //User overrides can be edited. |
||
| 209 | |||
| 210 | if( !empty($system->mail_smtpserver) ) |
||
| 211 | $ret[] = array('id' =>$system->id, 'name' => "$system->name", 'mail_smtpserver' => $system->mail_smtpdisplay, |
||
| 212 | 'is_editable' => $isEditable, 'type' => $system->type, 'errors' => $systemErrors); |
||
| 213 | } |
||
| 214 | else //Sendmail |
||
| 215 | { |
||
| 216 | $ret[] = array('id' =>$system->id, 'name' => "{$system->name} - sendmail", 'mail_smtpserver' => 'sendmail', |
||
| 217 | 'is_editable' => false, 'type' => $system->type, 'errors' => ''); |
||
| 218 | } |
||
| 219 | } |
||
| 220 | |||
| 221 | while($a = $this->db->fetchByAssoc($r)) |
||
| 222 | { |
||
| 223 | $oe = array(); |
||
| 224 | if($a['mail_sendtype'] != 'SMTP') |
||
| 225 | continue; |
||
| 226 | |||
| 227 | $oe['id'] =$a['id']; |
||
| 228 | $oe['name'] = $a['name']; |
||
| 229 | $oe['type'] = $a['type']; |
||
| 230 | $oe['is_editable'] = true; |
||
| 231 | $oe['errors'] = ''; |
||
| 232 | if ( !empty($a['mail_smtptype']) ) |
||
| 233 | $oe['mail_smtpserver'] = $this->_getOutboundServerDisplay($a['mail_smtptype'],$a['mail_smtpserver']); |
||
| 234 | else |
||
| 235 | $oe['mail_smtpserver'] = $a['mail_smtpserver']; |
||
| 236 | |||
| 237 | $ret[] = $oe; |
||
| 238 | } |
||
| 239 | |||
| 240 | return $ret; |
||
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Retrieves a cascading mailer set |
||
| 245 | * @param object user |
||
| 246 | * @param string mailer_id |
||
| 247 | * @return object |
||
| 248 | */ |
||
| 249 | 6 | function getUserMailerSettings(&$user, $mailer_id='', $ieId='') { |
|
| 250 | 6 | $mailer = ''; |
|
| 251 | |||
| 252 | 6 | if(!empty($mailer_id)) { |
|
| 253 | $mailer = "AND id = '{$mailer_id}'"; |
||
| 254 | 6 | } elseif(!empty($ieId)) { |
|
| 255 | $q = "SELECT stored_options FROM inbound_email WHERE id = '{$ieId}'"; |
||
| 256 | $r = $this->db->query($q); |
||
| 257 | $a = $this->db->fetchByAssoc($r); |
||
| 258 | |||
| 259 | if(!empty($a)) { |
||
| 260 | $opts = unserialize(base64_decode($a['stored_options'])); |
||
| 261 | |||
| 262 | if(isset($opts['outbound_email'])) { |
||
| 263 | $mailer = "AND id = '{$opts['outbound_email']}'"; |
||
| 264 | } |
||
| 265 | } |
||
| 266 | } |
||
| 267 | |||
| 268 | 6 | $q = "SELECT id FROM outbound_email WHERE user_id = '{$user->id}' {$mailer}"; |
|
| 269 | 6 | $r = $this->db->query($q); |
|
| 270 | 6 | $a = $this->db->fetchByAssoc($r); |
|
| 271 | |||
| 272 | 6 | if(empty($a)) { |
|
| 273 | 6 | $ret = $this->getSystemMailerSettings(); |
|
| 274 | } else { |
||
| 275 | $ret = $this->retrieve($a['id']); |
||
| 276 | } |
||
| 277 | 6 | return $ret; |
|
| 278 | } |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Retrieve an array containing inbound emails ids for all inbound email accounts which have |
||
| 282 | * their outbound account set to this object. |
||
| 283 | * |
||
| 284 | * @param SugarBean $user |
||
| 285 | * @param string $outbound_id |
||
|
0 ignored issues
–
show
|
|||
| 286 | * @return array |
||
| 287 | */ |
||
| 288 | function getAssociatedInboundAccounts($user) |
||
| 289 | { |
||
| 290 | $query = "SELECT id,stored_options FROM inbound_email WHERE is_personal='1' AND deleted='0' AND created_by = '{$user->id}'"; |
||
| 291 | $rs = $this->db->query($query); |
||
| 292 | |||
| 293 | $results = array(); |
||
| 294 | while($row = $this->db->fetchByAssoc($rs) ) |
||
| 295 | { |
||
| 296 | $opts = unserialize(base64_decode($row['stored_options'])); |
||
| 297 | if( isset($opts['outbound_email']) && $opts['outbound_email'] == $this->id) |
||
| 298 | { |
||
| 299 | $results[] = $row['id']; |
||
| 300 | } |
||
| 301 | } |
||
| 302 | |||
| 303 | return $results; |
||
| 304 | } |
||
| 305 | /** |
||
| 306 | * Retrieves a cascading mailer set |
||
| 307 | * @param object user |
||
| 308 | * @param string mailer_id |
||
| 309 | * @return object |
||
| 310 | */ |
||
| 311 | 2 | function getInboundMailerSettings($user, $mailer_id='', $ieId='') { |
|
| 312 | 2 | $mailer = ''; |
|
| 313 | |||
| 314 | 2 | if(!empty($mailer_id)) { |
|
| 315 | $mailer = "id = '{$mailer_id}'"; |
||
| 316 | 2 | } elseif(!empty($ieId)) { |
|
| 317 | $q = "SELECT stored_options FROM inbound_email WHERE id = '{$ieId}'"; |
||
| 318 | $r = $this->db->query($q); |
||
| 319 | $a = $this->db->fetchByAssoc($r); |
||
| 320 | |||
| 321 | if(!empty($a)) { |
||
| 322 | $opts = unserialize(base64_decode($a['stored_options'])); |
||
| 323 | |||
| 324 | if(isset($opts['outbound_email'])) { |
||
| 325 | $mailer = "id = '{$opts['outbound_email']}'"; |
||
| 326 | } else { |
||
| 327 | $mailer = "id = '{$ieId}'"; |
||
| 328 | } |
||
| 329 | } else { |
||
| 330 | // its possible that its an system account |
||
| 331 | $mailer = "id = '{$ieId}'"; |
||
| 332 | } |
||
| 333 | } |
||
| 334 | |||
| 335 | 2 | if (empty($mailer)) { |
|
| 336 | 2 | $mailer = "type = 'system'"; |
|
| 337 | } // if |
||
| 338 | |||
| 339 | 2 | $q = "SELECT id FROM outbound_email WHERE {$mailer}"; |
|
| 340 | 2 | $r = $this->db->query($q); |
|
| 341 | 2 | $a = $this->db->fetchByAssoc($r); |
|
| 342 | |||
| 343 | 2 | if(empty($a)) { |
|
| 344 | $ret = $this->getSystemMailerSettings(); |
||
| 345 | } else { |
||
| 346 | 2 | $ret = $this->retrieve($a['id']); |
|
| 347 | } |
||
| 348 | 2 | return $ret; |
|
| 349 | } |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Determine if the user is allowed to use the current system outbound connection. |
||
| 353 | */ |
||
| 354 | function isAllowUserAccessToSystemDefaultOutbound() |
||
| 355 | { |
||
| 356 | $allowAccess = FALSE; |
||
| 357 | |||
| 358 | // first check that a system default exists |
||
| 359 | $q = "SELECT id FROM outbound_email WHERE type = 'system'"; |
||
| 360 | $r = $this->db->query($q); |
||
| 361 | $a = $this->db->fetchByAssoc($r); |
||
| 362 | if (!empty($a)) { |
||
| 363 | // next see if the admin preference for using the system outbound is set |
||
| 364 | $admin = new Administration(); |
||
| 365 | $admin->retrieveSettings('',TRUE); |
||
| 366 | if (isset($admin->settings['notify_allow_default_outbound']) |
||
| 367 | && $admin->settings['notify_allow_default_outbound'] == 2 ) |
||
| 368 | $allowAccess = TRUE; |
||
| 369 | } |
||
| 370 | |||
| 371 | return $allowAccess; |
||
| 372 | } |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Retrieves the system's Outbound options |
||
| 376 | */ |
||
| 377 | 56 | function getSystemMailerSettings() { |
|
| 378 | 56 | $q = "SELECT id FROM outbound_email WHERE type = 'system'"; |
|
| 379 | 56 | $r = $this->db->query($q); |
|
| 380 | 56 | $a = $this->db->fetchByAssoc($r); |
|
| 381 | |||
| 382 | 56 | if(empty($a)) { |
|
| 383 | $this->id = ""; |
||
| 384 | $this->name = 'system'; |
||
| 385 | $this->type = 'system'; |
||
| 386 | $this->user_id = '1'; |
||
| 387 | $this->mail_sendtype = 'SMTP'; |
||
| 388 | $this->mail_smtptype = 'other'; |
||
| 389 | $this->mail_smtpserver = ''; |
||
| 390 | $this->mail_smtpport = 25; |
||
| 391 | $this->mail_smtpuser = ''; |
||
| 392 | $this->mail_smtppass = ''; |
||
| 393 | $this->mail_smtpauth_req = 1; |
||
| 394 | $this->mail_smtpssl = 0; |
||
| 395 | $this->mail_smtpdisplay = $this->_getOutboundServerDisplay($this->mail_smtptype,$this->mail_smtpserver); |
||
| 396 | $this->save(); |
||
| 397 | $ret = $this; |
||
| 398 | } else { |
||
| 399 | 56 | $ret = $this->retrieve($a['id']); |
|
| 400 | } |
||
| 401 | |||
| 402 | 56 | return $ret; |
|
| 403 | } |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Populates this instance |
||
| 407 | * @param string $id |
||
| 408 | * @return object $this |
||
| 409 | */ |
||
| 410 | 56 | function retrieve($id) { |
|
| 411 | 56 | require_once('include/utils/encryption_utils.php'); |
|
| 412 | 56 | $q = "SELECT * FROM outbound_email WHERE id = '{$id}'"; |
|
| 413 | 56 | $r = $this->db->query($q); |
|
| 414 | 56 | $a = $this->db->fetchByAssoc($r); |
|
| 415 | |||
| 416 | 56 | if(!empty($a)) { |
|
| 417 | 56 | foreach($a as $k => $v) { |
|
| 418 | 56 | if ($k == 'mail_smtppass' && !empty($v)) { |
|
| 419 | $this->$k = blowfishDecode(blowfishGetKey('OutBoundEmail'), $v); |
||
| 420 | } else { |
||
| 421 | 56 | $this->$k = $v; |
|
| 422 | } // else |
||
| 423 | } |
||
| 424 | 56 | if ( !empty($a['mail_smtptype']) ) |
|
| 425 | 56 | $this->mail_smtpdisplay = $this->_getOutboundServerDisplay($a['mail_smtptype'],$a['mail_smtpserver']); |
|
| 426 | else |
||
| 427 | $this->mail_smtpdisplay = $a['mail_smtpserver']; |
||
| 428 | } |
||
| 429 | |||
| 430 | 56 | return $this; |
|
| 431 | } |
||
| 432 | |||
| 433 | function populateFromPost() { |
||
| 434 | foreach($this->field_defs as $def) { |
||
| 435 | if(isset($_POST[$def])) { |
||
| 436 | $this->$def = $_POST[$def]; |
||
| 437 | } else if ($def != 'mail_smtppass') { |
||
| 438 | $this->$def = ""; |
||
| 439 | } |
||
| 440 | } |
||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Generate values for saving into outbound_emails table |
||
| 445 | * @param array $keys |
||
| 446 | * @return array |
||
| 447 | */ |
||
| 448 | protected function getValues(&$keys) |
||
| 449 | { |
||
| 450 | $values = array(); |
||
| 451 | $validKeys = array(); |
||
| 452 | |||
| 453 | foreach($keys as $def) { |
||
| 454 | if ($def == 'mail_smtppass' && !empty($this->$def)) { |
||
| 455 | $this->$def = blowfishEncode(blowfishGetKey('OutBoundEmail'), $this->$def); |
||
| 456 | } // if |
||
| 457 | if($def == 'mail_smtpauth_req' || $def == 'mail_smtpssl' || $def == 'mail_smtpport'){ |
||
| 458 | if(empty($this->$def)){ |
||
| 459 | $this->$def = 0; |
||
| 460 | } |
||
| 461 | $values[] = intval($this->$def); |
||
| 462 | $validKeys[] = $def; |
||
| 463 | } else if (isset($this->$def)) { |
||
| 464 | $values[] = $this->db->quoted($this->$def); |
||
| 465 | $validKeys[] = $def; |
||
| 466 | } |
||
| 467 | } |
||
| 468 | $keys = $validKeys; |
||
| 469 | return $values; |
||
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * saves an instance |
||
| 474 | */ |
||
| 475 | function save() { |
||
| 476 | require_once('include/utils/encryption_utils.php'); |
||
| 477 | if( empty($this->id) ) { |
||
| 478 | $this->id = create_guid(); |
||
| 479 | $this->new_with_id = true; |
||
| 480 | } |
||
| 481 | |||
| 482 | $cols = $this->field_defs; |
||
| 483 | $values = $this->getValues($cols); |
||
| 484 | |||
| 485 | if($this->new_with_id) { |
||
| 486 | $q = sprintf("INSERT INTO outbound_email (%s) VALUES (%s)", implode($cols, ","), implode($values, ",")); |
||
| 487 | } else { |
||
| 488 | $updvalues = array(); |
||
| 489 | foreach($values as $k => $val) { |
||
| 490 | $updvalues[] = "{$cols[$k]} = $val"; |
||
| 491 | } |
||
| 492 | $q = "UPDATE outbound_email SET ".implode(', ', $updvalues)." WHERE id = ".$this->db->quoted($this->id); |
||
| 493 | } |
||
| 494 | |||
| 495 | $this->db->query($q, true); |
||
| 496 | return $this; |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Saves system mailer. Presumes all values are filled. |
||
| 501 | */ |
||
| 502 | function saveSystem() { |
||
| 503 | $q = "SELECT id FROM outbound_email WHERE type = 'system'"; |
||
| 504 | $r = $this->db->query($q); |
||
| 505 | $a = $this->db->fetchByAssoc($r); |
||
| 506 | |||
| 507 | if(empty($a)) { |
||
| 508 | $a['id'] = ''; // trigger insert |
||
| 509 | } |
||
| 510 | |||
| 511 | $this->id = $a['id']; |
||
| 512 | $this->name = 'system'; |
||
| 513 | $this->type = 'system'; |
||
| 514 | $this->user_id = '1'; |
||
| 515 | $this->save(); |
||
| 516 | |||
| 517 | $this->updateUserSystemOverrideAccounts(); |
||
| 518 | |||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Update the user system override accounts with the system information if anything has changed. |
||
| 523 | * |
||
| 524 | */ |
||
| 525 | function updateUserSystemOverrideAccounts() |
||
| 526 | { |
||
| 527 | require_once('include/utils/encryption_utils.php'); |
||
| 528 | $updateFields = array('mail_smtptype','mail_sendtype','mail_smtpserver', 'mail_smtpport','mail_smtpauth_req','mail_smtpssl'); |
||
| 529 | |||
| 530 | //Update the username ans password for the override accounts if alloweed access. |
||
| 531 | if( $this->isAllowUserAccessToSystemDefaultOutbound() ) |
||
| 532 | { |
||
| 533 | $updateFields[] = 'mail_smtpuser'; |
||
| 534 | $updateFields[] = 'mail_smtppass'; |
||
| 535 | } |
||
| 536 | $values = $this->getValues($updateFields); |
||
| 537 | $updvalues = array(); |
||
| 538 | foreach($values as $k => $val) { |
||
| 539 | $updvalues[] = "{$updateFields[$k]} = $val"; |
||
| 540 | } |
||
| 541 | $query = "UPDATE outbound_email set ".implode(', ', $updvalues)." WHERE type='system-override' "; |
||
| 542 | |||
| 543 | $this->db->query($query); |
||
| 544 | } |
||
| 545 | /** |
||
| 546 | * Remove all of the user override accounts. |
||
| 547 | * |
||
| 548 | */ |
||
| 549 | function removeUserOverrideAccounts() |
||
| 550 | { |
||
| 551 | $query = "DELETE FROM outbound_email WHERE type = 'system-override'"; |
||
| 552 | return $this->db->query($query); |
||
| 553 | } |
||
| 554 | /** |
||
| 555 | * Deletes an instance |
||
| 556 | */ |
||
| 557 | function delete() { |
||
| 558 | if(empty($this->id)) { |
||
| 559 | return false; |
||
| 560 | } |
||
| 561 | |||
| 562 | $q = "DELETE FROM outbound_email WHERE id = ".$this->db->quoted($this->id); |
||
| 563 | return $this->db->query($q); |
||
| 564 | } |
||
| 565 | |||
| 566 | 56 | private function _getOutboundServerDisplay( |
|
| 567 | $smtptype, |
||
| 568 | $smtpserver |
||
| 569 | ) |
||
| 570 | { |
||
| 571 | 56 | global $app_strings; |
|
| 572 | |||
| 573 | switch ($smtptype) { |
||
| 574 | 56 | case "yahoomail": |
|
| 575 | return $app_strings['LBL_SMTPTYPE_YAHOO']; break; |
||
|
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. Loading history...
|
|||
| 576 | 56 | case "gmail": |
|
| 577 | return $app_strings['LBL_SMTPTYPE_GMAIL']; break; |
||
|
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. Loading history...
|
|||
| 578 | 56 | case "exchange": |
|
| 579 | return $smtpserver . ' - ' . $app_strings['LBL_SMTPTYPE_EXCHANGE']; break; |
||
|
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. Loading history...
|
|||
| 580 | default: |
||
| 581 | 56 | return $smtpserver; break; |
|
|
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. Loading history...
|
|||
| 582 | } |
||
| 583 | } |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Get mailer for current user by name |
||
| 587 | * @param User $user |
||
| 588 | * @param string $name |
||
| 589 | * @return OutboundEmail|false |
||
| 590 | */ |
||
| 591 | public function getMailerByName($user, $name) |
||
| 592 | { |
||
| 593 | if($name == "system" && !$this->isAllowUserAccessToSystemDefaultOutbound()) { |
||
| 594 | $oe = $this->getUsersMailerForSystemOverride($user->id); |
||
| 595 | if(!empty($oe) && !empty($oe->id)) { |
||
| 596 | return $oe; |
||
| 597 | } |
||
| 598 | else { |
||
| 599 | return $this->getSystemMailerSettings(); |
||
| 600 | } |
||
| 601 | } |
||
| 602 | $res = $this->db->query("SELECT id FROM outbound_email WHERE user_id = '{$user->id}' AND name='".$this->db->quote($name)."'"); |
||
| 603 | $a = $this->db->fetchByAssoc($res); |
||
| 604 | if(!isset($a['id'])) { |
||
| 605 | return false; |
||
| 606 | } |
||
| 607 | return $this->retrieve($a['id']); |
||
| 608 | } |
||
| 609 | } |
||
| 610 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.