Merged in feature/PMC-1332 (pull request #7136)

PMC-1332 PMCORE-1018

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
Approved-by: Paula Quispe <paula.quispe@processmaker.com>
This commit is contained in:
Paula Quispe
2020-02-03 13:58:16 +00:00
committed by Julio Cesar Laura Avendaño
37 changed files with 2841 additions and 361 deletions

View File

@@ -510,6 +510,7 @@ class SpoolRun
case 'MAIL':
case 'PHPMAILER':
case 'IMAP':
case 'GMAILAPI':
switch ($this->config['MESS_ENGINE']) {
case 'MAIL':
$phpMailer = new PHPMailer();
@@ -520,6 +521,11 @@ class SpoolRun
$phpMailer = new PHPMailer(true);
$phpMailer->Mailer = 'smtp';
break;
case 'GMAILAPI':
$phpMailer = new PHPMailerOAuth();
$phpMailer->AuthType = 'XOAUTH2';
$phpMailer->isSMTP();
break;
}
$phpMailer->SMTPAuth = (isset($this->config['SMTPAuth']) ? $this->config['SMTPAuth'] : '');
@@ -529,6 +535,7 @@ class SpoolRun
break;
case 'IMAP':
case 'PHPMAILER':
case 'GMAILAPI':
//Posible Options for SMTPSecure are: "", "ssl" or "tls"
if (isset($this->config['SMTPSecure']) && preg_match('/^(ssl|tls)$/', $this->config['SMTPSecure'])) {
$phpMailer->SMTPSecure = $this->config['SMTPSecure'];
@@ -543,8 +550,15 @@ class SpoolRun
$phpMailer->Encoding = "8bit";
$phpMailer->Host = $this->config['MESS_SERVER'];
$phpMailer->Port = $this->config['MESS_PORT'];
$phpMailer->Username = $this->config['MESS_ACCOUNT'];
$phpMailer->Password = $this->config['MESS_PASSWORD'];
if ($this->config['MESS_ENGINE'] !== 'GMAILAPI') {
$phpMailer->Username = $this->config['MESS_ACCOUNT'];
$phpMailer->Password = $this->config['MESS_PASSWORD'];
} else {
$phpMailer->oauthUserEmail = $this->config['MESS_ACCOUNT'];
$phpMailer->oauthClientId = $this->config['OAUTH_CLIENT_ID'];
$phpMailer->oauthClientSecret = $this->config['OAUTH_CLIENT_SECRET'];
$phpMailer->oauthRefreshToken = $this->config['OAUTH_REFRESH_TOKEN'];
}
//From
$phpMailer->SetFrom($this->fileData['from_email'], utf8_decode($this->fileData['from_name']));

View File

@@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Facades\Crypt;
use ProcessMaker\BusinessModel\EmailServer;
/*----------------------------------********---------------------------------*/
use ProcessMaker\ChangeLog\ChangeLog;
@@ -930,6 +931,12 @@ class WsBase
$row = $rsCriteria->getRow();
$arrayConfigAux = $row;
$arrayConfigAux["SMTPSecure"] = $row["SMTPSECURE"];
$arrayConfigAux["OAUTH_CLIENT_ID"] = !empty($row["OAUTH_CLIENT_ID"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_ID"]) : '';
$arrayConfigAux["OAUTH_CLIENT_SECRET"] = !empty($row["OAUTH_CLIENT_SECRET"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_SECRET"]) : '';
$arrayConfigAux["OAUTH_REFRESH_TOKEN"] = !empty($row["OAUTH_REFRESH_TOKEN"]) ?
Crypt::decryptString($row["OAUTH_REFRESH_TOKEN"]) : '';
}
}
}

View File

@@ -931,7 +931,9 @@ function getEmailConfiguration ()
* @param array | $attachments = [] | Attachment | An Optional arrray. An array of files (full paths) to be attached to the email.
* @param boolean | $showMessage = true | Show message | Optional parameter. Set to TRUE to show the message in the case's message history.
* @param int | $delIndex = 0 | Delegation index of the case | Optional parameter. The delegation index of the current task in the case.
* @param array | $config = [] | Email server configuration | An optional array: An array of parameters to be used in the Email sent (MESS_ENGINE, MESS_SERVER, MESS_PORT, MESS_FROM_MAIL, MESS_RAUTH, MESS_ACCOUNT, MESS_PASSWORD, and SMTPSecure) Or String: UID of Email server .
* @param array | $config = [] | Email server configuration | An optional array: An array of parameters to be used in the Email sent (MESS_ENGINE,
* MESS_SERVER, MESS_PORT, MESS_FROM_MAIL, MESS_RAUTH, MESS_ACCOUNT, MESS_PASSWORD, SMTPSecure, OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET and OAUTH_REFRESH_TOKEN)
* Or String: UID of Email server .
* @return int | | result | Result of sending email
*
* @see class.pmFunctions::PMFSendMessageToGroup()

View File

@@ -95,6 +95,12 @@ class EmailServerMapBuilder
$tMap->addColumn('MESS_DEFAULT', 'MessDefault', 'int', CreoleTypes::INTEGER, true, null);
$tMap->addColumn('OAUTH_CLIENT_ID', 'OauthClientId', 'string', CreoleTypes::VARCHAR, true, 512);
$tMap->addColumn('OAUTH_CLIENT_SECRET', 'OauthClientSecret', 'string', CreoleTypes::VARCHAR, true, 512);
$tMap->addColumn('OAUTH_REFRESH_TOKEN', 'OauthRefreshToken', 'string', CreoleTypes::VARCHAR, true, 512);
} // doBuild()
} // EmailServerMapBuilder

View File

@@ -117,6 +117,24 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
*/
protected $mess_default = 0;
/**
* The value for the oauth_client_id field.
* @var string
*/
protected $oauth_client_id = '';
/**
* The value for the oauth_client_secret field.
* @var string
*/
protected $oauth_client_secret = '';
/**
* The value for the oauth_refresh_token field.
* @var string
*/
protected $oauth_refresh_token = '';
/**
* Flag to prevent endless save loop, if this object is referenced
* by another object which falls in this transaction.
@@ -296,6 +314,39 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
return $this->mess_default;
}
/**
* Get the [oauth_client_id] column value.
*
* @return string
*/
public function getOauthClientId()
{
return $this->oauth_client_id;
}
/**
* Get the [oauth_client_secret] column value.
*
* @return string
*/
public function getOauthClientSecret()
{
return $this->oauth_client_secret;
}
/**
* Get the [oauth_refresh_token] column value.
*
* @return string
*/
public function getOauthRefreshToken()
{
return $this->oauth_refresh_token;
}
/**
* Set the value of [mess_uid] column.
*
@@ -626,6 +677,72 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
} // setMessDefault()
/**
* Set the value of [oauth_client_id] column.
*
* @param string $v new value
* @return void
*/
public function setOauthClientId($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->oauth_client_id !== $v || $v === '') {
$this->oauth_client_id = $v;
$this->modifiedColumns[] = EmailServerPeer::OAUTH_CLIENT_ID;
}
} // setOauthClientId()
/**
* Set the value of [oauth_client_secret] column.
*
* @param string $v new value
* @return void
*/
public function setOauthClientSecret($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->oauth_client_secret !== $v || $v === '') {
$this->oauth_client_secret = $v;
$this->modifiedColumns[] = EmailServerPeer::OAUTH_CLIENT_SECRET;
}
} // setOauthClientSecret()
/**
* Set the value of [oauth_refresh_token] column.
*
* @param string $v new value
* @return void
*/
public function setOauthRefreshToken($v)
{
// Since the native PHP type for this column is string,
// we will cast the input to a string (if it is not).
if ($v !== null && !is_string($v)) {
$v = (string) $v;
}
if ($this->oauth_refresh_token !== $v || $v === '') {
$this->oauth_refresh_token = $v;
$this->modifiedColumns[] = EmailServerPeer::OAUTH_REFRESH_TOKEN;
}
} // setOauthRefreshToken()
/**
* Hydrates (populates) the object variables with values from the database resultset.
*
@@ -673,12 +790,18 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$this->mess_default = $rs->getInt($startcol + 14);
$this->oauth_client_id = $rs->getString($startcol + 15);
$this->oauth_client_secret = $rs->getString($startcol + 16);
$this->oauth_refresh_token = $rs->getString($startcol + 17);
$this->resetModified();
$this->setNew(false);
// FIXME - using NUM_COLUMNS may be clearer.
return $startcol + 15; // 15 = EmailServerPeer::NUM_COLUMNS - EmailServerPeer::NUM_LAZY_LOAD_COLUMNS).
return $startcol + 18; // 18 = EmailServerPeer::NUM_COLUMNS - EmailServerPeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) {
throw new PropelException("Error populating EmailServer object", $e);
@@ -927,6 +1050,15 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
case 14:
return $this->getMessDefault();
break;
case 15:
return $this->getOauthClientId();
break;
case 16:
return $this->getOauthClientSecret();
break;
case 17:
return $this->getOauthRefreshToken();
break;
default:
return null;
break;
@@ -962,6 +1094,9 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$keys[12] => $this->getMessTrySendInmediatly(),
$keys[13] => $this->getMailTo(),
$keys[14] => $this->getMessDefault(),
$keys[15] => $this->getOauthClientId(),
$keys[16] => $this->getOauthClientSecret(),
$keys[17] => $this->getOauthRefreshToken(),
);
return $result;
}
@@ -1038,6 +1173,15 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
case 14:
$this->setMessDefault($value);
break;
case 15:
$this->setOauthClientId($value);
break;
case 16:
$this->setOauthClientSecret($value);
break;
case 17:
$this->setOauthRefreshToken($value);
break;
} // switch()
}
@@ -1121,6 +1265,18 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$this->setMessDefault($arr[$keys[14]]);
}
if (array_key_exists($keys[15], $arr)) {
$this->setOauthClientId($arr[$keys[15]]);
}
if (array_key_exists($keys[16], $arr)) {
$this->setOauthClientSecret($arr[$keys[16]]);
}
if (array_key_exists($keys[17], $arr)) {
$this->setOauthRefreshToken($arr[$keys[17]]);
}
}
/**
@@ -1192,6 +1348,18 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$criteria->add(EmailServerPeer::MESS_DEFAULT, $this->mess_default);
}
if ($this->isColumnModified(EmailServerPeer::OAUTH_CLIENT_ID)) {
$criteria->add(EmailServerPeer::OAUTH_CLIENT_ID, $this->oauth_client_id);
}
if ($this->isColumnModified(EmailServerPeer::OAUTH_CLIENT_SECRET)) {
$criteria->add(EmailServerPeer::OAUTH_CLIENT_SECRET, $this->oauth_client_secret);
}
if ($this->isColumnModified(EmailServerPeer::OAUTH_REFRESH_TOKEN)) {
$criteria->add(EmailServerPeer::OAUTH_REFRESH_TOKEN, $this->oauth_refresh_token);
}
return $criteria;
}
@@ -1274,6 +1442,12 @@ abstract class BaseEmailServer extends BaseObject implements Persistent
$copyObj->setMessDefault($this->mess_default);
$copyObj->setOauthClientId($this->oauth_client_id);
$copyObj->setOauthClientSecret($this->oauth_client_secret);
$copyObj->setOauthRefreshToken($this->oauth_refresh_token);
$copyObj->setNew(true);

View File

@@ -25,7 +25,7 @@ abstract class BaseEmailServerPeer
const CLASS_DEFAULT = 'classes.model.EmailServer';
/** The total number of columns. */
const NUM_COLUMNS = 15;
const NUM_COLUMNS = 18;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
@@ -76,6 +76,15 @@ abstract class BaseEmailServerPeer
/** the column name for the MESS_DEFAULT field */
const MESS_DEFAULT = 'EMAIL_SERVER.MESS_DEFAULT';
/** the column name for the OAUTH_CLIENT_ID field */
const OAUTH_CLIENT_ID = 'EMAIL_SERVER.OAUTH_CLIENT_ID';
/** the column name for the OAUTH_CLIENT_SECRET field */
const OAUTH_CLIENT_SECRET = 'EMAIL_SERVER.OAUTH_CLIENT_SECRET';
/** the column name for the OAUTH_REFRESH_TOKEN field */
const OAUTH_REFRESH_TOKEN = 'EMAIL_SERVER.OAUTH_REFRESH_TOKEN';
/** The PHP to DB Name Mapping */
private static $phpNameMap = null;
@@ -87,10 +96,10 @@ abstract class BaseEmailServerPeer
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('MessUid', 'MessEngine', 'MessServer', 'MessPort', 'MessIncomingServer', 'MessIncomingPort', 'MessRauth', 'MessAccount', 'MessPassword', 'MessFromMail', 'MessFromName', 'Smtpsecure', 'MessTrySendInmediatly', 'MailTo', 'MessDefault', ),
BasePeer::TYPE_COLNAME => array (EmailServerPeer::MESS_UID, EmailServerPeer::MESS_ENGINE, EmailServerPeer::MESS_SERVER, EmailServerPeer::MESS_PORT, EmailServerPeer::MESS_INCOMING_SERVER, EmailServerPeer::MESS_INCOMING_PORT, EmailServerPeer::MESS_RAUTH, EmailServerPeer::MESS_ACCOUNT, EmailServerPeer::MESS_PASSWORD, EmailServerPeer::MESS_FROM_MAIL, EmailServerPeer::MESS_FROM_NAME, EmailServerPeer::SMTPSECURE, EmailServerPeer::MESS_TRY_SEND_INMEDIATLY, EmailServerPeer::MAIL_TO, EmailServerPeer::MESS_DEFAULT, ),
BasePeer::TYPE_FIELDNAME => array ('MESS_UID', 'MESS_ENGINE', 'MESS_SERVER', 'MESS_PORT', 'MESS_INCOMING_SERVER', 'MESS_INCOMING_PORT', 'MESS_RAUTH', 'MESS_ACCOUNT', 'MESS_PASSWORD', 'MESS_FROM_MAIL', 'MESS_FROM_NAME', 'SMTPSECURE', 'MESS_TRY_SEND_INMEDIATLY', 'MAIL_TO', 'MESS_DEFAULT', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
BasePeer::TYPE_PHPNAME => array ('MessUid', 'MessEngine', 'MessServer', 'MessPort', 'MessIncomingServer', 'MessIncomingPort', 'MessRauth', 'MessAccount', 'MessPassword', 'MessFromMail', 'MessFromName', 'Smtpsecure', 'MessTrySendInmediatly', 'MailTo', 'MessDefault', 'OauthClientId', 'OauthClientSecret', 'OauthRefreshToken', ),
BasePeer::TYPE_COLNAME => array (EmailServerPeer::MESS_UID, EmailServerPeer::MESS_ENGINE, EmailServerPeer::MESS_SERVER, EmailServerPeer::MESS_PORT, EmailServerPeer::MESS_INCOMING_SERVER, EmailServerPeer::MESS_INCOMING_PORT, EmailServerPeer::MESS_RAUTH, EmailServerPeer::MESS_ACCOUNT, EmailServerPeer::MESS_PASSWORD, EmailServerPeer::MESS_FROM_MAIL, EmailServerPeer::MESS_FROM_NAME, EmailServerPeer::SMTPSECURE, EmailServerPeer::MESS_TRY_SEND_INMEDIATLY, EmailServerPeer::MAIL_TO, EmailServerPeer::MESS_DEFAULT, EmailServerPeer::OAUTH_CLIENT_ID, EmailServerPeer::OAUTH_CLIENT_SECRET, EmailServerPeer::OAUTH_REFRESH_TOKEN, ),
BasePeer::TYPE_FIELDNAME => array ('MESS_UID', 'MESS_ENGINE', 'MESS_SERVER', 'MESS_PORT', 'MESS_INCOMING_SERVER', 'MESS_INCOMING_PORT', 'MESS_RAUTH', 'MESS_ACCOUNT', 'MESS_PASSWORD', 'MESS_FROM_MAIL', 'MESS_FROM_NAME', 'SMTPSECURE', 'MESS_TRY_SEND_INMEDIATLY', 'MAIL_TO', 'MESS_DEFAULT', 'OAUTH_CLIENT_ID', 'OAUTH_CLIENT_SECRET', 'OAUTH_REFRESH_TOKEN', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, )
);
/**
@@ -100,10 +109,10 @@ abstract class BaseEmailServerPeer
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('MessUid' => 0, 'MessEngine' => 1, 'MessServer' => 2, 'MessPort' => 3, 'MessIncomingServer' => 4, 'MessIncomingPort' => 5, 'MessRauth' => 6, 'MessAccount' => 7, 'MessPassword' => 8, 'MessFromMail' => 9, 'MessFromName' => 10, 'Smtpsecure' => 11, 'MessTrySendInmediatly' => 12, 'MailTo' => 13, 'MessDefault' => 14, ),
BasePeer::TYPE_COLNAME => array (EmailServerPeer::MESS_UID => 0, EmailServerPeer::MESS_ENGINE => 1, EmailServerPeer::MESS_SERVER => 2, EmailServerPeer::MESS_PORT => 3, EmailServerPeer::MESS_INCOMING_SERVER => 4, EmailServerPeer::MESS_INCOMING_PORT => 5, EmailServerPeer::MESS_RAUTH => 6, EmailServerPeer::MESS_ACCOUNT => 7, EmailServerPeer::MESS_PASSWORD => 8, EmailServerPeer::MESS_FROM_MAIL => 9, EmailServerPeer::MESS_FROM_NAME => 10, EmailServerPeer::SMTPSECURE => 11, EmailServerPeer::MESS_TRY_SEND_INMEDIATLY => 12, EmailServerPeer::MAIL_TO => 13, EmailServerPeer::MESS_DEFAULT => 14, ),
BasePeer::TYPE_FIELDNAME => array ('MESS_UID' => 0, 'MESS_ENGINE' => 1, 'MESS_SERVER' => 2, 'MESS_PORT' => 3, 'MESS_INCOMING_SERVER' => 4, 'MESS_INCOMING_PORT' => 5, 'MESS_RAUTH' => 6, 'MESS_ACCOUNT' => 7, 'MESS_PASSWORD' => 8, 'MESS_FROM_MAIL' => 9, 'MESS_FROM_NAME' => 10, 'SMTPSECURE' => 11, 'MESS_TRY_SEND_INMEDIATLY' => 12, 'MAIL_TO' => 13, 'MESS_DEFAULT' => 14, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, )
BasePeer::TYPE_PHPNAME => array ('MessUid' => 0, 'MessEngine' => 1, 'MessServer' => 2, 'MessPort' => 3, 'MessIncomingServer' => 4, 'MessIncomingPort' => 5, 'MessRauth' => 6, 'MessAccount' => 7, 'MessPassword' => 8, 'MessFromMail' => 9, 'MessFromName' => 10, 'Smtpsecure' => 11, 'MessTrySendInmediatly' => 12, 'MailTo' => 13, 'MessDefault' => 14, 'OauthClientId' => 15, 'OauthClientSecret' => 16, 'OauthRefreshToken' => 17, ),
BasePeer::TYPE_COLNAME => array (EmailServerPeer::MESS_UID => 0, EmailServerPeer::MESS_ENGINE => 1, EmailServerPeer::MESS_SERVER => 2, EmailServerPeer::MESS_PORT => 3, EmailServerPeer::MESS_INCOMING_SERVER => 4, EmailServerPeer::MESS_INCOMING_PORT => 5, EmailServerPeer::MESS_RAUTH => 6, EmailServerPeer::MESS_ACCOUNT => 7, EmailServerPeer::MESS_PASSWORD => 8, EmailServerPeer::MESS_FROM_MAIL => 9, EmailServerPeer::MESS_FROM_NAME => 10, EmailServerPeer::SMTPSECURE => 11, EmailServerPeer::MESS_TRY_SEND_INMEDIATLY => 12, EmailServerPeer::MAIL_TO => 13, EmailServerPeer::MESS_DEFAULT => 14, EmailServerPeer::OAUTH_CLIENT_ID => 15, EmailServerPeer::OAUTH_CLIENT_SECRET => 16, EmailServerPeer::OAUTH_REFRESH_TOKEN => 17, ),
BasePeer::TYPE_FIELDNAME => array ('MESS_UID' => 0, 'MESS_ENGINE' => 1, 'MESS_SERVER' => 2, 'MESS_PORT' => 3, 'MESS_INCOMING_SERVER' => 4, 'MESS_INCOMING_PORT' => 5, 'MESS_RAUTH' => 6, 'MESS_ACCOUNT' => 7, 'MESS_PASSWORD' => 8, 'MESS_FROM_MAIL' => 9, 'MESS_FROM_NAME' => 10, 'SMTPSECURE' => 11, 'MESS_TRY_SEND_INMEDIATLY' => 12, 'MAIL_TO' => 13, 'MESS_DEFAULT' => 14, 'OAUTH_CLIENT_ID' => 15, 'OAUTH_CLIENT_SECRET' => 16, 'OAUTH_REFRESH_TOKEN' => 17, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, )
);
/**
@@ -234,6 +243,12 @@ abstract class BaseEmailServerPeer
$criteria->addSelectColumn(EmailServerPeer::MESS_DEFAULT);
$criteria->addSelectColumn(EmailServerPeer::OAUTH_CLIENT_ID);
$criteria->addSelectColumn(EmailServerPeer::OAUTH_CLIENT_SECRET);
$criteria->addSelectColumn(EmailServerPeer::OAUTH_REFRESH_TOKEN);
}
const COUNT = 'COUNT(EMAIL_SERVER.MESS_UID)';
@@ -564,6 +579,9 @@ abstract class BaseEmailServerPeer
}
} else {
if ($obj->isNew() || $obj->isColumnModified(EmailServerPeer::MESS_ENGINE))
$columns[EmailServerPeer::MESS_ENGINE] = $obj->getMessEngine();
}
return BasePeer::doValidate(EmailServerPeer::DATABASE_NAME, EmailServerPeer::TABLE_NAME, $columns);

View File

@@ -5013,6 +5013,9 @@
<column name="MESS_TRY_SEND_INMEDIATLY" type="INTEGER" required="true" default="0"/>
<column name="MAIL_TO" type="VARCHAR" size="256" required="false" default=""/>
<column name="MESS_DEFAULT" type="INTEGER" required="true" default="0"/>
<column name="OAUTH_CLIENT_ID" type="VARCHAR" size="512" required="true" default=""/>
<column name="OAUTH_CLIENT_SECRET" type="VARCHAR" size="512" required="true" default=""/>
<column name="OAUTH_REFRESH_TOKEN" type="VARCHAR" size="512" required="true" default=""/>
</table>
<table name="WEB_ENTRY_EVENT">

View File

@@ -4331,6 +4331,18 @@ msgstr "Click the lock to make changes."
msgid "Click the lock to prevent further changes."
msgstr "Click the lock to prevent further changes."
# TRANSLATION
# LABEL/ID_CLIENT_ID
#: LABEL/ID_CLIENT_ID
msgid "Client ID"
msgstr "Client ID"
# TRANSLATION
# LABEL/ID_CLIENT_SECRET
#: LABEL/ID_CLIENT_SECRET
msgid "Client Secret"
msgstr "Client Secret"
# TRANSLATION
# LABEL/ID_CLOSE
#: LABEL/ID_CLOSE
@@ -7064,8 +7076,8 @@ msgstr "The email was resend to"
# TRANSLATION
# LABEL/ID_EMAIL_SERVER_ACCOUNT_FROM
#: LABEL/ID_EMAIL_SERVER_ACCOUNT_FROM
msgid "Sender Account"
msgstr "Sender Account"
msgid "From Account"
msgstr "From Account"
# TRANSLATION
# LABEL/ID_EMAIL_SERVER_CONFIRM_DELETE
@@ -18701,6 +18713,12 @@ msgstr "SMTP (PHPMailer)"
msgid "SMTP (OpenMail)"
msgstr "SMTP (OpenMail)"
# TRANSLATION
# LABEL/ID_MESS_ENGINE_TYPE_4
#: LABEL/ID_MESS_ENGINE_TYPE_4
msgid "OAUTH (GMail OAuth)"
msgstr "OAUTH (GMail OAuth)"
# TRANSLATION
# LABEL/ID_MESS_SEND_MAX_REQUIRED
#: LABEL/ID_MESS_SEND_MAX_REQUIRED

View File

@@ -57530,6 +57530,8 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_CLEAR_LOG','en','Clear Log','2014-01-15') ,
( 'LABEL','ID_CLICK_LOCK','en','Click the lock to make changes.','2014-01-15') ,
( 'LABEL','ID_CLICK_UNLOCK','en','Click the lock to prevent further changes.','2014-01-15') ,
( 'LABEL','ID_CLIENT_ID','en','Client ID','2019-11-14') ,
( 'LABEL','ID_CLIENT_SECRET','en','Client Secret','2019-11-14') ,
( 'LABEL','ID_CLOSE','en','Close','2014-01-15') ,
( 'LABEL','ID_CLOSE_EDITOR','en','Close Editor','2014-01-15') ,
( 'LABEL','ID_CODE','en','Code','2014-01-15') ,
@@ -57997,7 +57999,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_EMAIL_MORE_USER','en','This email is assigned to more than one user. Please contact your administrator.','2015-10-02') ,
( 'LABEL','ID_EMAIL_NOT_CORRESPONDS_TOKEN','en','The email does not corresponds to the token gmail user.','2015-10-02') ,
( 'LABEL','ID_EMAIL_RESENT_TO','en','The email was resend to','2016-04-08') ,
( 'LABEL','ID_EMAIL_SERVER_ACCOUNT_FROM','en','Sender Account','2017-02-21') ,
( 'LABEL','ID_EMAIL_SERVER_ACCOUNT_FROM','en','From Account','2017-02-21') ,
( 'LABEL','ID_EMAIL_SERVER_CONFIRM_DELETE','en','Do you want to delete the Email Server?','2014-12-24') ,
( 'LABEL','ID_EMAIL_SERVER_DEFAULT','en','Default','2014-12-24') ,
( 'LABEL','ID_EMAIL_SERVER_DELETE_DATA','en','Delete data...','2014-12-24') ,
@@ -59980,6 +59982,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_MESS_ENGINE_TYPE_1','en','Mail (PHP)','2014-01-15') ,
( 'LABEL','ID_MESS_ENGINE_TYPE_2','en','SMTP (PHPMailer)','2014-01-15') ,
( 'LABEL','ID_MESS_ENGINE_TYPE_3','en','SMTP (OpenMail)','2014-01-15') ,
( 'LABEL','ID_MESS_ENGINE_TYPE_4','en','OAUTH (GMail OAuth)','2019-11-15') ,
( 'LABEL','ID_MESS_SEND_MAX_REQUIRED','en','The maximum number of attempts to send mail is a required field.','2014-01-15') ,
( 'LABEL','ID_MESS_TEST_BODY','en','ProcessMaker Test Email','2014-01-15') ,
( 'LABEL','ID_MESS_TEST_MESSAGE_ERROR_PHP_MAIL','en','Test message send failed, error:','2014-01-15') ,

View File

@@ -2784,6 +2784,9 @@ CREATE TABLE `EMAIL_SERVER`
`MESS_TRY_SEND_INMEDIATLY` INTEGER default 0 NOT NULL,
`MAIL_TO` VARCHAR(256) default '',
`MESS_DEFAULT` INTEGER default 0 NOT NULL,
`OAUTH_CLIENT_ID` VARCHAR(512) default '' NOT NULL,
`OAUTH_CLIENT_SECRET` VARCHAR(512) default '' NOT NULL,
`OAUTH_REFRESH_TOKEN` VARCHAR(512) default '' NOT NULL,
PRIMARY KEY (`MESS_UID`)
)ENGINE=InnoDB DEFAULT CHARSET='utf8';
#-----------------------------------------------------------------------------

View File

@@ -817,7 +817,10 @@ switch (($_POST['action']) ? $_POST['action'] : $_REQUEST['action']) {
'MESS_ACCOUNT' => $aSetup['MESS_ACCOUNT'],
'MESS_PASSWORD' => $aSetup['MESS_PASSWORD'],
'SMTPSecure' => $aSetup['SMTPSecure'],
'SMTPAuth' => $aSetup['MESS_RAUTH']
'SMTPAuth' => $aSetup['MESS_RAUTH'],
'OAUTH_CLIENT_ID' => $aSetup['OAUTH_CLIENT_ID'],
'OAUTH_CLIENT_SECRET' => $aSetup['OAUTH_CLIENT_SECRET'],
'OAUTH_REFRESH_TOKEN' => $aSetup['OAUTH_REFRESH_TOKEN']
)
);
$oSpool->create(array('msg_uid' => $data['MSG_UID'], 'app_uid' => $data['APP_UID'], 'del_index' => $data['DEL_INDEX'], 'app_msg_type' => $data['APP_MSG_TYPE'], 'app_msg_subject' => $data['APP_MSG_SUBJECT'], 'app_msg_from' => $data['APP_MSG_FROM'], 'app_msg_to' => $data['APP_MSG_TO'], 'app_msg_body' => $data['APP_MSG_BODY'], 'app_msg_cc' => $data['APP_MSG_CC'], 'app_msg_bcc' => $data['APP_MSG_BCC'], 'app_msg_attach' => $data['APP_MSG_ATTACH'], 'app_msg_template' => $data['APP_MSG_TEMPLATE'], 'app_msg_status' => 'pending'

View File

@@ -1,27 +1,37 @@
<?php
use Illuminate\Support\Facades\Cache;
global $RBAC;
$resultRbac = $RBAC->requirePermissions('PM_SETUP_EMAIL');
$resultRbac = $RBAC->requirePermissions('PM_SETUP_EMAIL');
if (!$resultRbac) {
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
G::header('location: ../login/login');
die();
}
$messageSent = "";
if (Cache::has('errorMessageIfNotAuthenticate')) {
$messageSent = Cache::get('errorMessageIfNotAuthenticate');
}
Cache::forget('errorMessageIfNotAuthenticate');
//Data
$configuration = new Configurations();
$arrayConfigPage = $configuration->getConfiguration("emailServerList", "pageSize", null, $_SESSION["USER_LOGGED"]);
$arrayConfig = array();
$arrayConfig["pageSize"] = (isset($arrayConfigPage["pageSize"]))? $arrayConfigPage["pageSize"] : 20;
$arrayConfig["pageSize"] = (isset($arrayConfigPage["pageSize"])) ? $arrayConfigPage["pageSize"] : 20;
$headPublisher = headPublisher::getSingleton();
$headPublisher->addContent("emailServer/emailServer"); //Adding a HTML file
$headPublisher->addExtJsScript("emailServer/emailServer", false); //Adding a JavaScript file
$headPublisher->assign("CONFIG", $arrayConfig);
$headPublisher->assign("errorMessageIfNotAuthenticate", $messageSent);
/*----------------------------------********---------------------------------*/
$headPublisher->assign("EMAILSERVER_LICENSED", (PMLicensedFeatures::getSingleton()->verifyfeature("zIKRGpDM3pjcHFsWGplNDN0dTl5bGN3UTNiOWdQU0E5Q05QTksrU1ladWQ0VT0="))? 1 : 0);
$headPublisher->assign("EMAILSERVER_LICENSED", (PMLicensedFeatures::getSingleton()->verifyfeature("zIKRGpDM3pjcHFsWGplNDN0dTl5bGN3UTNiOWdQU0E5Q05QTksrU1ladWQ0VT0=")) ? 1 : 0);
/*----------------------------------********---------------------------------*/
G::RenderPage("publish", "extJs");

View File

@@ -1,11 +1,15 @@
<?php
$option = (isset($_POST["option"]))? $_POST["option"] : "";
$response = array();
use ProcessMaker\Core\System;
use ProcessMaker\GmailOAuth\GmailOAuth;
$option = (isset($_POST["option"])) ? $_POST["option"] : "";
$response = [];
$RBAC->allows(basename(__FILE__), $option);
switch ($option) {
case "INS":
$arrayData = array();
$arrayData = [];
$server = "";
$port = "";
@@ -16,45 +20,45 @@ switch ($option) {
$smtpSecure = "";
$cboEmailEngine = $_POST["cboEmailEngine"];
$accountFrom = (isset($_POST["accountFrom"]))? $_POST["accountFrom"] : "";
$accountFrom = (isset($_POST["accountFrom"])) ? $_POST["accountFrom"] : "";
$fromName = $_POST["fromName"];
$fromMail = $_POST["fromMail"];
$sendTestMail = (int)($_POST["sendTestMail"]);
$mailTo = ($sendTestMail == 1)? $_POST["mailTo"] : "";
$emailServerDefault = (int)($_POST["emailServerDefault"]);
$sendTestMail = (int) ($_POST["sendTestMail"]);
$mailTo = ($sendTestMail == 1) ? $_POST["mailTo"] : "";
$emailServerDefault = (int) ($_POST["emailServerDefault"]);
if ($cboEmailEngine == "PHPMAILER") {
$server = $_POST["server"];
$port = (int)($_POST["port"]);
$reqAuthentication = (int)($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
$port = (int) ($_POST["port"]);
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
$smtpSecure = $_POST["smtpSecure"];
} elseif ($cboEmailEngine == "IMAP") {
$server = $_POST["server"];
$port = (int)($_POST["port"]);
$port = (int) ($_POST["port"]);
$incomingServer = $_POST["incomingServer"];
$incomingPort = (int)($_POST["incomingPort"]);
$reqAuthentication = (int)($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
$incomingPort = (int) ($_POST["incomingPort"]);
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
$smtpSecure = $_POST["smtpSecure"];
}
try {
$arrayData = array(
"MESS_ENGINE" => $cboEmailEngine,
"MESS_SERVER" => $server,
"MESS_PORT" => $port,
"MESS_INCOMING_SERVER" => $incomingServer,
"MESS_INCOMING_PORT" => $incomingPort,
"MESS_RAUTH" => $reqAuthentication,
"MESS_ACCOUNT" => $accountFrom,
"MESS_PASSWORD" => $password,
"MESS_FROM_MAIL" => $fromMail,
"MESS_FROM_NAME" => $fromName,
"SMTPSECURE" => $smtpSecure,
"MESS_ENGINE" => $cboEmailEngine,
"MESS_SERVER" => $server,
"MESS_PORT" => $port,
"MESS_INCOMING_SERVER" => $incomingServer,
"MESS_INCOMING_PORT" => $incomingPort,
"MESS_RAUTH" => $reqAuthentication,
"MESS_ACCOUNT" => $accountFrom,
"MESS_PASSWORD" => $password,
"MESS_FROM_MAIL" => $fromMail,
"MESS_FROM_NAME" => $fromName,
"SMTPSECURE" => $smtpSecure,
"MESS_TRY_SEND_INMEDIATLY" => $sendTestMail,
"MAIL_TO" => $mailTo,
"MESS_DEFAULT" => $emailServerDefault
"MAIL_TO" => $mailTo,
"MESS_DEFAULT" => $emailServerDefault
);
$emailSever = new \ProcessMaker\BusinessModel\EmailServer();
@@ -62,14 +66,14 @@ switch ($option) {
$arrayEmailServerData = $emailSever->create($arrayData);
$response["status"] = "OK";
$response["data"] = $arrayEmailServerData;
$response["data"] = $arrayEmailServerData;
} catch (Exception $e) {
$response["status"] = "ERROR";
$response["status"] = "ERROR";
$response["message"] = $e->getMessage();
}
break;
case "UPD":
$arrayData = array();
$arrayData = [];
$emailServerUid = $_POST["emailServerUid"];
@@ -82,45 +86,45 @@ switch ($option) {
$smtpSecure = "";
$cboEmailEngine = $_POST["cboEmailEngine"];
$accountFrom = (isset($_POST["accountFrom"]))? $_POST["accountFrom"] : "";
$accountFrom = (isset($_POST["accountFrom"])) ? $_POST["accountFrom"] : "";
$fromName = $_POST["fromName"];
$fromMail = $_POST["fromMail"];
$sendTestMail = (int)($_POST["sendTestMail"]);
$mailTo = ($sendTestMail == 1)? $_POST["mailTo"] : "";
$emailServerDefault = (int)($_POST["emailServerDefault"]);
$sendTestMail = (int) ($_POST["sendTestMail"]);
$mailTo = ($sendTestMail == 1) ? $_POST["mailTo"] : "";
$emailServerDefault = (int) ($_POST["emailServerDefault"]);
if ($cboEmailEngine == "PHPMAILER") {
$server = $_POST["server"];
$port = (int)($_POST["port"]);
$reqAuthentication = (int)($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
$port = (int) ($_POST["port"]);
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
$smtpSecure = $_POST["smtpSecure"];
} elseif ($cboEmailEngine == "IMAP") {
$server = $_POST["server"];
$port = (int)($_POST["port"]);
$port = (int) ($_POST["port"]);
$incomingServer = $_POST["incomingServer"];
$incomingPort = (int)($_POST["incomingPort"]);
$reqAuthentication = (int)($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
$incomingPort = (int) ($_POST["incomingPort"]);
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
$smtpSecure = $_POST["smtpSecure"];
}
try {
$arrayData = array(
"MESS_ENGINE" => $cboEmailEngine,
"MESS_SERVER" => $server,
"MESS_PORT" => $port,
"MESS_INCOMING_SERVER" => $incomingServer,
"MESS_INCOMING_PORT" => $incomingPort,
"MESS_RAUTH" => $reqAuthentication,
"MESS_ACCOUNT" => $accountFrom,
"MESS_PASSWORD" => $password,
"MESS_FROM_MAIL" => $fromMail,
"MESS_FROM_NAME" => $fromName,
"SMTPSECURE" => $smtpSecure,
"MESS_ENGINE" => $cboEmailEngine,
"MESS_SERVER" => $server,
"MESS_PORT" => $port,
"MESS_INCOMING_SERVER" => $incomingServer,
"MESS_INCOMING_PORT" => $incomingPort,
"MESS_RAUTH" => $reqAuthentication,
"MESS_ACCOUNT" => $accountFrom,
"MESS_PASSWORD" => $password,
"MESS_FROM_MAIL" => $fromMail,
"MESS_FROM_NAME" => $fromName,
"SMTPSECURE" => $smtpSecure,
"MESS_TRY_SEND_INMEDIATLY" => $sendTestMail,
"MAIL_TO" => $mailTo,
"MESS_DEFAULT" => $emailServerDefault
"MAIL_TO" => $mailTo,
"MESS_DEFAULT" => $emailServerDefault
);
$emailSever = new \ProcessMaker\BusinessModel\EmailServer();
@@ -128,9 +132,9 @@ switch ($option) {
$arrayEmailServerData = $emailSever->update($emailServerUid, $arrayData);
$response["status"] = "OK";
$response["data"] = $arrayEmailServerData;
$response["data"] = $arrayEmailServerData;
} catch (Exception $e) {
$response["status"] = "ERROR";
$response["status"] = "ERROR";
$response["message"] = $e->getMessage();
}
@@ -145,7 +149,7 @@ switch ($option) {
$response["status"] = "OK";
} catch (Exception $e) {
$response["status"] = "ERROR";
$response["status"] = "ERROR";
$response["message"] = $e->getMessage();
}
break;
@@ -153,27 +157,27 @@ switch ($option) {
$pageSize = $_POST["pageSize"];
$search = $_POST["search"];
$sortField = (isset($_POST["sort"]))? $_POST["sort"]: "";
$sortDir = (isset($_POST["dir"]))? $_POST["dir"]: "";
$start = (isset($_POST["start"]))? $_POST["start"]: 0;
$limit = (isset($_POST["limit"]))? $_POST["limit"]: $pageSize;
$sortField = (isset($_POST["sort"])) ? $_POST["sort"] : "";
$sortDir = (isset($_POST["dir"])) ? $_POST["dir"] : "";
$start = (isset($_POST["start"])) ? $_POST["start"] : 0;
$limit = (isset($_POST["limit"])) ? $_POST["limit"] : $pageSize;
try {
$emailSever = new \ProcessMaker\BusinessModel\EmailServer();
$result = $emailSever->getEmailServers(array("filter" => $search), $sortField, $sortDir, $start, $limit);
$response["status"] = "OK";
$response["status"] = "OK";
$response["success"] = true;
$response["resultTotal"] = $result["total"];
$response["resultRoot"] = $result["data"];
$response["resultRoot"] = $result["data"];
} catch (Exception $e) {
$response["status"] = "ERROR";
$response["status"] = "ERROR";
$response["message"] = $e->getMessage();
}
break;
case "TEST":
$arrayData = array();
$arrayData = [];
$server = "";
$port = "";
@@ -184,48 +188,76 @@ switch ($option) {
$smtpSecure = "";
$cboEmailEngine = $_POST["cboEmailEngine"];
$accountFrom = (isset($_POST["accountFrom"]))? $_POST["accountFrom"] : "";
$accountFrom = (isset($_POST["accountFrom"])) ? $_POST["accountFrom"] : "";
$fromName = $_POST["fromName"];
$fromMail = $_POST["fromMail"];
$sendTestMail = (int)($_POST["sendTestMail"]);
$mailTo = ($sendTestMail == 1)? $_POST["mailTo"] : "";
$emailServerDefault = (int)($_POST["emailServerDefault"]);
$sendTestMail = (int) ($_POST["sendTestMail"]);
$mailTo = ($sendTestMail == 1) ? $_POST["mailTo"] : "";
$emailServerDefault = (int) ($_POST["emailServerDefault"]);
if ($cboEmailEngine == "PHPMAILER" || $cboEmailEngine == "IMAP") {
$server = $_POST["server"];
$port = (int)($_POST["port"]);
$reqAuthentication = (int)($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1)? $_POST["password"] : "";
$port = (int) ($_POST["port"]);
$reqAuthentication = (int) ($_POST["reqAuthentication"]);
$password = ($reqAuthentication == 1) ? $_POST["password"] : "";
$smtpSecure = $_POST["smtpSecure"];
}
try {
$arrayData = array(
"MESS_ENGINE" => $cboEmailEngine,
"MESS_SERVER" => $server,
"MESS_PORT" => $port,
"MESS_RAUTH" => $reqAuthentication,
"MESS_ACCOUNT" => $accountFrom,
"MESS_PASSWORD" => $password,
"MESS_FROM_MAIL" => $fromMail,
"MESS_FROM_NAME" => $fromName,
"SMTPSECURE" => $smtpSecure,
"MESS_ENGINE" => $cboEmailEngine,
"MESS_SERVER" => $server,
"MESS_PORT" => $port,
"MESS_RAUTH" => $reqAuthentication,
"MESS_ACCOUNT" => $accountFrom,
"MESS_PASSWORD" => $password,
"MESS_FROM_MAIL" => $fromMail,
"MESS_FROM_NAME" => $fromName,
"SMTPSECURE" => $smtpSecure,
"MESS_TRY_SEND_INMEDIATLY" => $sendTestMail,
"MAIL_TO" => $mailTo,
"MESS_DEFAULT" => $emailServerDefault
"MAIL_TO" => $mailTo,
"MESS_DEFAULT" => $emailServerDefault
);
$emailSever = new \ProcessMaker\BusinessModel\EmailServer();
$arrayEmailServerData = $emailSever->testConnection($arrayData);
$response["data"] = $arrayEmailServerData;
$response["data"] = $arrayEmailServerData;
} catch (Exception $e) {
$response["status"] = "ERROR";
$response["status"] = "ERROR";
$response["message"] = $e->getMessage();
}
break;
case "createAuthUrl":
try {
$gmailOAuth = new GmailOAuth();
$gmailOAuth->setClientID($_POST['clientID']);
$gmailOAuth->setClientSecret($_POST['clientSecret']);
$gmailOAuth->setRedirectURI(System::getServerMainPath() . "/emailServer/emailServerGmailOAuth");
$gmailOAuth->setEmailEngine($_POST['emailEngine']);
$gmailOAuth->setFromAccount($_POST['fromAccount']);
$gmailOAuth->setSenderEmail($_POST['senderEmail']);
$gmailOAuth->setSenderName($_POST['senderName']);
$gmailOAuth->setSendTestMail((int) $_POST['sendTestMail']);
$gmailOAuth->setMailTo($_POST['mailTo']);
$gmailOAuth->setSetDefaultConfiguration((int) $_POST['setDefaultConfiguration']);
if (!empty($_POST['emailServerUid'])) {
$gmailOAuth->setEmailServerUid($_POST['emailServerUid']);
}
$client = $gmailOAuth->getGoogleClient();
$response = [
"status" => 200,
"data" => $client->createAuthUrl()
];
$_SESSION['gmailOAuth'] = $gmailOAuth;
} catch (Exception $e) {
$response = [
"status" => 500,
"message" => $e->getMessage()
];
}
break;
}
echo G::json_encode($response);

View File

@@ -0,0 +1,41 @@
<?php
use Illuminate\Support\Facades\Cache;
use ProcessMaker\Core\System;
use ProcessMaker\GmailOAuth\GmailOAuth;
Cache::forget('errorMessageIfNotAuthenticate');
try {
$header = "location:" . System::getServerMainPath() . "/setup/main?s=EMAIL_SERVER";
$validInput = empty($_GET['code']) || empty($_SESSION['gmailOAuth']) || !is_object($_SESSION['gmailOAuth']);
if ($validInput) {
G::header($header);
return;
}
$RBAC->allows(basename(__FILE__), "code");
$gmailOAuth = $_SESSION['gmailOAuth'];
$googleClient = $gmailOAuth->getGoogleClient();
$result = $googleClient->authenticate($_GET['code']);
if (isset($result["error"])) {
Cache::put('errorMessageIfNotAuthenticate', G::json_decode($result["error"]), 2);
G::header($header);
return;
}
$gmailOAuth->setRefreshToken($googleClient->getRefreshToken());
$gmailOAuth->saveEmailServer();
$gmailOAuth->sendTestMailWithPHPMailerOAuth();
} catch (Exception $e) {
/**
* The laravel cache is volatile in each session, you can specify the duration
* value in minutes for each session. We use 2 minutes, enough time to retrieve
* the error message if there is one.
*/
Cache::put('errorMessageIfNotAuthenticate', $e->getMessage(), 2);
}
G::header($header);
return;

View File

@@ -5,6 +5,7 @@ use AppMessage;
use Bootstrap;
use Exception;
use G;
use Illuminate\Support\Facades\Crypt;
use ProcessMaker\Core\System;
use SpoolRun;
use TemplatePower;
@@ -14,7 +15,7 @@ class EmailServer
{
private $arrayFieldDefinition = array(
"MESS_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "emailServerUid"),
"MESS_ENGINE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("PHPMAILER", "MAIL", "IMAP"), "fieldNameAux" => "emailServerEngine"),
"MESS_ENGINE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("PHPMAILER", "MAIL", "IMAP", "GMAILAPI"), "fieldNameAux" => "emailServerEngine"),
"MESS_SERVER" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerServer"),
"MESS_PORT" => array("type" => "int", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerPort"),
"MESS_INCOMING_SERVER" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerIncomingServer"),
@@ -809,6 +810,13 @@ class EmailServer
$arrayData["MESS_PASSWORD"] = G::encrypt($arrayData["MESS_PASSWORD"], "EMAILENCRYPT");
}
$arrayData["OAUTH_CLIENT_ID"] = !empty($arrayData["OAUTH_CLIENT_ID"]) ?
Crypt::encryptString($arrayData["OAUTH_CLIENT_ID"]) : "";
$arrayData["OAUTH_CLIENT_SECRET"] = !empty($arrayData["OAUTH_CLIENT_SECRET"]) ?
Crypt::encryptString($arrayData["OAUTH_CLIENT_SECRET"]) : "";
$arrayData["OAUTH_REFRESH_TOKEN"] = !empty($arrayData["OAUTH_REFRESH_TOKEN"]) ?
Crypt::encryptString($arrayData["OAUTH_REFRESH_TOKEN"]) : "";
$emailServer->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$emailServerUid = \ProcessMaker\Util\Common::generateUID();
@@ -981,6 +989,13 @@ class EmailServer
}
}
$arrayData["OAUTH_CLIENT_ID"] = !empty($arrayData["OAUTH_CLIENT_ID"]) ?
Crypt::encryptString($arrayData["OAUTH_CLIENT_ID"]) : "";
$arrayData["OAUTH_CLIENT_SECRET"] = !empty($arrayData["OAUTH_CLIENT_SECRET"]) ?
Crypt::encryptString($arrayData["OAUTH_CLIENT_SECRET"]) : "";
$arrayData["OAUTH_REFRESH_TOKEN"] = !empty($arrayData["OAUTH_REFRESH_TOKEN"]) ?
Crypt::encryptString($arrayData["OAUTH_REFRESH_TOKEN"]) : "";
$emailServer->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
if ($emailServer->validate()) {
@@ -1106,6 +1121,9 @@ class EmailServer
$criteria->addSelectColumn(\EmailServerPeer::MESS_TRY_SEND_INMEDIATLY);
$criteria->addSelectColumn(\EmailServerPeer::MAIL_TO);
$criteria->addSelectColumn(\EmailServerPeer::MESS_DEFAULT);
$criteria->addSelectColumn(\EmailServerPeer::OAUTH_CLIENT_ID);
$criteria->addSelectColumn(\EmailServerPeer::OAUTH_CLIENT_SECRET);
$criteria->addSelectColumn(\EmailServerPeer::OAUTH_REFRESH_TOKEN);
return $criteria;
} catch (Exception $e) {
@@ -1124,7 +1142,7 @@ class EmailServer
public function getEmailServerDataFromRecord(array $record)
{
try {
return array(
return [
$this->getFieldNameByFormatFieldName("MESS_UID") => $record["MESS_UID"],
$this->getFieldNameByFormatFieldName("MESS_ENGINE") => $record["MESS_ENGINE"],
$this->getFieldNameByFormatFieldName("MESS_SERVER") => $record["MESS_SERVER"],
@@ -1143,8 +1161,11 @@ class EmailServer
$this->getFieldNameByFormatFieldName("MESS_BACKGROUND") => '',
$this->getFieldNameByFormatFieldName("MESS_PASSWORD_HIDDEN") => '',
$this->getFieldNameByFormatFieldName("MESS_EXECUTE_EVERY") => '',
$this->getFieldNameByFormatFieldName("MESS_SEND_MAX") => ''
);
$this->getFieldNameByFormatFieldName("MESS_SEND_MAX") => '',
$this->getFieldNameByFormatFieldName("OAUTH_CLIENT_ID") => $record["OAUTH_CLIENT_ID"],
$this->getFieldNameByFormatFieldName("OAUTH_CLIENT_SECRET") => $record["OAUTH_CLIENT_SECRET"],
$this->getFieldNameByFormatFieldName("OAUTH_REFRESH_TOKEN") => $record["OAUTH_REFRESH_TOKEN"]
];
} catch (Exception $e) {
throw $e;
}
@@ -1191,6 +1212,12 @@ class EmailServer
$arrayData["MESS_PASSWORD_HIDDEN"] = '';
$arrayData["MESS_EXECUTE_EVERY"] = '';
$arrayData["MESS_SEND_MAX"] = '';
$arrayData["OAUTH_CLIENT_ID"] = !empty($row["OAUTH_CLIENT_ID"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_ID"]) : '';
$arrayData["OAUTH_CLIENT_SECRET"] = !empty($row["OAUTH_CLIENT_SECRET"]) ?
Crypt::decryptString($row["OAUTH_CLIENT_SECRET"]) : '';
$arrayData["OAUTH_REFRESH_TOKEN"] = !empty($row["OAUTH_REFRESH_TOKEN"]) ?
Crypt::decryptString($row["OAUTH_REFRESH_TOKEN"]) : '';
}
//Return
@@ -1287,6 +1314,9 @@ class EmailServer
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$row['OAUTH_CLIENT_ID'] = !empty($row['OAUTH_CLIENT_ID']) ? Crypt::decryptString($row['OAUTH_CLIENT_ID']) : '';
$row['OAUTH_CLIENT_SECRET'] = !empty($row['OAUTH_CLIENT_SECRET']) ? Crypt::decryptString($row['OAUTH_CLIENT_SECRET']) : '';
$row['OAUTH_REFRESH_TOKEN'] = !empty($row['OAUTH_REFRESH_TOKEN']) ? Crypt::decryptString($row['OAUTH_REFRESH_TOKEN']) : '';
$arrayEmailServer[] = $this->getEmailServerDataFromRecord($row);
}
@@ -1340,6 +1370,9 @@ class EmailServer
$row["MESS_PASSWORD_HIDDEN"] = '';
$row["MESS_EXECUTE_EVERY"] = '';
$row["MESS_SEND_MAX"] = '';
$row["OAUTH_CLIENT_ID"] = !empty($row["OAUTH_CLIENT_ID"]) ? Crypt::decryptString($row["OAUTH_CLIENT_ID"]) : '';
$row["OAUTH_CLIENT_SECRET"] = !empty($row["OAUTH_CLIENT_SECRET"]) ? Crypt::decryptString($row["OAUTH_CLIENT_SECRET"]) : '';
$row["OAUTH_REFRESH_TOKEN"] = !empty($row["OAUTH_REFRESH_TOKEN"]) ? Crypt::decryptString($row["OAUTH_REFRESH_TOKEN"]) : '';
//Return
return (!$flagGetRecord)? $this->getEmailServerDataFromRecord($row) : $row;

View File

@@ -1016,7 +1016,10 @@ class System
"MESS_BACKGROUND" => "",
"MESS_PASSWORD_HIDDEN" => "",
"MESS_EXECUTE_EVERY" => "",
"MESS_SEND_MAX" => ""
"MESS_SEND_MAX" => "",
"OAUTH_CLIENT_ID" => $arrayEmailServerDefault["OAUTH_CLIENT_ID"],
"OAUTH_CLIENT_SECRET" => $arrayEmailServerDefault["OAUTH_CLIENT_SECRET"],
"OAUTH_REFRESH_TOKEN" => $arrayEmailServerDefault["OAUTH_REFRESH_TOKEN"]
);
//Return

View File

@@ -0,0 +1,482 @@
<?php
namespace ProcessMaker\GmailOAuth;
use AppMessage;
use Bootstrap;
use G;
use Google_Client;
use Google_Service_Gmail;
use Google_Service_Gmail_Message;
use PHPMailerOAuth;
use ProcessMaker\BusinessModel\EmailServer;
use ProcessMaker\Core\System;
use TemplatePower;
use WsBase;
class GmailOAuth
{
private $emailServerUid;
private $emailEngine;
private $clientID;
private $clientSecret;
private $fromAccount;
private $senderEmail;
private $senderName;
private $sendTestMail;
private $mailTo;
private $setDefaultConfiguration;
private $redirectURI;
private $refreshToken;
/**
* Set $emailServerUid property.
* @param string $emailServerUid
* @return void
*/
public function setEmailServerUid($emailServerUid): void
{
$this->emailServerUid = $emailServerUid;
}
/**
* Set $clientID property.
* @param string $clientID
* @return void
*/
public function setClientID($clientID): void
{
$this->clientID = $clientID;
}
/**
* Set $clientSecret property.
* @param string $clientSecret
* @return void
*/
public function setClientSecret($clientSecret): void
{
$this->clientSecret = $clientSecret;
}
/**
* Set $redirectURI property.
* @param string $redirectURI
* @return void
*/
public function setRedirectURI($redirectURI): void
{
$this->redirectURI = $redirectURI;
}
/**
* Set $emailEngine property.
* @param string $emailEngine
* @return void
*/
public function setEmailEngine($emailEngine): void
{
$this->emailEngine = $emailEngine;
}
/**
* Set $fromAccount property.
* @param string $fromAccount
* @return void
*/
public function setFromAccount($fromAccount): void
{
$this->fromAccount = $fromAccount;
}
/**
* Set $senderEmail property.
* @param string $senderEmail
* @return void
*/
public function setSenderEmail($senderEmail): void
{
$this->senderEmail = $senderEmail;
}
/**
* Set $senderName property.
* @param string $senderName
* @return void
*/
public function setSenderName($senderName): void
{
$this->senderName = $senderName;
}
/**
* Set $sendTestMail property.
* @param string $sendTestMail
* @return void
*/
public function setSendTestMail($sendTestMail): void
{
$this->sendTestMail = $sendTestMail;
}
/**
* Set $mailTo property.
* @param string $mailTo
* @return void
*/
public function setMailTo($mailTo): void
{
$this->mailTo = $mailTo;
}
/**
* Set $setDefaultConfiguration property.
* @param string $setDefaultConfiguration
* @return void
*/
public function setSetDefaultConfiguration($setDefaultConfiguration): void
{
$this->setDefaultConfiguration = $setDefaultConfiguration;
}
/**
* Set $refreshToken property.
* @param string $refreshToken
* @return void
*/
public function setRefreshToken($refreshToken): void
{
$this->refreshToken = $refreshToken;
}
/**
* Get $emailServerUid property.
* @return string
*/
public function getEmailServerUid()
{
return $this->emailServerUid;
}
/**
* Get $clientID property.
* @return string
*/
public function getClientID()
{
return $this->clientID;
}
/**
* Get $clientSecret property.
* @return string
*/
public function getClientSecret()
{
return $this->clientSecret;
}
/**
* Get $redirectURI property.
* @return string
*/
public function getRedirectURI()
{
return $this->redirectURI;
}
/**
* Get $emailEngine property.
* @return string
*/
public function getEmailEngine()
{
return $this->emailEngine;
}
/**
* Get $fromAccount property.
* @return string
*/
public function getFromAccount()
{
return $this->fromAccount;
}
/**
* Get $senderEmail property.
* @return string
*/
public function getSenderEmail()
{
return $this->senderEmail;
}
/**
* Get $senderName property.
* @return string
*/
public function getSenderName()
{
return $this->senderName;
}
/**
* Get $sendTestMail property.
* @return string
*/
public function getSendTestMail()
{
return $this->sendTestMail;
}
/**
* Get $mailTo property.
* @return string
*/
public function getMailTo()
{
return $this->mailTo;
}
/**
* Get $defaultConfiguration property.
* @return string
*/
public function getSetDefaultConfiguration()
{
return $this->setDefaultConfiguration;
}
/**
* Get $refreshToken property.
* @return string
*/
public function getRefreshToken()
{
return $this->refreshToken;
}
/**
* Get a Google_Client object, this may vary depending on the service provider.
* @return Google_Client
*/
public function getGoogleClient(): Google_Client
{
$googleClient = new Google_Client();
$googleClient->setClientId($this->clientID);
$googleClient->setClientSecret($this->clientSecret);
$googleClient->setRedirectUri($this->redirectURI);
$googleClient->setAccessType('offline');
$googleClient->setApprovalPrompt('force');
$googleClient->addScope(Google_Service_Gmail::MAIL_GOOGLE_COM);
return $googleClient;
}
/**
* Save the data in the EmailServer table, and return the stored fields.
* @return array
*/
public function saveEmailServer(): array
{
$result = [];
$data = [
"MESS_ENGINE" => $this->emailEngine,
"OAUTH_CLIENT_ID" => $this->clientID,
"OAUTH_CLIENT_SECRET" => $this->clientSecret,
"OAUTH_REFRESH_TOKEN" => $this->refreshToken,
"MESS_ACCOUNT" => $this->fromAccount,
"MESS_FROM_MAIL" => $this->senderEmail,
"MESS_FROM_NAME" => $this->senderName,
"MESS_TRY_SEND_INMEDIATLY" => $this->sendTestMail,
"MAIL_TO" => $this->mailTo,
"MESS_DEFAULT" => $this->setDefaultConfiguration,
"MESS_RAUTH" => 1,
"SMTPSECURE" => "No",
"MESS_PASSWORD" => "",
"MESS_SERVER" => "smtp.gmail.com",
"MESS_PORT" => "",
"MESS_PASSWORD" => "",
"MESS_INCOMING_SERVER" => "",
"MESS_INCOMING_PORT" => ""
];
$emailServer = new EmailServer();
if (empty($this->emailServerUid)) {
$result = $emailServer->create($data);
} else {
$result = $emailServer->update($this->emailServerUid, $data);
}
return $result;
}
/**
* This sends a test email with Google_Service_Gmail_Message object, as long
* as the test flag is activated.
* @return Google_Service_Gmail_Message
*/
public function sendTestEmailWithGoogleServiceGmail(): Google_Service_Gmail_Message
{
$googleServiceGmailMessage = new Google_Service_Gmail_Message();
if (!filter_var($this->fromAccount, FILTER_VALIDATE_EMAIL)) {
return $googleServiceGmailMessage;
}
if (!filter_var($this->mailTo, FILTER_VALIDATE_EMAIL)) {
return $googleServiceGmailMessage;
}
if ($this->sendTestMail === 0) {
return $googleServiceGmailMessage;
}
$googleClient = $this->getGoogleClient();
$googleClient->refreshToken($this->getRefreshToken());
if ($googleClient->isAccessTokenExpired()) {
$newAccessToken = $googleClient->getAccessToken();
$googleClient->setAccessToken($newAccessToken);
}
$raw = $this->getRawMessage();
$googleServiceGmailMessage->setRaw($raw);
$service = new Google_Service_Gmail($googleClient);
$result = $service->users_messages->send("me", $googleServiceGmailMessage);
return $result;
}
/**
* Get message body.
* @return string
*/
public function getMessageBody(): string
{
$templateTower = new TemplatePower(PATH_TPL . "admin" . PATH_SEP . "email.tpl");
$templateTower->prepare();
$templateTower->assign("server", System::getServerHostname());
$templateTower->assign("date", date("H:i:s"));
$templateTower->assign("ver", System::getVersion());
$templateTower->assign("engine", G::LoadTranslation("ID_MESS_ENGINE_TYPE_4"));
$templateTower->assign("msg", G::LoadTranslation("ID_MESS_TEST_BODY"));
$outputContent = $templateTower->getOutputContent();
return $outputContent;
}
/**
* Get a plain text of the test message.
* @return string
*/
public function getRawMessage(): string
{
$outputContent = $this->getMessageBody();
$strRawMessage = ""
. "From: Email <{$this->fromAccount}> \r\n"
. "To: <{$this->mailTo}>\r\n"
. "Subject: =?utf-8?B?" . base64_encode(G::LoadTranslation("ID_MESS_TEST_SUBJECT")) . "?=\r\n"
. "MIME-Version: 1.0\r\n"
. "Content-Type: text/html; charset=utf-8\r\n"
. "Content-Transfer-Encoding: quoted-printable\r\n\r\n"
. "{$outputContent}\r\n";
$raw = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
return $raw;
}
/**
* This sends a test email with PHPMailerOAuth object, as long
* as the test flag is activated.
* @return PHPMailerOAuth
*/
public function sendTestMailWithPHPMailerOAuth(): PHPMailerOAuth
{
$phpMailerOAuth = new PHPMailerOAuth();
if (!filter_var($this->fromAccount, FILTER_VALIDATE_EMAIL)) {
return $phpMailerOAuth;
}
if (!filter_var($this->mailTo, FILTER_VALIDATE_EMAIL)) {
return $phpMailerOAuth;
}
if ($this->sendTestMail === 0) {
return $phpMailerOAuth;
}
$senderEmail = $this->senderEmail;
if (!filter_var($senderEmail, FILTER_VALIDATE_EMAIL)) {
$senderEmail = $this->fromAccount;
}
if (empty($this->senderName)) {
$this->senderName = "";
}
$phpMailerOAuth->isHTML(true);
$phpMailerOAuth->isSMTP();
$phpMailerOAuth->Host = 'smtp.gmail.com';
$phpMailerOAuth->SMTPAuth = true;
$phpMailerOAuth->AuthType = 'XOAUTH2';
$phpMailerOAuth->oauthUserEmail = $this->fromAccount;
$phpMailerOAuth->oauthClientId = $this->clientID;
$phpMailerOAuth->oauthClientSecret = $this->clientSecret;
$phpMailerOAuth->oauthRefreshToken = $this->refreshToken;
$phpMailerOAuth->SetFrom($senderEmail, $this->senderName);
$phpMailerOAuth->Subject = G::LoadTranslation("ID_MESS_TEST_SUBJECT");
$phpMailerOAuth->Body = utf8_encode($this->getMessageBody());
$phpMailerOAuth->AddAddress($this->mailTo);
$status = $phpMailerOAuth->Send();
$this->saveIntoStandardLogs($status ? "sent" : "pending");
$this->saveIntoAppMessage($status ? "sent" : "pending");
return $phpMailerOAuth;
}
/**
* Register into APP_MESSAGE table.
* @param string $status
*/
public function saveIntoAppMessage(string $status = "")
{
$appMsgUid = G::generateUniqueID();
$spool = new AppMessage();
$spool->setAppMsgUid($appMsgUid);
$spool->setMsgUid("");
$spool->setAppUid("");
$spool->setDelIndex(0);
$spool->setAppMsgType(WsBase::MESSAGE_TYPE_TEST_EMAIL);
$spool->setAppMsgTypeId(isset(AppMessage::$app_msg_type_values[WsBase::MESSAGE_TYPE_TEST_EMAIL]) ? AppMessage::$app_msg_type_values[WsBase::MESSAGE_TYPE_TEST_EMAIL] : 0);
$spool->setAppMsgSubject(G::LoadTranslation("ID_MESS_TEST_SUBJECT"));
$spool->setAppMsgFrom($this->fromAccount);
$spool->setAppMsgTo($this->mailTo);
$spool->setAppMsgBody(utf8_encode($this->getMessageBody()));
$spool->setAppMsgDate(date('Y-m-d H:i:s'));
$spool->setAppMsgCc("");
$spool->setAppMsgBcc("");
$spool->setappMsgAttach(serialize([""]));
$spool->setAppMsgTemplate("");
$spool->setAppMsgStatus($status);
$spool->setAppMsgStatusId(AppMessage::$app_msg_status_values[$status] ? AppMessage::$app_msg_status_values[$status] : 0);
$spool->setAppMsgSendDate(date('Y-m-d H:i:s'));
$spool->setAppMsgShowMessage(1);
$spool->setAppMsgError("");
$spool->setAppNumber(0);
$spool->setTasId(0);
$spool->setProId(0);
$spool->save();
}
/**
* Register into standard logs.
* @param string $status
*/
public function saveIntoStandardLogs(string $status = "")
{
$channel = "Test Email Servers Configuration";
$severity = 200; //INFO
$message = "Email Server test has been sent";
$context = [
"emailServerUid" => $this->emailServerUid,
"emailEngine" => $this->emailEngine,
"from" => $this->fromAccount,
"senderAccount" => $this->mailTo,
"senderEmail" => $this->senderEmail,
"senderName" => $this->senderName,
"status" => $status
];
$workspace = config("system.workspace");
Bootstrap::registerMonolog($channel, $severity, $message, $context, $workspace);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
class AppMessage extends Model
{
protected $table = 'APP_MESSAGE';
public $timestamps = false;
}

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Crypt;
class EmailServerModel extends Model
{
@@ -31,13 +32,25 @@ class EmailServerModel extends Model
'EMAIL_SERVER.SMTPSECURE',
'EMAIL_SERVER.MESS_TRY_SEND_INMEDIATLY',
'EMAIL_SERVER.MAIL_TO',
'EMAIL_SERVER.MESS_DEFAULT'
'EMAIL_SERVER.MESS_DEFAULT',
'EMAIL_SERVER.OAUTH_CLIENT_ID',
'EMAIL_SERVER.OAUTH_CLIENT_SECRET',
'EMAIL_SERVER.OAUTH_REFRESH_TOKEN'
];
$query = EmailServerModel::query()->select($selectedColumns);
$query->where('EMAIL_SERVER.MESS_UID', '=', $messUid);
$res = $query->get()->values()->toArray();
$firstElement = head($res);
if (!empty($firstElement)) {
$firstElement['OAUTH_CLIENT_ID'] = !empty($firstElement['OAUTH_CLIENT_ID']) ?
Crypt::decryptString($firstElement['OAUTH_CLIENT_ID']) : '';
$firstElement['OAUTH_CLIENT_SECRET'] = !empty($firstElement['OAUTH_CLIENT_SECRET']) ?
Crypt::decryptString($firstElement['OAUTH_CLIENT_SECRET']) : '';
$firstElement['OAUTH_REFRESH_TOKEN'] = !empty($firstElement['OAUTH_REFRESH_TOKEN']) ?
Crypt::decryptString($firstElement['OAUTH_REFRESH_TOKEN']) : '';
}
return $firstElement;
}
@@ -64,7 +77,10 @@ class EmailServerModel extends Model
'EMAIL_SERVER.SMTPSECURE',
'EMAIL_SERVER.MESS_TRY_SEND_INMEDIATLY',
'EMAIL_SERVER.MAIL_TO',
'EMAIL_SERVER.MESS_DEFAULT'
'EMAIL_SERVER.MESS_DEFAULT',
'EMAIL_SERVER.OAUTH_CLIENT_ID',
'EMAIL_SERVER.OAUTH_CLIENT_SECRET',
'EMAIL_SERVER.OAUTH_REFRESH_TOKEN'
];
$query = EmailServerModel::query()->select($selectedColumns)
->where('MESS_DEFAULT', '=', 1);
@@ -77,6 +93,12 @@ class EmailServerModel extends Model
$firstElement['MESS_PASSWORD_HIDDEN'] = '';
$firstElement['MESS_EXECUTE_EVERY'] = '';
$firstElement['MESS_SEND_MAX'] = '';
$firstElement['OAUTH_CLIENT_ID'] = !empty($firstElement['OAUTH_CLIENT_ID']) ?
Crypt::decryptString($firstElement['OAUTH_CLIENT_ID']) : '';
$firstElement['OAUTH_CLIENT_SECRET'] = !empty($firstElement['OAUTH_CLIENT_SECRET']) ?
Crypt::decryptString($firstElement['OAUTH_CLIENT_SECRET']) : '';
$firstElement['OAUTH_REFRESH_TOKEN'] = !empty($firstElement['OAUTH_REFRESH_TOKEN']) ?
Crypt::decryptString($firstElement['OAUTH_REFRESH_TOKEN']) : '';
}
return $firstElement;

View File

@@ -25,8 +25,6 @@ emailServer.application = {
case "DEL":
msg = _("ID_EMAIL_SERVER_DELETE_DATA");
break;
//case "LST":
// break;
case "TEST":
msg = _("ID_EMAIL_SERVER_TEST_DATA");
break;
@@ -40,9 +38,9 @@ emailServer.application = {
/*----------------------------------********---------------------------------*/
if (Ext.getCmp("chkEmailServerDefault").checked) {
/*----------------------------------********---------------------------------*/
/*----------------------------------********---------------------------------*/
var emailDefault = 1;
/*----------------------------------********---------------------------------*/
/*----------------------------------********---------------------------------*/
} else {
var emailDefault = 0;
}
@@ -102,7 +100,7 @@ emailServer.application = {
cboEmailEngine: typeEmailEngine,
fromMail: Ext.getCmp("txtFromMail").getValue(),
fromName: Ext.getCmp("txtFromName").getValue(),
sendTestMail: (Ext.getCmp("chkSendTestMail").checked)? 1 : 0,
sendTestMail: (Ext.getCmp("chkSendTestMail").checked) ? 1 : 0,
mailTo: Ext.getCmp("txtMailTo").getValue(),
emailServerDefault: emailDefault
};
@@ -156,9 +154,6 @@ emailServer.application = {
}
}
break;
//case "LST":
// break;
case "TEST":
showTestConnection(typeEmailEngine, dataResponse.data);
@@ -213,6 +208,8 @@ emailServer.application = {
emailServerSetMailTo(Ext.getCmp("chkSendTestMail").checked);
Ext.getCmp("txtMailTo").setValue("");
Ext.getCmp("textClientId").setValue("");
Ext.getCmp("textClientSecret").setValue("");
/*----------------------------------********---------------------------------*/
Ext.getCmp("chkEmailServerDefault").setValue(false);
@@ -229,19 +226,19 @@ emailServer.application = {
case "UPD":
var record = grdpnlMain.getSelectionModel().getSelected();
if (typeof(record) != "undefined") {
if (typeof (record) != "undefined") {
Ext.getCmp("emailServerUid").setValue(record.get("MESS_UID"));
Ext.getCmp("cboEmailEngine").setValue(record.get("MESS_ENGINE"));
emailServerSetEmailEngine(record.get("MESS_ENGINE"));
Ext.getCmp("txtServer").setValue(record.get("MESS_SERVER"));
Ext.getCmp("txtPort").setValue((record.get("MESS_PORT") != 0)? record.get("MESS_PORT") : "");
Ext.getCmp("txtPort").setValue((record.get("MESS_PORT") != 0) ? record.get("MESS_PORT") : "");
Ext.getCmp("txtIncomingServer").setValue(record.get("MESS_INCOMING_SERVER"));
Ext.getCmp("txtIncomingPort").setValue((record.get("MESS_INCOMING_PORT") !== 0)? record.get("MESS_INCOMING_PORT") : "");
Ext.getCmp("txtIncomingPort").setValue((record.get("MESS_INCOMING_PORT") !== 0) ? record.get("MESS_INCOMING_PORT") : "");
Ext.getCmp("chkReqAuthentication").setValue((parseInt(record.get("MESS_RAUTH")) == 1)? true : false);
Ext.getCmp("chkReqAuthentication").setValue((parseInt(record.get("MESS_RAUTH")) == 1) ? true : false);
emailServerSetPassword(Ext.getCmp("chkReqAuthentication").checked);
@@ -250,17 +247,19 @@ emailServer.application = {
Ext.getCmp("txtFromMail").setValue(record.get("MESS_FROM_MAIL"));
Ext.getCmp("txtFromName").setValue(record.get("MESS_FROM_NAME"));
Ext.getCmp("rdoGrpSmtpSecure").setValue((record.get("SMTPSECURE") != "")? record.get("SMTPSECURE") : "No");
Ext.getCmp("chkSendTestMail").setValue((parseInt(record.get("MESS_TRY_SEND_INMEDIATLY")) == 1)? true : false);
Ext.getCmp("rdoGrpSmtpSecure").setValue((record.get("SMTPSECURE") != "") ? record.get("SMTPSECURE") : "No");
Ext.getCmp("chkSendTestMail").setValue((parseInt(record.get("MESS_TRY_SEND_INMEDIATLY")) == 1) ? true : false);
emailServerSetMailTo(Ext.getCmp("chkSendTestMail").checked);
Ext.getCmp("txtMailTo").setValue(record.get("MAIL_TO"));
Ext.getCmp("textClientId").setValue(record.get("OAUTH_CLIENT_ID"));
Ext.getCmp("textClientSecret").setValue(record.get("OAUTH_CLIENT_SECRET"));
/*----------------------------------********---------------------------------*/
if (parseInt(record.get("MESS_DEFAULT")) == 1) {
/*----------------------------------********---------------------------------*/
/*----------------------------------********---------------------------------*/
Ext.getCmp("chkEmailServerDefault").setValue(true);
/*----------------------------------********---------------------------------*/
/*----------------------------------********---------------------------------*/
} else {
Ext.getCmp("chkEmailServerDefault").setValue(false);
}
@@ -278,6 +277,12 @@ emailServer.application = {
{
Ext.getCmp("frmEmailServer").getForm().clearInvalid();
Ext.getCmp("textClientId").setVisible(false);
Ext.getCmp("textClientSecret").setVisible(false);
Ext.getCmp("buttonContinue").setVisible(false);
Ext.getCmp("btnTest").setVisible(true);
Ext.getCmp("btnSave").setVisible(true);
if (cboEmailEngine === "PHPMAILER") {
Ext.getCmp("txtServer").setVisible(true);
Ext.getCmp("txtPort").setVisible(true);
@@ -334,6 +339,29 @@ emailServer.application = {
Ext.getCmp("txtIncomingPort").allowBlank = false;
Ext.getCmp("txtAccountFrom").allowBlank = false;
/*----------------------------------********---------------------------------*/
} else if (cboEmailEngine === "GMAILAPI") {
Ext.getCmp("txtServer").setVisible(false);
Ext.getCmp("txtPort").setVisible(false);
Ext.getCmp("txtIncomingServer").setVisible(false);
Ext.getCmp("txtIncomingPort").setVisible(false);
Ext.getCmp("chkReqAuthentication").setVisible(false);
Ext.getCmp("rdoGrpSmtpSecure").setVisible(false);
Ext.getCmp("btnTest").setVisible(false);
Ext.getCmp("btnSave").setVisible(false);
Ext.getCmp("txtAccountFrom").setVisible(true);
Ext.getCmp("textClientId").setVisible(true);
Ext.getCmp("textClientSecret").setVisible(true);
Ext.getCmp("buttonContinue").setVisible(true);
emailServerSetPassword(false);
Ext.getCmp("txtServer").allowBlank = true;
Ext.getCmp("txtPort").allowBlank = true;
Ext.getCmp("txtIncomingServer").allowBlank = true;
Ext.getCmp("txtIncomingPort").allowBlank = true;
Ext.getCmp("txtAccountFrom").allowBlank = false;
Ext.getCmp("txtPassword").allowBlank = true;
} else {
//MAIL
Ext.getCmp("txtServer").setVisible(false);
@@ -360,7 +388,7 @@ emailServer.application = {
function emailServerSetPassword(flagPassChecked)
{
if (flagPassChecked) {
if (flagPassChecked && Ext.getCmp("cboEmailEngine").getValue() !== 'GMAILAPI') {
Ext.getCmp("txtPassword").setVisible(true);
Ext.getCmp("txtPassword").allowBlank = false;
} else {
@@ -387,67 +415,67 @@ emailServer.application = {
FLAGTEST = 1;
if (option === "PHPMAILER" || option === "IMAP") {
if (typeof(testData.resolving_name) != "undefined") {
if (typeof (testData.resolving_name) != "undefined") {
if (testData.resolving_name.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.resolving_name.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.resolving_name.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.resolving_name.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.resolving_name.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.resolving_name.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.resolving_name.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.check_port) != "undefined") {
if (typeof (testData.check_port) != "undefined") {
if (testData.check_port.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.check_port.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.check_port.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.check_port.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.check_port.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.check_port.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.check_port.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.establishing_connection_host) != "undefined") {
if (typeof (testData.establishing_connection_host) != "undefined") {
if (testData.establishing_connection_host.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.establishing_connection_host.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.establishing_connection_host.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.establishing_connection_host.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.establishing_connection_host.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.establishing_connection_host.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.establishing_connection_host.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.login) != "undefined") {
if (typeof (testData.login) != "undefined") {
if (testData.login.result != "") {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.login.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.login.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.login.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.login.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.login.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.login.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.sending_email) != "undefined") {
if (typeof (testData.sending_email) != "undefined") {
if (testData.sending_email.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.sending_email.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.sending_email.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.sending_email.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.sending_email.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.sending_email.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.sending_email.message + "</span><br />";
FLAGTEST = 0;
}
}
} else {
//MAIL
if (typeof(testData.verifying_mail) != "undefined") {
if (typeof (testData.verifying_mail) != "undefined") {
if (testData.verifying_mail.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em;\" />" + testData.verifying_mail.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em;\" />" + testData.verifying_mail.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.verifying_mail.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.verifying_mail.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.verifying_mail.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.verifying_mail.message + "</span><br />";
FLAGTEST = 0;
}
}
if (typeof(testData.sending_email) != "undefined") {
if (typeof (testData.sending_email) != "undefined") {
if (testData.sending_email.result) {
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.sending_email.title + "<br />";
msg = msg + "<img src = \"/images/select-icon.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em; color: #0000FF;\" />" + testData.sending_email.title + "<br />";
} else {
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.sending_email.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.sending_email.message + "</span><br />";
msg = msg + "<img src = \"/images/error.png\" width=\"21\" height=\"21\" style=\"margin-right: 0.6em;\" />" + testData.sending_email.title + "<br /><span style=\"margin-left:2.3em; color: #0000FF;\">" + testData.sending_email.message + "</span><br />";
FLAGTEST = 0;
}
}
@@ -504,7 +532,9 @@ emailServer.application = {
{name: "SMTPSECURE", type: "string"},
{name: "MESS_TRY_SEND_INMEDIATLY", type: "int"},
{name: "MAIL_TO", type: "string"},
{name: "MESS_DEFAULT", type: "int"}
{name: "MESS_DEFAULT", type: "int"},
{name: "OAUTH_CLIENT_ID", type: "string"},
{name: "OAUTH_CLIENT_SECRET", type: "string"}
]
}),
@@ -540,7 +570,7 @@ emailServer.application = {
var emailUrlValidationText = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))|((([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$/i;
Ext.apply(Ext.form.VTypes, {
emailUrlValidation: function(val, field)
emailUrlValidation: function (val, field)
{
return emailUrlValidationText.test(val);
}
@@ -555,7 +585,8 @@ emailServer.application = {
/*----------------------------------********---------------------------------*/
["IMAP", "SMTP - IMAP (PHPMailer)"],
/*----------------------------------********---------------------------------*/
["MAIL", "Mail (PHP)"]
["MAIL", "Mail (PHP)"],
["GMAILAPI", "GMAIL API (PHPMailer)"]
]
});
@@ -579,7 +610,7 @@ emailServer.application = {
forceSelection: true,
listeners: {
select: function(combo, value)
select: function (combo, value)
{
emailServerSetEmailEngine(Ext.getCmp("cboEmailEngine").getValue());
}
@@ -597,7 +628,7 @@ emailServer.application = {
id: "txtPort",
name: "txtPort",
fieldLabel: _("PORT_DEFAULT"), //Port (default 25)
fieldLabel: _("PORT_DEFAULT"), //Port (default 25)
anchor: "36%",
maxLength: 3,
@@ -615,7 +646,7 @@ emailServer.application = {
id: "txtIncomingPort",
name: "txtIncomingPort",
fieldLabel: _("INCOMING_PORT_DEFAULT"), //Port (default 993)
fieldLabel: _("INCOMING_PORT_DEFAULT"), //Port (default 993)
anchor: "36%",
maxLength: 3,
@@ -628,7 +659,7 @@ emailServer.application = {
boxLabel: _("REQUIRE_AUTHENTICATION"), //Require authentication
handler: function()
handler: function ()
{
emailServerSetPassword(this.checked);
}
@@ -680,7 +711,7 @@ emailServer.application = {
vertical: true,
items: [
{boxLabel: "No", inputValue: "No", name: "rdoGrpSmtpSecure", checked: true},
{boxLabel: "No", inputValue: "No", name: "rdoGrpSmtpSecure", checked: true},
{boxLabel: "TLS", inputValue: "tls", name: "rdoGrpSmtpSecure"},
{boxLabel: "SSL", inputValue: "ssl", name: "rdoGrpSmtpSecure"}
]
@@ -692,7 +723,7 @@ emailServer.application = {
boxLabel: _("SEND_TEST_MAIL"), //Send a test mail
handler: function()
handler: function ()
{
emailServerSetMailTo(this.checked);
}
@@ -756,66 +787,140 @@ emailServer.application = {
var btnCancel = new Ext.Action({
id: "btnCancel",
text: _("ID_CANCEL"),
width: 85,
disabled: false,
handler: function ()
{
handler: function () {
Ext.getCmp("frmEmailServer").setVisible(true);
winData.hide();
}
});
var textClientId = new Ext.form.TextField({
id: "textClientId",
name: "textClientId",
fieldLabel: _("ID_CLIENT_ID")
});
var textClientSecret = new Ext.form.TextField({
id: "textClientSecret",
name: "textClientSecret",
fieldLabel: _("ID_CLIENT_SECRET")
});
var buttonContinue = new Ext.Action({
id: 'buttonContinue',
text: _("ID_CONTINUE"),
width: 85,
handler: function () {
var frmEmailServer, parameters;
frmEmailServer = Ext.getCmp("frmEmailServer");
if (frmEmailServer.getForm().isValid()) {
winData.setDisabled(true);
parameters = {
option: 'createAuthUrl',
emailEngine: Ext.getCmp("cboEmailEngine").getValue(),
clientID: Ext.getCmp("textClientId").getValue(),
clientSecret: Ext.getCmp("textClientSecret").getValue(),
fromAccount: Ext.getCmp("txtAccountFrom").getValue(),
senderEmail: Ext.getCmp("txtFromMail").getValue(),
senderName: Ext.getCmp("txtFromName").getValue(),
sendTestMail: (Ext.getCmp("chkSendTestMail").checked) ? 1 : 0,
mailTo: Ext.getCmp("txtMailTo").getValue(),
setDefaultConfiguration: Ext.getCmp("chkEmailServerDefault").checked ? 1 : 0
};
if (EMAILSERVEROPTION === "UPD") {
parameters.emailServerUid = Ext.getCmp("emailServerUid").getValue();
}
Ext.Ajax.request({
url: "emailServerAjax",
method: "POST",
params: parameters,
success: function (response) {
winData.setDisabled(false);
var dataResponse = Ext.util.JSON.decode(response.responseText);
if (dataResponse.status === 200) {
if (window.parent.parent) {
window.parent.parent.location = dataResponse.data;
} else if (window.parent) {
window.parent.location = dataResponse.data;
} else {
window.location = dataResponse.data;
}
} else {
Ext.MessageBox.show({
title: _("ID_ERROR"),
icon: Ext.MessageBox.ERROR,
msg: dataResponse.message,
buttons: {ok: _("ID_ACCEPT")}
});
}
},
failure: function () {
winData.setDisabled(false);
Ext.MessageBox.show({
title: _("ID_ERROR"),
icon: Ext.MessageBox.ERROR,
msg: "",
buttons: {ok: _("ID_ACCEPT")}
});
}
});
} else {
Ext.MessageBox.alert(_("ID_INVALID_DATA"), _("ID_CHECK_FIELDS_MARK_RED"));
}
}
});
var frmEmailServer = new Ext.FormPanel({
id: "frmEmailServer",
frame: true,
labelAlign: "right",
labelWidth: 150,
autoWidth: true,
autoScroll: false,
defaults: {width: 325},
items: [
{
xtype: "hidden",
id: "emailServerUid",
name: "emailServerUid"
},
cboEmailEngine,
txtServer,
txtPort,
txtIncomingServer,
txtIncomingPort,
chkReqAuthentication,
textClientId,
textClientSecret,
txtAccountFrom,
txtPassword,
txtFromMail,
txtFromName,
rdoGrpSmtpSecure,
chkSendTestMail,
txtMailTo
/*----------------------------------********---------------------------------*/
, chkEmailServerDefault
/*----------------------------------********---------------------------------*/
]
});
//Components
var winData = new Ext.Window({
layout: "fit",
width: 550,
height: 450,
//title: "",
modal: true,
resizable: false,
closeAction: "hide",
items: [
new Ext.FormPanel({
id: "frmEmailServer",
frame: true,
labelAlign: "right",
labelWidth: 150,
autoWidth: true,
autoScroll: false,
defaults: {width: 325},
items: [
{
xtype: "hidden",
id: "emailServerUid",
name: "emailServerUid"
},
cboEmailEngine,
txtServer,
txtPort,
txtIncomingServer,
txtIncomingPort,
chkReqAuthentication,
txtAccountFrom,
txtPassword,
txtFromMail,
txtFromName,
rdoGrpSmtpSecure,
chkSendTestMail,
txtMailTo
/*----------------------------------********---------------------------------*/
, chkEmailServerDefault
/*----------------------------------********---------------------------------*/
]
})
],
buttons: [btnTest, btnSave, btnCancel]
items: [frmEmailServer],
buttons: [buttonContinue, btnTest, btnSave, btnCancel]
});
winData.show();
winData.hide();
var winTestConnection = new Ext.Window({
layout: "fit",
@@ -906,7 +1011,7 @@ emailServer.application = {
{
var record = grdpnlMain.getSelectionModel().getSelected();
if (typeof(record) != "undefined") {
if (typeof (record) != "undefined") {
Ext.getCmp("btnSave").disable();
EMAILSERVEROPTION = "UPD";
@@ -927,18 +1032,18 @@ emailServer.application = {
{
var record = grdpnlMain.getSelectionModel().getSelected();
if (typeof(record) != "undefined") {
if (typeof (record) != "undefined") {
Ext.MessageBox.confirm(
_("ID_CONFIRM"),
_("ID_EMAIL_SERVER_DELETE_WARNING_MESSAGE"),
function (btn)
{
if (btn == "yes") {
EMAILSERVEROPTION = "DEL";
emailServerProcessAjax(EMAILSERVEROPTION, record.get("MESS_UID"));
_("ID_CONFIRM"),
_("ID_EMAIL_SERVER_DELETE_WARNING_MESSAGE"),
function (btn) {
if (btn == "yes") {
EMAILSERVEROPTION = "DEL";
Ext.getCmp("cboEmailEngine").setValue(record.get("MESS_ENGINE"));
Ext.getCmp("rdoGrpSmtpSecure").setValue((record.get("SMTPSECURE") != "") ? record.get("SMTPSECURE") : "No");
emailServerProcessAjax(EMAILSERVEROPTION, record.get("MESS_UID"));
}
}
}
);
}
}
@@ -1016,32 +1121,32 @@ emailServer.application = {
var rendererMessServer = function (value)
{
return (value != "")? value : "-";
return (value != "") ? value : "-";
};
var rendererMessPort = function (value)
{
return (value != 0)? value : "-";
return (value != 0) ? value : "-";
};
var rendererMessIncomingServer = function (value)
{
return (value !== "")? value : "-";
return (value !== "") ? value : "-";
};
var rendererMessIncomingPort = function (value)
{
return (value !== 0)? value : "-";
return (value !== 0) ? value : "-";
};
var rendererMessSmtpSecure = function (value)
{
return (value != "")? value : "-";
return (value != "") ? value : "-";
};
var rendererMessDefault = function (value)
{
return (value == 1)? "<img src = \"/images/ext/default/saved.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em;\" />" : "";
return (value == 1) ? "<img src = \"/images/ext/default/saved.png\" width=\"17\" height=\"17\" style=\"margin-right: 0.9em;\" />" : "";
};
var cmodel = new Ext.grid.ColumnModel({
@@ -1050,20 +1155,20 @@ emailServer.application = {
},
columns: [
{id: "MESS_UID", dataIndex: "MESS_UID", hidden: true, header: "uid_emailServer", width: 0, hideable: false, align: "left"},
{id: "MESS_UID", dataIndex: "MESS_UID", hidden: true, header: "uid_emailServer", width: 0, hideable: false, align: "left"},
{id: "MESS_ENGINE", dataIndex: "MESS_ENGINE", hidden: false, header: _("EMAIL_ENGINE"), width: 80, hideable: true, align: "left"},
{id: "MESS_SERVER", dataIndex: "MESS_SERVER", hidden: false, header: _("ID_SERVER"), width: 150, hideable: true, align: "center", renderer: rendererMessServer},
{id: "MESS_PORT", dataIndex: "MESS_PORT", hidden: false, header: _("ID_EMAIL_SERVER_PORT"), width: 50, hideable: true, align: "center", renderer: rendererMessPort},
{id: "MESS_PORT", dataIndex: "MESS_PORT", hidden: false, header: _("ID_EMAIL_SERVER_PORT"), width: 50, hideable: true, align: "center", renderer: rendererMessPort},
{id: "MESS_INCOMING_SERVER", dataIndex: "MESS_INCOMING_SERVER", hidden: true, header: _("ID_INCOMING_SERVER"), width: 150, hideable: true, align: "center", renderer: rendererMessIncomingServer},
{id: "MESS_INCOMING_PORT", dataIndex: "MESS_INCOMING_PORT", hidden: true, header: _("ID_EMAIL_SERVER_PORT"), width: 50, hideable: true, align: "center", renderer: rendererMessIncomingPort},
{id: "MESS_RAUTH", dataIndex: "MESS_RAUTH", hidden: true, header: _("REQUIRE_AUTHENTICATION"), width: 50, hideable: false, align: "left"},
{id: "MESS_ACCOUNT", dataIndex: "MESS_ACCOUNT", hidden: false, header: _("ID_EMAIL_SERVER_ACCOUNT_FROM"), width: 130, hideable: true, align: "left"},
{id: "MESS_PASSWORD", dataIndex: "MESS_PASSWORD", hidden: true, header: _("ID_PASSWORD"), width: 130, hideable: false, align: "left"},
{id: "MESS_INCOMING_PORT", dataIndex: "MESS_INCOMING_PORT", hidden: true, header: _("ID_EMAIL_SERVER_PORT"), width: 50, hideable: true, align: "center", renderer: rendererMessIncomingPort},
{id: "MESS_RAUTH", dataIndex: "MESS_RAUTH", hidden: true, header: _("REQUIRE_AUTHENTICATION"), width: 50, hideable: false, align: "left"},
{id: "MESS_ACCOUNT", dataIndex: "MESS_ACCOUNT", hidden: false, header: _("ID_EMAIL_SERVER_ACCOUNT_FROM"), width: 130, hideable: true, align: "left"},
{id: "MESS_PASSWORD", dataIndex: "MESS_PASSWORD", hidden: true, header: _("ID_PASSWORD"), width: 130, hideable: false, align: "left"},
{id: "MESS_FROM_MAIL", dataIndex: "MESS_FROM_MAIL", hidden: false, header: _("ID_FROM_EMAIL"), width: 130, hideable: true, align: "left"},
{id: "MESS_FROM_NAME", dataIndex: "MESS_FROM_NAME", hidden: false, header: _("ID_FROM_NAME"), width: 150, hideable: true, align: "left"},
{id: "SMTPSECURE", dataIndex: "SMTPSECURE", hidden: false, header: _("USE_SECURE_CONNECTION"), width: 140, hideable: true, align: "center", renderer: rendererMessSmtpSecure},
{id: "MESS_TRY_SEND_INMEDIATLY", dataIndex: "MESS_TRY_SEND_INMEDIATLY", hidden: true, header: _("SEND_TEST_MAIL"), width: 50, hideable: false, align: "left"},
{id: "MAIL_TO", dataIndex: "MAIL_TO", hidden: false, header: _("MAIL_TO"), width: 150, hideable: true, align: "left"},
{id: "MESS_TRY_SEND_INMEDIATLY", dataIndex: "MESS_TRY_SEND_INMEDIATLY", hidden: true, header: _("SEND_TEST_MAIL"), width: 50, hideable: false, align: "left"},
{id: "MAIL_TO", dataIndex: "MAIL_TO", hidden: false, header: _("MAIL_TO"), width: 150, hideable: true, align: "left"},
{id: "MESS_DEFAULT", dataIndex: "MESS_DEFAULT", hidden: false, header: _("ID_EMAIL_SERVER_DEFAULT"), width: 50, hideable: true, align: "center", renderer: rendererMessDefault}
]
});
@@ -1129,7 +1234,7 @@ emailServer.application = {
{
var record = grdpnlMain.getSelectionModel().getSelected();
if (typeof(record) != "undefined") {
if (typeof (record) != "undefined") {
Ext.getCmp("btnSave").disable();
EMAILSERVEROPTION = "UPD";
@@ -1157,14 +1262,14 @@ emailServer.application = {
//Initialize events
grdpnlMain.on(
"rowcontextmenu",
function (grid, rowIndex, evt)
{
var sm = grid.getSelectionModel();
sm.selectRow(rowIndex, sm.isSelected(rowIndex));
},
this
);
"rowcontextmenu",
function (grid, rowIndex, evt)
{
var sm = grid.getSelectionModel();
sm.selectRow(rowIndex, sm.isSelected(rowIndex));
},
this
);
grdpnlMain.addListener("rowcontextmenu", onMnuContext, this);
@@ -1178,6 +1283,10 @@ emailServer.application = {
autoScroll: false,
items: [grdpnlMain]
});
if (errorMessageIfNotAuthenticate && errorMessageIfNotAuthenticate !== "") {
Ext.MessageBox.alert(_("ID_INVALID_DATA"), errorMessageIfNotAuthenticate);
}
}
}