summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-05-14 09:51:41 +0100
committerLester Caine <lester@lsces.co.uk>2026-05-14 09:51:41 +0100
commit72119ef864e1a5ffa377a504dc2ef430d7e6cd4a (patch)
tree24a4b9539cf4f4b8116bd38d3444001843cb8e45
parent72312119fe678d14b61e3c508db98a6dd0ee4ec0 (diff)
downloadcontact-72119ef864e1a5ffa377a504dc2ef430d7e6cd4a.tar.gz
contact-72119ef864e1a5ffa377a504dc2ef430d7e6cd4a.tar.bz2
contact-72119ef864e1a5ffa377a504dc2ef430d7e6cd4a.zip
php-cs-fixer tidies to php8.5 standards
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rwxr-xr-xadd_xref.php16
-rwxr-xr-xadd_xref_address.php4
-rwxr-xr-xadmin/admin_contact_inc.php4
-rwxr-xr-xadmin/admin_contact_type.php3
-rwxr-xr-xadmin/admin_xref_types.php3
-rwxr-xr-xadmin/schema_inc.php20
-rwxr-xr-xedit.php6
-rwxr-xr-xedit_key_break.php4
-rwxr-xr-xedit_notes.php6
-rwxr-xr-xedit_xref.php8
-rwxr-xr-xedit_xref_type.php6
-rwxr-xr-xform.php6
-rwxr-xr-ximport/ContactOld.php74
-rwxr-xr-ximport/ImportContact.php10
-rwxr-xr-ximport/ImportContact2.php50
-rwxr-xr-ximport/ImportPhx.php6
-rwxr-xr-ximport/ImportPhx2.php10
-rwxr-xr-ximport/ImportSage.php10
-rwxr-xr-ximport/ImportWande.php10
-rwxr-xr-ximport/Mbox.php1387
-rwxr-xr-ximport/load_contacts.php4
-rwxr-xr-ximport/load_phx_contacts.php4
-rwxr-xr-ximport/load_sage_contacts.php8
-rwxr-xr-ximport/load_wande_contacts.php4
-rwxr-xr-ximport/mime.php2471
-rwxr-xr-ximport/mimeDecode.php1583
-rwxr-xr-ximport/mimePart.php2019
-rwxr-xr-ximport/modify.php26
-rwxr-xr-ximport/phail.php36
-rwxr-xr-ximport/read.php24
-rwxr-xr-ximport/schema_import_inc.php4
-rwxr-xr-xincludes/bit_setup_inc.php2
-rwxr-xr-xincludes/classes/Contact.php89
-rwxr-xr-xincludes/classes/ContactType.php17
-rwxr-xr-xincludes/classes/ContactXref.php49
-rwxr-xr-xincludes/classes/ContactXrefType.php17
-rwxr-xr-xincludes/lookup_contact_inc.php2
-rwxr-xr-xincludes/lookup_contact_xref_type_inc.php2
-rwxr-xr-xindex.php2
-rwxr-xr-xlib/phpcoord-2.3.php35
-rwxr-xr-xlib/test-2.3.php89
-rwxr-xr-xlist.php2
-rwxr-xr-xlist1.php2
-rwxr-xr-xlist2.php2
-rwxr-xr-xlist_contacts.php5
-rwxr-xr-xlist_contracts.php4
-rwxr-xr-xload_emails.php18
-rwxr-xr-xload_sage_contacts.php8
-rwxr-xr-xmodules/index.php2
-rwxr-xr-xprocess.php4
-rwxr-xr-xtemplates/index.php2
-rwxr-xr-xview_xref.php10
52 files changed, 4067 insertions, 4122 deletions
diff --git a/add_xref.php b/add_xref.php
index 7cbdf9c..749d6f4 100755
--- a/add_xref.php
+++ b/add_xref.php
@@ -30,18 +30,18 @@ if (isset($_REQUEST["fCancel"])) {
} elseif (isset($_REQUEST["fAddXref"])) {
$source = $_REQUEST["source"];
$format = $_REQUEST["format-".$source];
- if ( $format != 'generic' ) {
- if ( isset( $_REQUEST[$format."xref"] ) ) { $_REQUEST["xref"] = $_REQUEST[$format."xref"]; }
- if ( isset( $_REQUEST[$format."xkey"] ) ) { $_REQUEST["xkey"] = $_REQUEST[$format."xkey"]; }
- if ( isset( $_REQUEST[$format."xkey_ext"] ) ) { $_REQUEST["xkey_ext"] = $_REQUEST[$format."xkey_ext"]; }
- }
+ if ( $format != 'generic' ) {
+ if ( isset( $_REQUEST[$format."xref"] ) ) { $_REQUEST["xref"] = $_REQUEST[$format."xref"]; }
+ if ( isset( $_REQUEST[$format."xkey"] ) ) { $_REQUEST["xkey"] = $_REQUEST[$format."xkey"]; }
+ if ( isset( $_REQUEST[$format."xkey_ext"] ) ) { $_REQUEST["xkey_ext"] = $_REQUEST[$format."xkey_ext"]; }
+ }
if( $gContent->storeXref( $_REQUEST ) ) {
header("Location: ".$gContent->getDisplayUrl() );
die;
- } else {
+ }
$xrefInfo = $_REQUEST;
$xrefInfo['data'] = &$_REQUEST['edit'];
- }
+
}
if( !isset( $_REQUEST['xref_type'] ) ) $_REQUEST['xref_type'] = 0;
@@ -68,4 +68,4 @@ $gBitSmarty->assign( 'xrefInfo', $xrefInfo );
$gBitSmarty->assign( 'title', $gContent->mInfo['title'] );
$gBitSmarty->assign( 'errors', $gContent->mErrors );
-$gBitSystem->display( 'bitpackage:contact/add_xref.tpl', 'Edit: ' , array( 'display_mode' => 'edit' ));
+$gBitSystem->display( 'bitpackage:contact/add_xref.tpl', 'Edit: ' , [ 'display_mode' => 'edit' ]);
diff --git a/add_xref_address.php b/add_xref_address.php
index 1c0d2cd..bc9e471 100755
--- a/add_xref_address.php
+++ b/add_xref_address.php
@@ -34,7 +34,7 @@ if (isset($_REQUEST["fCancel"])) {
$xrefInfo = $_REQUEST;
$xrefInfo['data'] = &$_REQUEST['edit'];
}
-}
+}
$_REQUEST['xref_type'] = 10;
@@ -56,4 +56,4 @@ $gBitSmarty->assign( 'xrefInfo', $xrefInfo );
$gBitSmarty->assign( 'title', $gContent->mInfo['title'] );
$gBitSmarty->assign( 'errors', $gContent->mErrors );
-$gBitSystem->display( 'bitpackage:contact/add_xref_address.tpl', 'Edit: ' , array( 'display_mode' => 'edit' ));
+$gBitSystem->display( 'bitpackage:contact/add_xref_address.tpl', 'Edit: ' , [ 'display_mode' => 'edit' ]);
diff --git a/admin/admin_contact_inc.php b/admin/admin_contact_inc.php
index 69a43b9..5ea1ae2 100755
--- a/admin/admin_contact_inc.php
+++ b/admin/admin_contact_inc.php
@@ -50,14 +50,14 @@ asort($contactTypeDefaults);
$gBitSmarty->assign('contactTypeDefaults', $contactTypeDefaults);
if (isset($_REQUEST["contactlistfeatures"])) {
-
+
foreach( $formContactListFeatures as $item => $data ) {
simple_set_toggle( $item, CONTACT_PKG_NAME );
}
foreach( $contactTypeDefaults as $key => $val ) {
simple_set_toggle_array( 'defaultTypes', $key, CONTACT_PKG_NAME);
- }
+ }
}
foreach( $contactTypeDefaults as $key => $val) {
diff --git a/admin/admin_contact_type.php b/admin/admin_contact_type.php
index 8176111..cb9fff0 100755
--- a/admin/admin_contact_type.php
+++ b/admin/admin_contact_type.php
@@ -2,7 +2,6 @@
// $Header$
require_once '../../kernel/includes/setup_inc.php';
-use Bitweaver\Contact\Contact;
use Bitweaver\Contact\ContactType;
use Bitweaver\KernelTools;
@@ -28,4 +27,4 @@ if( isset( $_REQUEST["fSubmitAddContactType"] ) ) {
$contacttype = ContactType::getContactTypeList();
$gBitSmarty->assign( 'contacttype', $contacttype );
-$gBitSystem->display( 'bitpackage:contact/admin_contact_type.tpl', KernelTools::tra( 'Edit Contact Types' ) , array( 'display_mode' => 'admin' ));
+$gBitSystem->display( 'bitpackage:contact/admin_contact_type.tpl', KernelTools::tra( 'Edit Contact Types' ) , [ 'display_mode' => 'admin' ]);
diff --git a/admin/admin_xref_types.php b/admin/admin_xref_types.php
index e53958b..3ffff55 100755
--- a/admin/admin_xref_types.php
+++ b/admin/admin_xref_types.php
@@ -2,7 +2,6 @@
// $Header$
require_once '../../kernel/includes/setup_inc.php';
-use Bitweaver\Contact\Contact;
use Bitweaver\Contact\ContactXrefType;
use Bitweaver\KernelTools;
include_once CONTACT_PKG_INCLUDE_PATH . 'lookup_contact_xref_type_inc.php';
@@ -29,4 +28,4 @@ if( isset( $_REQUEST["fSubmitAddXrefType"] ) ) {
$xref_types = ContactXrefType::getContactXrefTypeList();
$gBitSmarty->assign( 'xref_types', $xref_types );
-$gBitSystem->display( 'bitpackage:contact/admin_xref_types.tpl', KernelTools::tra( 'Edit XrefTypes' ) , array( 'display_mode' => 'admin' ));
+$gBitSystem->display( 'bitpackage:contact/admin_xref_types.tpl', KernelTools::tra( 'Edit XrefTypes' ) , [ 'display_mode' => 'admin' ]);
diff --git a/admin/schema_inc.php b/admin/schema_inc.php
index d0b3275..d305cbb 100755
--- a/admin/schema_inc.php
+++ b/admin/schema_inc.php
@@ -70,11 +70,11 @@ foreach( array_keys( $tables ) AS $tableName ) {
$gBitInstaller->registerSchemaTable( CONTACT_PKG_NAME, $tableName, $tables[$tableName] );
}
-$gBitInstaller->registerPackageInfo( CONTACT_PKG_NAME, array(
+$gBitInstaller->registerPackageInfo( CONTACT_PKG_NAME, [
'description' => "Base Contact management package with contact xref and address books
designed to be expanded with additional plugins.",
'license' => '<a href="http://www.gnu.org/licenses/licenses.html#LGPL">LGPL</a>',
-) );
+] );
// ### Indexes
$indices = [
@@ -84,31 +84,31 @@ $indices = [
$gBitInstaller->registerSchemaIndexes( CONTACT_PKG_NAME, $indices );
// ### Sequences
-$sequences = array (
+$sequences = [
'contact_xref_seq' => [ 'start' => 1 ],
-);
+];
$gBitInstaller->registerSchemaSequences( CONTACT_PKG_NAME, $sequences );
// ### Defaults
// ### Default User Permissions
-$gBitInstaller->registerUserPermissions( CONTACT_PKG_NAME, array(
+$gBitInstaller->registerUserPermissions( CONTACT_PKG_NAME, [
[ 'p_contact_view', 'Can browse the Contact List', 'basic', CONTACT_PKG_NAME ],
[ 'p_contact_update', 'Can update the Contact List content', 'registered', CONTACT_PKG_NAME ],
[ 'p_contact_create', 'Can create a new Contact List entry', 'registered', CONTACT_PKG_NAME ],
[ 'p_contact_admin', 'Can admin Contact List', 'admin', CONTACT_PKG_NAME ],
- [ 'p_contact_expunge', 'Can remove a Contact entry', 'editors', CONTACT_PKG_NAME ]
-) );
+ [ 'p_contact_expunge', 'Can remove a Contact entry', 'editors', CONTACT_PKG_NAME ],
+] );
// ### Default Preferences
-$gBitInstaller->registerPreferences( CONTACT_PKG_NAME, array(
+$gBitInstaller->registerPreferences( CONTACT_PKG_NAME, [
[ CONTACT_PKG_NAME, 'contact_default_ordering', 'title_desc' ],
[ CONTACT_PKG_NAME, 'contact_list_created', 'y' ],
[ CONTACT_PKG_NAME, 'contact_list_lastmodif', 'y' ],
[ CONTACT_PKG_NAME, 'contact_list_notes', 'y' ],
[ CONTACT_PKG_NAME, 'contact_list_title', 'y' ],
[ CONTACT_PKG_NAME, 'contact_list_user', 'y' ],
-) );
+] );
$gBitInstaller->registerSchemaDefault( CONTACT_PKG_NAME, [
"INSERT INTO `" . BIT_DB_PREFIX . "contact_xref_type` VALUES ('0', 'type', 'Contact Type List', '3', '')",
@@ -153,6 +153,6 @@ $gBitInstaller->registerSchemaDefault( CONTACT_PKG_NAME, [
] );
// Requirements
-$gBitInstaller->registerRequirements( CONTACT_PKG_NAME, [
+$gBitInstaller->registerRequirements( CONTACT_PKG_NAME, [
'liberty' => [ 'min' => '5.0.0' ],
] ); \ No newline at end of file
diff --git a/edit.php b/edit.php
index f6d2d92..44eea46 100755
--- a/edit.php
+++ b/edit.php
@@ -41,7 +41,7 @@ if (isset( $_REQUEST["preview"] )) {
$gBitSmarty->assign( 'title', $_REQUEST["title"] );
$parsed = $gContent->parseData( $formInfo['edit'], !empty( $_REQUEST['format_guid'] ) ? $_REQUEST['format_guid'] :
- ( isset( $gContent->mInfo['format_guid'] ) ? $gContent->mInfo['format_guid'] : 'tikiwiki' ) );
+ ( $gContent->mInfo['format_guid'] ?? 'tikiwiki' ), );
$gBitSmarty->assign('parsed', $parsed);
$gContent->invokeServices( 'content_preview_function' );
} else {
@@ -62,7 +62,7 @@ if (isset($_REQUEST["fCancel"])) {
$formInfo = $_REQUEST;
$formInfo['data'] = &$_REQUEST['edit'];
}
-}
+}
// formInfo might be set due to a error on submit
if( empty( $formInfo ) ) {
@@ -76,4 +76,4 @@ $gBitSmarty->assign( 'errors', $gContent->mErrors );
$gBitSmarty->assign( (!empty( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'body').'TabSelect', 'tdefault' );
$gBitSmarty->assign('show_page_bar', 'y');
-$gBitSystem->display( 'bitpackage:contact/edit.tpl', 'Edit: ' , array( 'display_mode' => 'edit' ));
+$gBitSystem->display( 'bitpackage:contact/edit.tpl', 'Edit: ' , [ 'display_mode' => 'edit' ]);
diff --git a/edit_key_break.php b/edit_key_break.php
index 684e593..31d5c10 100755
--- a/edit_key_break.php
+++ b/edit_key_break.php
@@ -40,7 +40,7 @@ if( empty( $xrefInfo ) ) {
}
if( empty( $xrefInfo['content_id'] ) ) {
$xrefInfo = $_REQUEST;
- if ( isset($xrefInfo['edit']) ) {
+ if ( isset($xrefInfo['edit']) ) {
$xrefInfo['data'] = $xrefInfo['edit'];
}
}
@@ -52,4 +52,4 @@ $gBitSmarty->assign( 'title', $gContent->mInfo['title'] );
$gBitSmarty->assign( 'xref_title', $gContent->mInfo['xref_title'] );
$gBitSmarty->assign( 'errors', $gContent->mErrors );
-$gBitSystem->display( 'bitpackage:contact/edit_key_break.tpl', 'Edit: ' , array( 'display_mode' => 'edit' ));
+$gBitSystem->display( 'bitpackage:contact/edit_key_break.tpl', 'Edit: ' , [ 'display_mode' => 'edit' ]);
diff --git a/edit_notes.php b/edit_notes.php
index 72d0e15..8b2e0e4 100755
--- a/edit_notes.php
+++ b/edit_notes.php
@@ -42,11 +42,11 @@ for ( $n = 0; $n < $mbox->size(); $n++ ) {
$subject = $matches[1];
echo 'Mail #' . $n . ': ' . $subject . "<br>";
$Decoder = new Mail_mimeDecode( $message );
- $params = array(
+ $params = [
'include_bodies' => true,
'decode_bodies' => true,
'decode_headers' => true,
- );
+ ];
$Decoded = $Decoder->decode( $params );
if ($Decoded->ctype_primary == "multipart") {
\Bitweaver\vd( $Decoded->parts[0]->ctype_primary );
@@ -76,4 +76,4 @@ $gBitSmarty->assign( 'errors', $gContent->mErrors );
$gBitSmarty->assign( (!empty( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'body').'TabSelect', 'tdefault' );
$gBitSmarty->assign('show_page_bar', 'y');
-$gBitSystem->display( 'bitpackage:contact/edit.tpl', 'Edit: ' , array( 'display_mode' => 'edit' ));
+$gBitSystem->display( 'bitpackage:contact/edit.tpl', 'Edit: ' , [ 'display_mode' => 'edit' ]);
diff --git a/edit_xref.php b/edit_xref.php
index 16a0057..34f35b0 100755
--- a/edit_xref.php
+++ b/edit_xref.php
@@ -38,10 +38,10 @@ if (isset($_REQUEST["fCancel"])) {
if( $gContent->storeXref( $_REQUEST ) ) {
header("Location: ".$gContent->getDisplayUrl() );
die;
- } else {
+ }
$xrefInfo = $_REQUEST;
$xrefInfo['data'] = &$_REQUEST['edit'];
- }
+
} else if(isset( $_REQUEST["expunge"] ) ) {
if( $gContent->stepXref( $_REQUEST ) ) {
// if ( $_REQUEST['expunge'] > 2) {
@@ -61,7 +61,7 @@ $gBitSmarty->assign( 'xref_title', $gContent->mInfo['xref_title'] );
$gBitSmarty->assign( 'errors', $gContent->mErrors );
if( isset($xrefInfo['template']) ) {
- $gBitSystem->display( 'bitpackage:contact/edit_xref_'.$xrefInfo['template'].'.tpl', 'Edit: ' , array( 'display_mode' => 'edit' ));
+ $gBitSystem->display( 'bitpackage:contact/edit_xref_'.$xrefInfo['template'].'.tpl', 'Edit: ' , [ 'display_mode' => 'edit' ]);
} else {
- $gBitSystem->display( 'bitpackage:contact/edit_xref.tpl', 'Edit: ' , array( 'display_mode' => 'edit' ));
+ $gBitSystem->display( 'bitpackage:contact/edit_xref.tpl', 'Edit: ' , [ 'display_mode' => 'edit' ]);
}
diff --git a/edit_xref_type.php b/edit_xref_type.php
index 370e9dc..4a290d7 100755
--- a/edit_xref_type.php
+++ b/edit_xref_type.php
@@ -20,11 +20,11 @@ $gContent = new Contact();
$gBitSmarty->assign( 'xref_type_info', $gContent->mInfo);
if( isset( $_REQUEST["fSubmitSaveXrefType"] ) ) {
- $gContent->storeXrefType( $_REQUEST );
+ $gContent->storeXrefType( $_REQUEST );
$gContent->loadXrefType();
- header( "Location: " . CONTACT_PKG_URL . "admin/admin_xref_type.php" );
+ header( "Location: " . CONTACT_PKG_URL . "admin/admin_xref_type.php" );
} elseif( isset( $_REQUEST['fRemoveXref'] ) ) {
$gContent->expungeXrefType();
}
-$gBitSystem->display( 'bitpackage:contact/edit_xref_type.tpl' , NULL, array( 'display_mode' => 'edit' ));
+$gBitSystem->display( 'bitpackage:contact/edit_xref_type.tpl' , NULL, [ 'display_mode' => 'edit' ]);
diff --git a/form.php b/form.php
index f14aac2..44bea85 100755
--- a/form.php
+++ b/form.php
@@ -22,8 +22,6 @@ $gBitSystem->verifyPackage( 'contact' );
$cat_type = BITPAGE_CONTENT_TYPE_GUID;
if(isset($_REQUEST["fSaveForm"])) {
\Bitweaver\vd($_REQUEST);
-} else {
-
}
// Pro
@@ -40,6 +38,6 @@ if (isset($_REQUEST["fCancel"])) {
$formInfo = $_REQUEST;
$formInfo['data'] = &$_REQUEST['edit'];
}
-}
+}
-$gBitSystem->display( 'bitpackage:contact/form_DSInspection.tpl', 'Form: OD01 ' , array( 'display_mode' => 'form' ));
+$gBitSystem->display( 'bitpackage:contact/form_DSInspection.tpl', 'Form: OD01 ' , [ 'display_mode' => 'form' ]);
diff --git a/import/ContactOld.php b/import/ContactOld.php
index 63941c5..105af63 100755
--- a/import/ContactOld.php
+++ b/import/ContactOld.php
@@ -43,22 +43,22 @@ class Contact extends LibertyBase {
function load($pContactId = NULL) {
if ( $pContactId ) $this->mContactId = (int)$pContactId;
if( $this->verifyId( $this->mContactId ) ) {
- $query = "select ci.usn AS contact_id, ci.*
+ $query = "select ci.usn AS contact_id, ci.*
FROM `".BIT_DB_PREFIX."contact` ci
LEFT JOIN `".BIT_DB_PREFIX."contact_address` a ON a.contact_id = ci.usn
LEFT JOIN `".BIT_DB_PREFIX."postcode` p ON p.`postcode` = a.`postcode`
WHERE ci.`contact_id`=?";
/*
*/
- $result = $this->mDb->query( $query, array( $this->mContactId ) );
+ $result = $this->mDb->query( $query, [ $this->mContactId ] );
if ( $result && $result->numRows() ) {
$this->mInfo = $result->fields;
$this->mContactId = (int)$result->fields['contact_id'];
$this->mParentId = (int)$result->fields['usn'];
$this->mContactName = $result->fields['title'];
- $this->mInfo['creator'] = (isset( $result->fields['creator_real_name'] ) ? $result->fields['creator_real_name'] : $result->fields['creator_user'] );
- $this->mInfo['editor'] = (isset( $result->fields['modifier_real_name'] ) ? $result->fields['modifier_real_name'] : $result->fields['modifier_user'] );
+ $this->mInfo['creator'] = ($result->fields['creator_real_name'] ?? $result->fields['creator_user'] );
+ $this->mInfo['editor'] = ($result->fields['modifier_real_name'] ?? $result->fields['modifier_user'] );
$this->mInfo['display_url'] = $this->getDisplayUrl();
$os1 = new OSRef($this->mInfo['x_coordinate'], $this->mInfo['y_coordinate']);
$ll1 = $os1->toLatLng();
@@ -66,7 +66,7 @@ class Contact extends LibertyBase {
$this->mInfo['prop_lng'] = $ll1->lng;
}
}
- return;
+
}
/**
@@ -94,7 +94,7 @@ class Contact extends LibertyBase {
if ( empty( $pParamHash['parent_id'] ) )
$pParamHash['parent_id'] = $this->mContactId;
-
+
// content store
// check for name issues, first truncate length if too long
if( empty( $pParamHash['surname'] ) || empty( $pParamHash['forename'] ) ) {
@@ -102,7 +102,7 @@ class Contact extends LibertyBase {
} else {
$pParamHash['title'] = substr( $pParamHash['prefix'].' '.$pParamHash['forename'].' '.$pParamHash['surname'].' '.$pParamHash['suffix'], 0, 160 );
$pParamHash['content_store']['title'] = $pParamHash['title'];
- }
+ }
// Secondary store entries
$pParamHash['contact_store']['prefix'] = $pParamHash['prefix'];
@@ -128,14 +128,14 @@ class Contact extends LibertyBase {
**/
function store( &$pParamHash ) {
if( $this->verify( $pParamHash ) ) {
- // Start a transaction wrapping the whole insert into liberty
+ // Start a transaction wrapping the whole insert into liberty
$this->mDb->StartTrans();
$table = BIT_DB_PREFIX."contact";
if( $this->verifyId( $this->mContactId ) ) {
if( !empty( $pParamHash['contact_store'] ) ) {
- $result = $this->mDb->associateUpdate( $table, $pParamHash['contact_store'], array( "contact_id" => $this->mContactId ) );
+ $result = $this->mDb->associateUpdate( $table, $pParamHash['contact_store'], [ "contact_id" => $this->mContactId ] );
}
} else {
$pParamHash['contact_store']['contact_id'] = $pParamHash['contact_id'];
@@ -144,7 +144,7 @@ class Contact extends LibertyBase {
$pParamHash['contact_store']['usn'] = $pParamHash['contact_id'];
} else {
$pParamHash['contact_store']['usn'] = $this->mDb->GenID( 'contact_id_seq');
- }
+ }
$pParamHash['contact_store']['parent_id'] = $pParamHash['contact_store']['contact_id'];
$this->mContactId = $pParamHash['contact_store']['contact_id'];
$this->mParentId = $pParamHash['contact_store']['parent_id'];
@@ -171,9 +171,9 @@ class Contact extends LibertyBase {
if ($this->isValid() ) {
$this->mDb->StartTrans();
$query = "DELETE FROM `".BIT_DB_PREFIX."contact` WHERE `contact_id` = ?";
- $result = $this->mDb->query($query, array($this->mContactId ) );
+ $result = $this->mDb->query($query, [$this->mContactId ] );
$query = "DELETE FROM `".BIT_DB_PREFIX."contact_type_map` WHERE `contact_id` = ?";
- $result = $this->mDb->query($query, array($this->mContactId ) );
+ $result = $this->mDb->query($query, [$this->mContactId ] );
if (LibertyContent::expunge() ) {
$ret = TRUE;
$this->mDb->CompleteTrans();
@@ -183,7 +183,7 @@ class Contact extends LibertyBase {
}
return $ret;
}
-
+
/**
* Returns Request_URI to a Contact content object
*
@@ -251,10 +251,10 @@ class Contact extends LibertyBase {
*/
function getList( &$pListHash ) {
LibertyContent::prepGetList( $pListHash );
-
+
$whereSql = $joinSql = $selectSql = '';
- $bindVars = array();
-
+ $bindVars = [];
+
if ( isset($pListHash['find']) ) {
$findesc = '%' . strtoupper( $pListHash['find'] ) . '%';
$whereSql .= " AND (UPPER(con.`SURNAME`) like ? or UPPER(con.`FORENAME`) like ?) ";
@@ -274,7 +274,7 @@ class Contact extends LibertyBase {
$joinSql
WHERE $whereSql";
- $ret = array();
+ $ret = [];
$this->mDb->StartTrans();
$result = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] );
$cant = $this->mDb->getOne( $query_cant, $bindVars );
@@ -299,7 +299,7 @@ class Contact extends LibertyBase {
$query = "SELECT `type_name` FROM `contact_type`
ORDER BY `type_name`";
$result = $this->mDb->query($query);
- $ret = array();
+ $ret = [];
while ($res = $result->fetchRow()) {
$ret[] = trim($res["type_name"]);
@@ -357,7 +357,7 @@ class Contact extends LibertyBase {
$this->mContactId = 0;
// $pDataHash['contact_store']['contact_id'] = $pDataHash['contact_id'];
// $pDataHash['address_store']['contact_id'] = $pDataHash['contact_id'];
-
+
$result = $this->mDb->associateInsert( $table, $pDataHash['contact_store'] );
$result = $this->mDb->associateInsert( $atable, $pDataHash['address_store'] );
$this->mDb->CompleteTrans();
@@ -366,9 +366,9 @@ class Contact extends LibertyBase {
$this->mErrors['store'] = 'Failed to store this contact.';
}
*/
- return( count( $this->mErrors ) == 0 );
+ return( count( $this->mErrors ) == 0 );
}
-
+
/**
* Delete contact object and all related records
*/
@@ -440,9 +440,9 @@ class Contact extends LibertyBase {
$this->mErrors['store'] = 'Failed to store this contact.';
}
*/
- return( count( $this->mErrors ) == 0 );
+ return( count( $this->mErrors ) == 0 );
}
-
+
/**
* Delete contact object and all related records
*/
@@ -462,7 +462,7 @@ class Contact extends LibertyBase {
*/
function getContactList( &$pParamHash ) {
global $gBitSystem, $gBitUser;
-
+
if ( empty( $pParamHash['sort_mode'] ) ) {
if ( empty( $_REQUEST["sort_mode"] ) ) {
$pParamHash['sort_mode'] = 'organisation_asc';
@@ -470,16 +470,16 @@ class Contact extends LibertyBase {
$pParamHash['sort_mode'] = $_REQUEST['sort_mode'];
}
}
-
+
LibertyContent::prepGetList( $pParamHash );
$findSql = '';
$selectSql = '';
$joinSql = '';
$whereSql = '';
- $bindVars = array();
+ $bindVars = [];
$type = 'organisation';
-
+
// this will set $find, $sort_mode, $max_records and $offset
extract( $pParamHash );
@@ -491,10 +491,10 @@ class Contact extends LibertyBase {
$sort_mode = 'organisation_asc';
}
if( isset( $find_name ) and is_string( $find_name ) and $find_name <> '' ) {
- $split = preg_split('|[,. ]|', $find_name, 2);
+ $split = preg_split('|[,. ]|', $find_name, 2);
$whereSql .= " AND UPPER( ci.`surname` ) STARTING ? ";
$bindVars[] = strtoupper( $split[0] );
- if ( array_key_exists( 1, $split ) ) {
+ if ( array_key_exists( 1, $split ) ) {
$split[1] = trim( $split[1] );
$whereSql .= " AND UPPER( ci.`forename` ) STARTING ? ";
$bindVars[] = strtoupper( $split[1] );
@@ -521,10 +521,10 @@ class Contact extends LibertyBase {
FROM `".BIT_DB_PREFIX."contact` ci
JOIN `".BIT_DB_PREFIX."contact_address` a ON a.contact_id = ci.contact_id $findSql
$joinSql WHERE ci.`".$type."` <> '' $whereSql ";
-// INNER JOIN `".BIT_DB_PREFIX."contact_address` a ON a.contact_id = ci.contact_id
+// INNER JOIN `".BIT_DB_PREFIX."contact_address` a ON a.contact_id = ci.contact_id
vd($query);
$result = $this->mDb->query( $query, $bindVars, $max_records, $offset );
- $ret = array();
+ $ret = [];
while( $res = $result->fetchRow() ) {
if (!empty($parse_split)) {
$res = array_merge($this->parseSplit($res), $res);
@@ -537,7 +537,6 @@ vd($query);
return $ret;
}
-
/**
* loadContact( &$pParamHash );
* Get contact record
@@ -549,7 +548,7 @@ vd($query);
LEFT JOIN `".BIT_DB_PREFIX."contact_address` a ON a.usn = ci.usn
LEFT JOIN `".BIT_DB_PREFIX."postcode` p ON p.`postcode` = a.`postcode`
WHERE ci.`contact_id` = ?";
- if( $rs = $this->mDb->query( $sql, array( $this->mContactId ) ) ) {
+ if( $rs = $this->mDb->query( $sql, [ $this->mContactId ] ) ) {
if( $this->mInfo = $rs->fields ) {
/* if( $this->mInfo['local_custodian_code'] == 0 ) {
global $gBitSystem;
@@ -567,7 +566,7 @@ vd($query);
*/
- $result = $this->mDb->query( $sql, array( $this->mContactId ) );
+ $result = $this->mDb->query( $sql, [ $this->mContactId ] );
while( $res = $result->fetchRow() ) {
$this->mInfo['xref'][] = $res;
@@ -597,14 +596,13 @@ vd($query);
return( count( $this->mInfo ) );
}
-
/**
* getXrefList( &$pParamHash );
* Get list of xref records for this contact record
*/
function loadXrefList() {
if( empty( $this->mInfo['xref'] ) ) {
-
+
$sql = "SELECT x.`last_update_date`, x.`source`, s.`cross_ref_title` || '-' || x.`xorder` AS source_title, x.`cross_reference`, x.`data`, x.`xref_key` AS usn
FROM `".BIT_DB_PREFIX."contact_xref` x
JOIN `".BIT_DB_PREFIX."contact_xref_source` s
@@ -612,7 +610,7 @@ vd($query);
WHERE x.contact_id = ?
ORDER BY x.`source`, x.`xorder`";
- $result = $this->mDb->query( $sql, array( $this->mContactId ) );
+ $result = $this->mDb->query( $sql, [ $this->mContactId ] );
while( $res = $result->fetchRow() ) {
$this->mInfo['xref'][] = $res;
@@ -621,7 +619,7 @@ vd($query);
$sql = "SELECT t.* FROM `".BIT_DB_PREFIX."task_ticket` t
WHERE t.usn = ?";
- $result = $this->mDb->query( $sql, array( '9000000001' ) ); //$this->mContactId ) );
+ $result = $this->mDb->query( $sql, [ '9000000001' ] ); //$this->mContactId ) );
while( $res = $result->fetchRow() ) {
$this->mInfo['tickets'][] = $res;
}
diff --git a/import/ImportContact.php b/import/ImportContact.php
index ebef181..412d34f 100755
--- a/import/ImportContact.php
+++ b/import/ImportContact.php
@@ -40,17 +40,17 @@
if ( LibertyContent::store( $pDataHash ) ) {
$pDataHash['contact_store']['content_id'] = $pDataHash['content_id'];
$pDataHash['address_store']['content_id'] = $pDataHash['content_id'];
-
+
$result = $this->mDb->associateInsert( $table, $pDataHash['contact_store'] );
// $result = $this->mDb->associateInsert( $atable, $pDataHash['address_store'] );
- $this->mDb->CompleteTrans();
+ $this->mDb->CompleteTrans();
} else {
$this->mDb->RollbackTrans();
$this->mErrors['store'] = 'Failed to store this contact.';
- }
- return( count( $this->mErrors ) == 0 );
+ }
+ return( count( $this->mErrors ) == 0 );
}
-
+
/**
* Delete contact object and all related records
*/
diff --git a/import/ImportContact2.php b/import/ImportContact2.php
index d5d4801..cf4faf2 100755
--- a/import/ImportContact2.php
+++ b/import/ImportContact2.php
@@ -33,42 +33,42 @@
$pDataHash['content_id'] = 0;
if ( LibertyContent::store( $pDataHash ) ) {
$pDataHash['contact_store']['content_id'] = $pDataHash['content_id'];
-
+
$result = $this->mDb->associateInsert( $table, $pDataHash['contact_store'] );
- $this->mDb->CompleteTrans();
+ $this->mDb->CompleteTrans();
} else {
$this->mDb->RollbackTrans();
$this->mErrors['store'] = 'Failed to store this contact.';
- }
+ }
$Xref = new ContactXref();
- $pParams = array( 'source' => '#S',
- 'content_id' => $pDataHash['content_id'],
- 'xkey' => $data[2],
- 'xorder' => '0',
- 'xkey_ext' => $data[1] );
+ $pParams = [ 'source' => '#S',
+ 'content_id' => $pDataHash['content_id'],
+ 'xkey' => $data[2],
+ 'xorder' => '0',
+ 'xkey_ext' => $data[1], ];
$Xref->store($pParams);
- $pParams = array( 'source' => '#P',
- 'content_id' => $pDataHash['content_id'],
- 'xkey' => '',
- 'xorder' => '0',
- 'xkey_ext' => 'External patrol of property. No keys. See site list in photos. Phone Ideal Alarms once completed.' );
+ $pParams = [ 'source' => '#P',
+ 'content_id' => $pDataHash['content_id'],
+ 'xkey' => '',
+ 'xorder' => '0',
+ 'xkey_ext' => 'External patrol of property. No keys. See site list in photos. Phone Ideal Alarms once completed.', ];
$Xref->store($pParams);
- $pParams = array( 'source' => '#P',
- 'content_id' => $pDataHash['content_id'],
- 'xkey' => '08007 076595',
- 'xorder' => '1',
- 'xkey_ext' => NULL );
+ $pParams = [ 'source' => '#P',
+ 'content_id' => $pDataHash['content_id'],
+ 'xkey' => '08007 076595',
+ 'xorder' => '1',
+ 'xkey_ext' => NULL, ];
$Xref->store($pParams);
- $pParams = array( 'source' => '#P',
- 'content_id' => $pDataHash['content_id'],
- 'xkey' => $data[1],
- 'xorder' => '2',
- 'xkey_ext' => 'Property number' );
+ $pParams = [ 'source' => '#P',
+ 'content_id' => $pDataHash['content_id'],
+ 'xkey' => $data[1],
+ 'xorder' => '2',
+ 'xkey_ext' => 'Property number', ];
$Xref->store($pParams);
- return( count( $this->mErrors ) == 0 );
+ return( count( $this->mErrors ) == 0 );
}
-
+
/**
* Delete contact object and all related records
*/
diff --git a/import/ImportPhx.php b/import/ImportPhx.php
index cb92cca..3f0c8e9 100755
--- a/import/ImportPhx.php
+++ b/import/ImportPhx.php
@@ -59,7 +59,7 @@
$this->mContactId = 0;
// $pDataHash['contact_store']['contact_id'] = $pDataHash['contact_id'];
// $pDataHash['address_store']['contact_id'] = $pDataHash['contact_id'];
-
+
$result = $this->mDb->associateInsert( $table, $pDataHash['contact_store'] );
$result = $this->mDb->associateInsert( $atable, $pDataHash['address_store'] );
$this->mDb->CompleteTrans();
@@ -68,9 +68,9 @@
$this->mErrors['store'] = 'Failed to store this contact.';
}
*/
- return( count( $this->mErrors ) == 0 );
+ return( count( $this->mErrors ) == 0 );
}
-
+
/**
* Delete contact object and all related records
*/
diff --git a/import/ImportPhx2.php b/import/ImportPhx2.php
index f2cded2..7d19343 100755
--- a/import/ImportPhx2.php
+++ b/import/ImportPhx2.php
@@ -83,18 +83,18 @@
$pDataHash['contact_store']['address_id'] = $pDataHash['content_id'];
$pDataHash['phx_store']['content_id'] = $pDataHash['content_id'];
$pDataHash['address_store']['content_id'] = $pDataHash['content_id'];
-
+
$result = $this->mDb->associateInsert( $ctable, $pDataHash['contact_store'] );
$result = $this->mDb->associateInsert( $ptable, $pDataHash['phx_store'] );
$result = $this->mDb->associateInsert( $atable, $pDataHash['address_store'] );
- $this->mDb->CompleteTrans();
+ $this->mDb->CompleteTrans();
} else {
$this->mDb->RollbackTrans();
$this->mErrors['store'] = 'Failed to store this contact.';
- }
- return( count( $this->mErrors ) == 0 );
+ }
+ return( count( $this->mErrors ) == 0 );
}
-
+
/**
* Delete contact object and all related records
*/
diff --git a/import/ImportSage.php b/import/ImportSage.php
index d24afe8..98ce04a 100755
--- a/import/ImportSage.php
+++ b/import/ImportSage.php
@@ -66,18 +66,18 @@
$pDataHash['sage_store']['content_id'] = $pDataHash['content_id'];
$pDataHash['address_store']['content_id'] = $pDataHash['content_id'];
$pDataHash['contact_store']['address_id'] = $pDataHash['content_id'];
-
+
$result = $this->mDb->associateInsert( $ctable, $pDataHash['contact_store'] );
$result = $this->mDb->associateInsert( $stable, $pDataHash['sage_store'] );
$result = $this->mDb->associateInsert( $atable, $pDataHash['address_store'] );
- $this->mDb->CompleteTrans();
+ $this->mDb->CompleteTrans();
} else {
$this->mDb->RollbackTrans();
$this->mErrors['store'] = 'Failed to store this contact.';
- }
- return( count( $this->mErrors ) == 0 );
+ }
+ return( count( $this->mErrors ) == 0 );
}
-
+
/**
* Delete contact object and all related records
*/
diff --git a/import/ImportWande.php b/import/ImportWande.php
index 79fbad5..882b6e5 100755
--- a/import/ImportWande.php
+++ b/import/ImportWande.php
@@ -69,18 +69,18 @@
$pDataHash['contact_store']['address_id'] = $pDataHash['content_id'];
$pDataHash['wande_store']['content_id'] = $pDataHash['content_id'];
$pDataHash['address_store']['content_id'] = $pDataHash['content_id'];
-
+
$result = $this->mDb->associateInsert( $ctable, $pDataHash['contact_store'] );
$result = $this->mDb->associateInsert( $wtable, $pDataHash['wande_store'] );
$result = $this->mDb->associateInsert( $atable, $pDataHash['address_store'] );
- $this->mDb->CompleteTrans();
+ $this->mDb->CompleteTrans();
} else {
$this->mDb->RollbackTrans();
$this->mErrors['store'] = 'Failed to store this contact.';
- }
- return( count( $this->mErrors ) == 0 );
+ }
+ return( count( $this->mErrors ) == 0 );
}
-
+
/**
* Delete contact object and all related records
*/
diff --git a/import/Mbox.php b/import/Mbox.php
index 52daec1..65f914c 100755
--- a/import/Mbox.php
+++ b/import/Mbox.php
@@ -75,9 +75,6 @@ define('MAIL_MBOX_ERROR_NO_RESOURCE', 2111);
*/
define('MAIL_MBOX_ERROR_MSG_INVALID', 2112);
-
-
-
/**
* Class to read mbox mail files.
*
@@ -117,786 +114,780 @@ define('MAIL_MBOX_ERROR_MSG_INVALID', 2112);
*/
class Mail_Mbox extends PEAR
{
- /**
- * File resource / handle
- *
- * @var resource
- * @access protected
- */
- var $_resource = null;
-
- /**
- * Message index. Each mail has its own subarray,
- * which contains the start position and end position
- * as first and second subindex.
- *
- * @var array
- * @access protected
- */
- var $_index = null;
-
- /**
- * Timestamp at which the file has been modified last.
- *
- * @var int
- * @access protected
- */
- var $_lastModified = null;
-
- /**
- * Debug mode
- *
- * Set to true to turn on debug mode.
- *
- * @var bool
- * @access public
- * @see setDebug()
- * @see getDebug()
- */
- var $debug = false;
-
- /**
- * Directory in which the temporary mbox files are created.
- * Even if it's a unix directory, it does work on windows as
- * the only function it's used in is tempnam which automatically
- * chooses the right temp directory if this here doesn't exist.
- * So this variable is for special needs only.
- *
- * @var string
- * @access public
- * @see getTmpDir()
- * @see setTmpDir()
- */
- var $tmpdir = '/tmp';
+ /**
+ * File resource / handle
+ *
+ * @var resource
+ * @access protected
+ */
+ var $_resource = null;
- /**
- * Determines if the file is automatically re-opened and its
- * structure is parsed after modifying it. Setting this to false
- * makes you responsible for calling open() by hand, but is
- * *a lot* faster when appending many messages.
- *
- * @var bool
- * @access public
- */
- var $autoReopen = true;
+ /**
+ * Message index. Each mail has its own subarray,
+ * which contains the start position and end position
+ * as first and second subindex.
+ *
+ * @var array
+ * @access protected
+ */
+ var $_index = null;
+ /**
+ * Timestamp at which the file has been modified last.
+ *
+ * @var int
+ * @access protected
+ */
+ var $_lastModified = null;
+ /**
+ * Debug mode
+ *
+ * Set to true to turn on debug mode.
+ *
+ * @var bool
+ * @access public
+ * @see setDebug()
+ * @see getDebug()
+ */
+ var $debug = false;
- /**
- * Create a new Mbox class instance.
- * After creating it, you should use open().
- *
- * @param string $file Filename to open.
- *
- * @access public
- */
- function Mail_Mbox($file)
- {
- $this->_file = $file;
- }
+ /**
+ * Directory in which the temporary mbox files are created.
+ * Even if it's a unix directory, it does work on windows as
+ * the only function it's used in is tempnam which automatically
+ * chooses the right temp directory if this here doesn't exist.
+ * So this variable is for special needs only.
+ *
+ * @var string
+ * @access public
+ * @see getTmpDir()
+ * @see setTmpDir()
+ */
+ var $tmpdir = '/tmp';
- /**
- * Open the mbox file
- *
- * Also, this function will process the Mbox and create a cache
- * that tells each message start and end bytes.
- *
- * @return boolean|PEAR_Error True if all went ok, PEAR_Error on failure
- * @access public
- */
- function open($create = false)
- {
- // check if file exists else return pear error
- if (!is_file($this->_file)) {
- if ($create) {
- $ret = $this->_create();
- if (PEAR::isError($ret)) {
- return $ret;
- }
- } else {
- return PEAR::raiseError(
- 'Cannot open the mbox file "'
- . $this->_file . '": file does not exist.',
- MAIL_MBOX_ERROR_FILE_NOT_EXISTING
- );
- }
- }
+ /**
+ * Determines if the file is automatically re-opened and its
+ * structure is parsed after modifying it. Setting this to false
+ * makes you responsible for calling open() by hand, but is
+ * *a lot* faster when appending many messages.
+ *
+ * @var bool
+ * @access public
+ */
+ var $autoReopen = true;
- // opening the file
- $this->_lastModified = filemtime($this->_file);
- $this->_resource = fopen($this->_file, 'r');
- if (!is_resource($this->_resource)) {
- return PEAR::raiseError(
- 'Cannot open the mbox file: maybe without permission.',
- MAIL_MBOX_ERROR_NO_PERMISSION
- );
- }
+ /**
+ * Create a new Mbox class instance.
+ * After creating it, you should use open().
+ *
+ * @param string $file Filename to open.
+ *
+ * @access public
+ */
+ function Mail_Mbox($file)
+ {
+ $this->_file = $file;
+ }
- // process the file and get the messages bytes offsets
- $this->_process();
+ /**
+ * Open the mbox file
+ *
+ * Also, this function will process the Mbox and create a cache
+ * that tells each message start and end bytes.
+ *
+ * @return boolean|PEAR_Error True if all went ok, PEAR_Error on failure
+ * @access public
+ */
+ function open($create = false)
+ {
+ // check if file exists else return pear error
+ if (!is_file($this->_file)) {
+ if ($create) {
+ $ret = $this->_create();
+ if (PEAR::isError($ret)) {
+ return $ret;
+ }
+ } else {
+ return PEAR::raiseError(
+ 'Cannot open the mbox file "'
+ . $this->_file . '": file does not exist.',
+ MAIL_MBOX_ERROR_FILE_NOT_EXISTING,
+ );
+ }
+ }
- return true;
- }
+ // opening the file
+ $this->_lastModified = filemtime($this->_file);
+ $this->_resource = fopen($this->_file, 'r');
+ if (!is_resource($this->_resource)) {
+ return PEAR::raiseError(
+ 'Cannot open the mbox file: maybe without permission.',
+ MAIL_MBOX_ERROR_NO_PERMISSION,
+ );
+ }
- /**
- * Creates the file
- *
- * @return boolean True if it was created, false if it already
- * existed. PEAR_Error in case it could not
- * be created.
- *
- * @access protected
- */
- function _create()
- {
- if (is_file($this->_file)) {
- return false;
- }
+ // process the file and get the messages bytes offsets
+ $this->_process();
- //We should maybe try to check if the directory
- // is writable here. But that's too much fuss for now.
- touch($this->_file);
+ return true;
+ }
- if (is_file($this->_file)) {
- return true;
- }
+ /**
+ * Creates the file
+ *
+ * @return boolean True if it was created, false if it already
+ * existed. PEAR_Error in case it could not
+ * be created.
+ *
+ * @access protected
+ */
+ function _create()
+ {
+ if (is_file($this->_file)) {
+ return false;
+ }
- //error
- return PEAR::raiseError(
- 'File could not be created',
- MAIL_MBOX_ERROR_CANNOT_WRITE
- );
- }
+ //We should maybe try to check if the directory
+ // is writable here. But that's too much fuss for now.
+ touch($this->_file);
- /**
- * Re-opens the file and parses the messages again.
- * Used by other methods to be able to be able to prevent
- * re-opening the file.
- *
- * @return mixed See open() for return values. Returns true if
- * $this->autoReopen is false.
- * @access protected
- */
- function _reopen()
- {
- if ($this->autoReopen) {
- return $this->open();
- }
- return true;
- }
+ if (is_file($this->_file)) {
+ return true;
+ }
- /**
- * Close a Mbox
- *
- * Close the Mbox file opened by open()
- *
- * @return mixed true on success, else PEAR_Error
- * @access public
- */
- function close()
- {
- if (!is_resource($this->_resource)) {
- return PEAR::raiseError(
- 'Cannot close the mbox file because it was not open.',
- MAIL_MBOX_ERROR_NOT_OPEN
- );
- }
+ //error
+ return PEAR::raiseError(
+ 'File could not be created',
+ MAIL_MBOX_ERROR_CANNOT_WRITE,
+ );
+ }
- if (!fclose($this->_resource)) {
- return PEAR::raiseError(
- 'Cannot close the mbox, maybe file is being used (?)',
- MAIL_MBOX_ERROR_CANNOT_CLOSE
- );
- }
+ /**
+ * Re-opens the file and parses the messages again.
+ * Used by other methods to be able to be able to prevent
+ * re-opening the file.
+ *
+ * @return mixed See open() for return values. Returns true if
+ * $this->autoReopen is false.
+ * @access protected
+ */
+ function _reopen()
+ {
+ if ($this->autoReopen) {
+ return $this->open();
+ }
+ return true;
+ }
- return true;
- }
+ /**
+ * Close a Mbox
+ *
+ * Close the Mbox file opened by open()
+ *
+ * @return mixed true on success, else PEAR_Error
+ * @access public
+ */
+ function close()
+ {
+ if (!is_resource($this->_resource)) {
+ return PEAR::raiseError(
+ 'Cannot close the mbox file because it was not open.',
+ MAIL_MBOX_ERROR_NOT_OPEN,
+ );
+ }
- /**
- * Get number of messages in this mbox
- *
- * @return int Number of messages on Mbox (starting on 1,
- * 0 if no message exists)
- * @access public
- */
- function size()
- {
- if ($this->_index !== null) {
- return sizeof($this->_index);
- } else {
- return 0;
- }
- }
+ if (!fclose($this->_resource)) {
+ return PEAR::raiseError(
+ 'Cannot close the mbox, maybe file is being used (?)',
+ MAIL_MBOX_ERROR_CANNOT_CLOSE,
+ );
+ }
- /**
- * Get a message from the mbox
- *
- * Note: Message numbers start from 0.
- *
- * @param int $message The number of the message to retrieve
- *
- * @return string Return the message, PEAR_Error on error
- * @access public
- */
- function get($message)
- {
- // checking if we have bytes locations for this message
- if (!is_array($this->_index[$message])) {
- return PEAR::raiseError(
- 'Message does not exist.',
- MAIL_MBOX_ERROR_MESSAGE_NOT_EXISTING
- );
- }
+ return true;
+ }
- // getting bytes locations
- $bytesStart = $this->_index[$message][0];
- $bytesEnd = $this->_index[$message][1];
+ /**
+ * Get number of messages in this mbox
+ *
+ * @return int Number of messages on Mbox (starting on 1,
+ * 0 if no message exists)
+ * @access public
+ */
+ function size()
+ {
+ if ($this->_index !== null) {
+ return sizeof($this->_index);
+ }
+ return 0;
- // a debug feature to show the bytes locations
- if ($this->debug) {
- printf("%08d=%08d<br />", $bytesStart, $bytesEnd);
- }
+ }
- if (!is_resource($this->_resource)) {
- return PEAR::raiseError(
- 'Mbox resource is not valid. Maybe you need to re-open it?',
- MAIL_MBOX_ERROR_NO_RESOURCE
- );
- }
+ /**
+ * Get a message from the mbox
+ *
+ * Note: Message numbers start from 0.
+ *
+ * @param int $message The number of the message to retrieve
+ *
+ * @return string Return the message, PEAR_Error on error
+ * @access public
+ */
+ function get($message)
+ {
+ // checking if we have bytes locations for this message
+ if (!is_array($this->_index[$message])) {
+ return PEAR::raiseError(
+ 'Message does not exist.',
+ MAIL_MBOX_ERROR_MESSAGE_NOT_EXISTING,
+ );
+ }
- // seek to start of message
- if (fseek($this->_resource, $bytesStart) == -1) {
- return PEAR::raiseError(
- 'Cannot read message bytes',
- MAIL_MBOX_ERROR_CANNOT_READ
- );
- }
+ // getting bytes locations
+ $bytesStart = $this->_index[$message][0];
+ $bytesEnd = $this->_index[$message][1];
- if ($bytesEnd - $bytesStart <= 0) {
- return PEAR::raiseError(
- 'Message byte length is negative',
- MAIL_MBOX_ERROR_CANNOT_READ
- );
- }
+ // a debug feature to show the bytes locations
+ if ($this->debug) {
+ printf("%08d=%08d<br />", $bytesStart, $bytesEnd);
+ }
- // reading and returning message
- // (bytes to read = difference of bytes locations)
- $msg = fread($this->_resource, $bytesEnd - $bytesStart);
- return $this->_unescapeMessage($msg);
- }
+ if (!is_resource($this->_resource)) {
+ return PEAR::raiseError(
+ 'Mbox resource is not valid. Maybe you need to re-open it?',
+ MAIL_MBOX_ERROR_NO_RESOURCE,
+ );
+ }
- /**
- * Remove a message from Mbox and save it.
- *
- * Note: messages start with 0.
- *
- * @param int $message The number of the message to remove, or
- * array of message ids to remove
- *
- * @return mixed Return true else PEAR_Error
- * @access public
- */
- function remove($message)
- {
- if ($this->hasBeenModified()) {
- return PEAR::raiseError(
- 'File has been modified since loading. Re-open the file.',
- MAIL_MBOX_ERROR_MODIFIED
- );
- }
+ // seek to start of message
+ if (fseek($this->_resource, $bytesStart) == -1) {
+ return PEAR::raiseError(
+ 'Cannot read message bytes',
+ MAIL_MBOX_ERROR_CANNOT_READ,
+ );
+ }
- // convert single message to array
- if (!is_array($message)) {
- $message = array($message);
- }
+ if ($bytesEnd - $bytesStart <= 0) {
+ return PEAR::raiseError(
+ 'Message byte length is negative',
+ MAIL_MBOX_ERROR_CANNOT_READ,
+ );
+ }
- // checking if we have bytes locations for this message
- foreach ($message as $msg) {
- if (!isset($this->_index[$msg])
- || !is_array($this->_index[$msg])
- ) {
- return PEAR::raiseError(
- 'Message ' . $msg . 'does not exist.',
- MAIL_MBOX_ERROR_MESSAGE_NOT_EXISTING
- );
- }
- }
+ // reading and returning message
+ // (bytes to read = difference of bytes locations)
+ $msg = fread($this->_resource, $bytesEnd - $bytesStart);
+ return $this->_unescapeMessage($msg);
+ }
- // changing umask for security reasons
- $umaskOld = umask(077);
- // creating temp file
- $ftempname = tempnam($this->tmpdir, 'Mail_Mbox');
- // returning to old umask
- umask($umaskOld);
+ /**
+ * Remove a message from Mbox and save it.
+ *
+ * Note: messages start with 0.
+ *
+ * @param int $message The number of the message to remove, or
+ * array of message ids to remove
+ *
+ * @return mixed Return true else PEAR_Error
+ * @access public
+ */
+ function remove($message)
+ {
+ if ($this->hasBeenModified()) {
+ return PEAR::raiseError(
+ 'File has been modified since loading. Re-open the file.',
+ MAIL_MBOX_ERROR_MODIFIED,
+ );
+ }
- $ftemp = fopen($ftempname, 'w');
- if ($ftemp === false) {
- return PEAR::raiseError(
- 'Cannot create a temp file "' . $ftempname . '".',
- MAIL_MBOX_ERROR_CANNOT_CREATE_TMP
- );
- }
+ // convert single message to array
+ if (!is_array($message)) {
+ $message = [$message];
+ }
- // writing only undeleted messages
- $messages = $this->size();
+ // checking if we have bytes locations for this message
+ foreach ($message as $msg) {
+ if (!isset($this->_index[$msg])
+ || !is_array($this->_index[$msg])
+ ) {
+ return PEAR::raiseError(
+ 'Message ' . $msg . 'does not exist.',
+ MAIL_MBOX_ERROR_MESSAGE_NOT_EXISTING,
+ );
+ }
+ }
- for ($x = 0; $x < $messages; $x++) {
- if (in_array($x, $message)) {
- continue;
- }
+ // changing umask for security reasons
+ $umaskOld = umask(077);
+ // creating temp file
+ $ftempname = tempnam($this->tmpdir, 'Mail_Mbox');
+ // returning to old umask
+ umask($umaskOld);
- $messageThis = $this->_escapeMessage($this->get($x));
- if (is_string($messageThis)) {
- fwrite($ftemp, $messageThis, strlen($messageThis));
- }
- }
+ $ftemp = fopen($ftempname, 'w');
+ if ($ftemp === false) {
+ return PEAR::raiseError(
+ 'Cannot create a temp file "' . $ftempname . '".',
+ MAIL_MBOX_ERROR_CANNOT_CREATE_TMP,
+ );
+ }
- // closing file
- $this->close();
- fclose($ftemp);
+ // writing only undeleted messages
+ $messages = $this->size();
- return $this->_move($ftempname, $this->_file);
- }
+ for ($x = 0; $x < $messages; $x++) {
+ if (in_array($x, $message)) {
+ continue;
+ }
- /**
- * Update a message
- *
- * Note: messages start with 0.
- *
- * @param int $message The number of Message to update
- * @param string $content The new content of the Message
- *
- * @return mixed Return true if all is ok, else PEAR_Error
- * @access public
- */
- function update($message, $content)
- {
- if (!$this->_isValid($content)) {
- return PEAR::raiseError(
- 'Message is invalid', MAIL_MBOX_ERROR_MSG_INVALID
- );
- }
+ $messageThis = $this->_escapeMessage($this->get($x));
+ if (is_string($messageThis)) {
+ fwrite($ftemp, $messageThis, strlen($messageThis));
+ }
+ }
- if ($this->hasBeenModified()) {
- return PEAR::raiseError(
- 'File has been modified since loading. Re-open the file.',
- MAIL_MBOX_ERROR_MODIFIED
- );
- }
+ // closing file
+ $this->close();
+ fclose($ftemp);
- // checking if we have bytes locations for this message
- if (!is_array($this->_index[$message])) {
- return PEAR::raiseError(
- 'Message does not exist.',
- MAIL_MBOX_ERROR_MESSAGE_NOT_EXISTING
- );
- }
+ return $this->_move($ftempname, $this->_file);
+ }
- // creating temp file
- $ftempname = tempnam($this->tmpdir, 'Mail_Mbox');
- $ftemp = fopen($ftempname, 'w');
- if ($ftemp === false) {
- return PEAR::raiseError(
- 'Cannot create temp file "' . $ftempname . '" .',
- MAIL_MBOX_ERROR_CANNOT_CREATE_TMP
- );
- }
+ /**
+ * Update a message
+ *
+ * Note: messages start with 0.
+ *
+ * @param int $message The number of Message to update
+ * @param string $content The new content of the Message
+ *
+ * @return mixed Return true if all is ok, else PEAR_Error
+ * @access public
+ */
+ function update($message, $content)
+ {
+ if (!$this->_isValid($content)) {
+ return PEAR::raiseError(
+ 'Message is invalid', MAIL_MBOX_ERROR_MSG_INVALID,
+ );
+ }
- $messages = $this->size();
+ if ($this->hasBeenModified()) {
+ return PEAR::raiseError(
+ 'File has been modified since loading. Re-open the file.',
+ MAIL_MBOX_ERROR_MODIFIED,
+ );
+ }
- for ($x = 0; $x < $messages; $x++) {
- if ($x == $message) {
- $messageThis = $content;
- } else {
- $messageThis = $this->get($x);
- }
+ // checking if we have bytes locations for this message
+ if (!is_array($this->_index[$message])) {
+ return PEAR::raiseError(
+ 'Message does not exist.',
+ MAIL_MBOX_ERROR_MESSAGE_NOT_EXISTING,
+ );
+ }
- if (is_string($messageThis)) {
- $messageThis = $this->_escapeMessage($messageThis);
- fwrite($ftemp, $messageThis, strlen($messageThis));
- }
- }
+ // creating temp file
+ $ftempname = tempnam($this->tmpdir, 'Mail_Mbox');
+ $ftemp = fopen($ftempname, 'w');
+ if ($ftemp === false) {
+ return PEAR::raiseError(
+ 'Cannot create temp file "' . $ftempname . '" .',
+ MAIL_MBOX_ERROR_CANNOT_CREATE_TMP,
+ );
+ }
- // closing file
- $this->close();
- fclose($ftemp);
+ $messages = $this->size();
- return $this->_move($ftempname, $this->_file);
- }
+ for ($x = 0; $x < $messages; $x++) {
+ if ($x == $message) {
+ $messageThis = $content;
+ } else {
+ $messageThis = $this->get($x);
+ }
- /**
- * Insert a message
- *
- * PEAR::Mail_Mbox will insert the message according its offset.
- * 0 means before the actual message 0. 3 means before the message 3
- * (Remember: message 3 is the fourth message). The default is put
- * AFTER the last message (offset = null).
- *
- * @param string $content The content of the new message
- * @param int $offset Before the offset. Default: last message (null)
- *
- * @return mixed Return true else PEAR_Error object
- * @access public
- */
- function insert($content, $offset = null)
- {
- if (!$this->_isValid($content)) {
- return PEAR::raiseError(
- 'Message is invalid', MAIL_MBOX_ERROR_MSG_INVALID
- );
- }
+ if (is_string($messageThis)) {
+ $messageThis = $this->_escapeMessage($messageThis);
+ fwrite($ftemp, $messageThis, strlen($messageThis));
+ }
+ }
- if ($this->hasBeenModified()) {
- return PEAR::raiseError(
- 'File has been modified since loading. Re-open the file.',
- MAIL_MBOX_ERROR_MODIFIED
- );
- }
+ // closing file
+ $this->close();
+ fclose($ftemp);
- // optimize insert() to use append whenever possible
- if ($offset < 0 || $offset == $this->size() || $this->size() == 0) {
- return $this->append($content);
- }
+ return $this->_move($ftempname, $this->_file);
+ }
- // creating temp file
- $ftempname = tempnam($this->tmpdir, 'Mail_Mbox');
- $ftemp = fopen($ftempname, 'w');
- if ($ftemp === false) {
- return PEAR::raiseError(
- 'Cannot create temp file "' . $ftempname . '".',
- MAIL_MBOX_ERROR_CANNOT_CREATE_TMP
- );
- }
+ /**
+ * Insert a message
+ *
+ * PEAR::Mail_Mbox will insert the message according its offset.
+ * 0 means before the actual message 0. 3 means before the message 3
+ * (Remember: message 3 is the fourth message). The default is put
+ * AFTER the last message (offset = null).
+ *
+ * @param string $content The content of the new message
+ * @param int $offset Before the offset. Default: last message (null)
+ *
+ * @return mixed Return true else PEAR_Error object
+ * @access public
+ */
+ function insert($content, $offset = null)
+ {
+ if (!$this->_isValid($content)) {
+ return PEAR::raiseError(
+ 'Message is invalid', MAIL_MBOX_ERROR_MSG_INVALID,
+ );
+ }
- // writing only undeleted messages
- $messages = $this->size();
- $content = $this->_escapeMessage($content);
+ if ($this->hasBeenModified()) {
+ return PEAR::raiseError(
+ 'File has been modified since loading. Re-open the file.',
+ MAIL_MBOX_ERROR_MODIFIED,
+ );
+ }
- if ($messages == 0 && $offset !== null) {
- fwrite($ftemp, $content, strlen($content));
- } else {
- for ($x = 0; $x < $messages; $x++) {
- if ($offset !== null && $x == $offset) {
- fwrite($ftemp, $content, strlen($content));
- }
- $messageThis = $this->_escapeMessage($this->get($x));
+ // optimize insert() to use append whenever possible
+ if ($offset < 0 || $offset == $this->size() || $this->size() == 0) {
+ return $this->append($content);
+ }
- if (is_string($messageThis)) {
- fwrite($ftemp, $messageThis, strlen($messageThis));
- }
- }
- }
+ // creating temp file
+ $ftempname = tempnam($this->tmpdir, 'Mail_Mbox');
+ $ftemp = fopen($ftempname, 'w');
+ if ($ftemp === false) {
+ return PEAR::raiseError(
+ 'Cannot create temp file "' . $ftempname . '".',
+ MAIL_MBOX_ERROR_CANNOT_CREATE_TMP,
+ );
+ }
- if ($offset === null) {
- fwrite($ftemp, $content, strlen($content));
- }
+ // writing only undeleted messages
+ $messages = $this->size();
+ $content = $this->_escapeMessage($content);
- // closing file
- $this->close();
- fclose($ftemp);
+ if ($messages == 0 && $offset !== null) {
+ fwrite($ftemp, $content, strlen($content));
+ } else {
+ for ($x = 0; $x < $messages; $x++) {
+ if ($offset !== null && $x == $offset) {
+ fwrite($ftemp, $content, strlen($content));
+ }
+ $messageThis = $this->_escapeMessage($this->get($x));
- return $this->_move($ftempname, $this->_file);
- }
+ if (is_string($messageThis)) {
+ fwrite($ftemp, $messageThis, strlen($messageThis));
+ }
+ }
+ }
- /**
- * Appends a message at the end of the file.
- *
- * This method is also used by insert() since it's faster.
- *
- * @param string $content The content of the new message
- *
- * @return mixed Return true else PEAR_Error object
- * @access public
- */
- function append($content)
- {
- if (!$this->_isValid($content)) {
- return PEAR::raiseError(
- 'Message is invalid', MAIL_MBOX_ERROR_MSG_INVALID
- );
- }
+ if ($offset === null) {
+ fwrite($ftemp, $content, strlen($content));
+ }
- $this->close();
- $content = $this->_escapeMessage($content);
+ // closing file
+ $this->close();
+ fclose($ftemp);
- $fp = fopen($this->_file, 'a');
- if ($fp === false) {
- return PEAR::raiseError(
- 'Cannot open file "' . $this->_file . '" for appending.',
- MAIL_MBOX_ERROR_CANNOT_OPEN
- );
- }
+ return $this->_move($ftempname, $this->_file);
+ }
- if (fwrite($fp, $content, strlen($content)) === false) {
- return PEAR::raiseError(
- 'Cannot write to file "' . $this->_file. '".',
- MAIL_MBOX_ERROR_CANNOT_WRITE
- );
- }
+ /**
+ * Appends a message at the end of the file.
+ *
+ * This method is also used by insert() since it's faster.
+ *
+ * @param string $content The content of the new message
+ *
+ * @return mixed Return true else PEAR_Error object
+ * @access public
+ */
+ function append($content)
+ {
+ if (!$this->_isValid($content)) {
+ return PEAR::raiseError(
+ 'Message is invalid', MAIL_MBOX_ERROR_MSG_INVALID,
+ );
+ }
- return $this->_reopen();
- }
+ $this->close();
+ $content = $this->_escapeMessage($content);
- /**
- * Checks if the given message is valid.
- * If it was invalid and we'd add it to the file,
- * it would get unreadable
- *
- * @param string $content Message to be added or updated
- *
- * @return boolean True if it is valid, false if not
- */
- function _isValid($content)
- {
- if (substr($content, 0, 5) != 'From ') {
- return false;
- }
+ $fp = fopen($this->_file, 'a');
+ if ($fp === false) {
+ return PEAR::raiseError(
+ 'Cannot open file "' . $this->_file . '" for appending.',
+ MAIL_MBOX_ERROR_CANNOT_OPEN,
+ );
+ }
- return true;
- }
+ if (fwrite($fp, $content, strlen($content)) === false) {
+ return PEAR::raiseError(
+ 'Cannot write to file "' . $this->_file. '".',
+ MAIL_MBOX_ERROR_CANNOT_WRITE,
+ );
+ }
- /**
- * Move a file to another.
- *
- * Used internally to move the content of the temp file to the mbox file.
- * Note that we can't use rename() internally, as it behaves very, very
- * strange on windows.
- *
- * @param string $ftempname Source file - will be removed
- * @param string $filename Output file
- *
- * @return boolean|PEAR_Error True if everything went fine, PEAR_Error when
- * an error happened.
- * @access protected
- */
- function _move($ftempname, $filename)
- {
- if (!copy($ftempname, $filename)) {
- return PEAR::raiseError(
- 'Cannot copy "' . $ftempname . '" to "' . $filename . '".',
- MAIL_MBOX_ERROR_CANNOT_WRITE
- );
- }
+ return $this->_reopen();
+ }
- unlink($ftempname);
+ /**
+ * Checks if the given message is valid.
+ * If it was invalid and we'd add it to the file,
+ * it would get unreadable
+ *
+ * @param string $content Message to be added or updated
+ *
+ * @return boolean True if it is valid, false if not
+ */
+ function _isValid($content)
+ {
+ if (substr($content, 0, 5) != 'From ') {
+ return false;
+ }
- // open another resource and substitute it to the old one
- $this->_file = $filename;
- return $this->_reopen();
- }
+ return true;
+ }
- /**
- * Process the Mbox
- *
- * Put start bytes and end bytes of each message into _index array
- *
- * @return boolean|PEAR_Error True if all went ok, PEAR_Error on failure
- * @access protected
- */
- function _process()
- {
- $this->_index = array();
+ /**
+ * Move a file to another.
+ *
+ * Used internally to move the content of the temp file to the mbox file.
+ * Note that we can't use rename() internally, as it behaves very, very
+ * strange on windows.
+ *
+ * @param string $ftempname Source file - will be removed
+ * @param string $filename Output file
+ *
+ * @return boolean|PEAR_Error True if everything went fine, PEAR_Error when
+ * an error happened.
+ * @access protected
+ */
+ function _move($ftempname, $filename)
+ {
+ if (!copy($ftempname, $filename)) {
+ return PEAR::raiseError(
+ 'Cannot copy "' . $ftempname . '" to "' . $filename . '".',
+ MAIL_MBOX_ERROR_CANNOT_WRITE,
+ );
+ }
- // sanity check
- if (!is_resource($this->_resource)) {
- return PEAR::raiseError(
- 'Resource is not valid. Maybe the file has not be opened?',
- MAIL_MBOX_ERROR_NOT_OPEN
- );
- }
+ unlink($ftempname);
- // going to start
- if (fseek($this->_resource, 0) == -1) {
- return PEAR::raiseError(
- 'Cannot read mbox',
- MAIL_MBOX_ERROR_CANNOT_READ
- );
- }
+ // open another resource and substitute it to the old one
+ $this->_file = $filename;
+ return $this->_reopen();
+ }
- // current start byte position
- $start = 0;
- // last start byte position
- $laststart = 0;
- // there aren't any message
- $hasmessage = false;
+ /**
+ * Process the Mbox
+ *
+ * Put start bytes and end bytes of each message into _index array
+ *
+ * @return boolean|PEAR_Error True if all went ok, PEAR_Error on failure
+ * @access protected
+ */
+ function _process()
+ {
+ $this->_index = [];
- while ($line = fgets($this->_resource, 4096)) {
- // if line start with "From ", it is a new message
- if (0 === strncmp($line, 'From ', 5)) {
- // save last start byte position
- $laststart = $start;
+ // sanity check
+ if (!is_resource($this->_resource)) {
+ return PEAR::raiseError(
+ 'Resource is not valid. Maybe the file has not be opened?',
+ MAIL_MBOX_ERROR_NOT_OPEN,
+ );
+ }
- // new start byte position is the start of the line
- $start = ftell($this->_resource) - strlen($line);
+ // going to start
+ if (fseek($this->_resource, 0) == -1) {
+ return PEAR::raiseError(
+ 'Cannot read mbox',
+ MAIL_MBOX_ERROR_CANNOT_READ,
+ );
+ }
- // if it is not the first message add message positions
- if ($start > 0) {
- $this->_index[] = array($laststart, $start - 1);
- } else {
- // tell that there is really a message on the file
- $hasmessage = true;
- }
- }
- }
+ // current start byte position
+ $start = 0;
+ // last start byte position
+ $laststart = 0;
+ // there aren't any message
+ $hasmessage = false;
- // if there are just one message, or if it's the last one,
- // add it to messages positions
- if (($start == 0 && $hasmessage === true) || ($start > 0)) {
- $this->_index[] = array($start, ftell($this->_resource));
- }
+ while ($line = fgets($this->_resource, 4096)) {
+ // if line start with "From ", it is a new message
+ if (0 === strncmp($line, 'From ', 5)) {
+ // save last start byte position
+ $laststart = $start;
- return true;
- }
+ // new start byte position is the start of the line
+ $start = ftell($this->_resource) - strlen($line);
- /**
- * Quotes "From " lines in the midst of the message.
- * And quoted "From " lines, too :)
- * Also appends the trailing newline.
- * After escaping, the message can be written to file.
- *
- * @param string $message Message content
- *
- * @return string Escaped message
- *
- * @access protected
- * @see _unescapeMessage()
- */
- function _escapeMessage($message)
- {
- if (substr($message, -1) == "\n") {
- $message .= "\n";
- } else {
- $message .= "\n\n";
- }
- return preg_replace(
- "/\n([>]*From )/",
- "\n>$1",
- $message
- );
- }
+ // if it is not the first message add message positions
+ if ($start > 0) {
+ $this->_index[] = [$laststart, $start - 1];
+ } else {
+ // tell that there is really a message on the file
+ $hasmessage = true;
+ }
+ }
+ }
- /**
- * Removes quoted "From " lines from the message
- *
- * @param string $message Message content
- *
- * @return string Unescaped message
- *
- * @access protected
- * @see _escapeMessage()
- */
- function _unescapeMessage($message)
- {
- return preg_replace(
- "/\n>([>]*From )/",
- "\n$1",
- //the -1 drops the last newline
- substr($message, 0, -1)
- );
- }
+ // if there are just one message, or if it's the last one,
+ // add it to messages positions
+ if (($start == 0 && $hasmessage === true) || ($start > 0)) {
+ $this->_index[] = [$start, ftell($this->_resource)];
+ }
- /**
- * Checks if the file was modified since it has been loaded.
- * If this is true, the file needs to be re-opened.
- *
- * @return bool True if it has been modified.
- * @access public
- */
- function hasBeenModified()
- {
- return filemtime($this->_file) > $this->_lastModified;
- }
+ return true;
+ }
+ /**
+ * Quotes "From " lines in the midst of the message.
+ * And quoted "From " lines, too :)
+ * Also appends the trailing newline.
+ * After escaping, the message can be written to file.
+ *
+ * @param string $message Message content
+ *
+ * @return string Escaped message
+ *
+ * @access protected
+ * @see _unescapeMessage()
+ */
+ function _escapeMessage($message)
+ {
+ if (substr($message, -1) == "\n") {
+ $message .= "\n";
+ } else {
+ $message .= "\n\n";
+ }
+ return preg_replace(
+ "/\n([>]*From )/",
+ "\n>$1",
+ $message,
+ );
+ }
+ /**
+ * Removes quoted "From " lines from the message
+ *
+ * @param string $message Message content
+ *
+ * @return string Unescaped message
+ *
+ * @access protected
+ * @see _escapeMessage()
+ */
+ function _unescapeMessage($message)
+ {
+ return preg_replace(
+ "/\n>([>]*From )/",
+ "\n$1",
+ //the -1 drops the last newline
+ substr($message, 0, -1),
+ );
+ }
- /*
- * Dumb getter and setter
- */
+ /**
+ * Checks if the file was modified since it has been loaded.
+ * If this is true, the file needs to be re-opened.
+ *
+ * @return bool True if it has been modified.
+ * @access public
+ */
+ function hasBeenModified()
+ {
+ return filemtime($this->_file) > $this->_lastModified;
+ }
+ /*
+ * Dumb getter and setter
+ */
+ /**
+ * Set the directory for temporary files.
+ *
+ * @param string $tmpdir The new temporary directory
+ *
+ * @return mixed True if all is ok, PEAR_Error if $tmpdir
+ * is a dir but not writable
+ *
+ * @see Mail_Mbox::$tmpdir
+ */
+ function setTmpDir($tmpdir)
+ {
+ if (is_dir($tmpdir) && !is_writable($tmpdir)) {
+ return PEAR::raiseError(
+ '"' . $tmpdir . '" is not writable.',
+ MAIL_MBOX_ERROR_CANNOT_WRITE,
+ );
+ }
+ $this->tmpdir = $tmpdir;
+ return true;
- /**
- * Set the directory for temporary files.
- *
- * @param string $tmpdir The new temporary directory
- *
- * @return mixed True if all is ok, PEAR_Error if $tmpdir
- * is a dir but not writable
- *
- * @see Mail_Mbox::$tmpdir
- */
- function setTmpDir($tmpdir)
- {
- if (is_dir($tmpdir) && !is_writable($tmpdir)) {
- return PEAR::raiseError(
- '"' . $tmpdir . '" is not writable.',
- MAIL_MBOX_ERROR_CANNOT_WRITE
- );
- } else {
- $this->tmpdir = $tmpdir;
- return true;
- }
- }
+ }
- /**
- * Returns the temporary directory
- *
- * @return string The temporary directory
- */
- function getTmpDir()
- {
- return $this->tmpdir;
- }
+ /**
+ * Returns the temporary directory
+ *
+ * @return string The temporary directory
+ */
+ function getTmpDir()
+ {
+ return $this->tmpdir;
+ }
- /**
- * Set the debug flag
- *
- * @param bool $debug If debug is on or off
- *
- * @return void
- * @see Mail_Mbox::$debug
- */
- function setDebug($debug)
- {
- $this->debug = (bool)$debug;
- }
+ /**
+ * Set the debug flag
+ *
+ * @param bool $debug If debug is on or off
+ *
+ * @return void
+ * @see Mail_Mbox::$debug
+ */
+ function setDebug($debug)
+ {
+ $this->debug = (bool)$debug;
+ }
- /**
- * Returns the debug flag setting
- *
- * @see Mail_Mbox::$debug
- *
- * @return bool If debug is enabled.
- */
- function getDebug()
- {
- return $this->debug;
- }
+ /**
+ * Returns the debug flag setting
+ *
+ * @see Mail_Mbox::$debug
+ *
+ * @return bool If debug is enabled.
+ */
+ function getDebug()
+ {
+ return $this->debug;
+ }
- /**
- * Sets if the mbox is reloaded after modification
- * automatically.
- *
- * @param bool $autoReopen If the mbox is reloaded automatically
- *
- * @return void
- * @see Mail_Mbox::$autoReopen
- */
- function setAutoReopen($autoReopen)
- {
- $this->autoReopen = (bool)$autoReopen;
- }
+ /**
+ * Sets if the mbox is reloaded after modification
+ * automatically.
+ *
+ * @param bool $autoReopen If the mbox is reloaded automatically
+ *
+ * @return void
+ * @see Mail_Mbox::$autoReopen
+ */
+ function setAutoReopen($autoReopen)
+ {
+ $this->autoReopen = (bool)$autoReopen;
+ }
- /**
- * Returns the automatically reopening setting
- *
- * @return bool If the mbox is reloaded automatically.
- *
- * @see Mail_Mbox::$autoReopen
- */
- function getAutoReopen()
- {
- return $this->autoReopen;
- }
+ /**
+ * Returns the automatically reopening setting
+ *
+ * @return bool If the mbox is reloaded automatically.
+ *
+ * @see Mail_Mbox::$autoReopen
+ */
+ function getAutoReopen()
+ {
+ return $this->autoReopen;
+ }
}
?>
diff --git a/import/load_contacts.php b/import/load_contacts.php
index 23a3a38..d23f77f 100755
--- a/import/load_contacts.php
+++ b/import/load_contacts.php
@@ -28,8 +28,8 @@ if ( $handle == FALSE) {
$row = -999;
} else {
while (($data = fgetcsv($handle, 800, ",")) !== FALSE) {
- if ( $row ) $contact->ContactRecordLoad( $data );
- $row++;
+ if ( $row ) $contact->ContactRecordLoad( $data );
+ $row++;
}
fclose($handle);
}
diff --git a/import/load_phx_contacts.php b/import/load_phx_contacts.php
index 264e872..35aa10b 100755
--- a/import/load_phx_contacts.php
+++ b/import/load_phx_contacts.php
@@ -28,8 +28,8 @@ if ( $handle == FALSE) {
$row = -999;
} else {
while (($data = fgetcsv($handle, 800, ",")) !== FALSE) {
- if ( $row ) $contact->PhxRecordLoad( $data, $row );
- $row++;
+ if ( $row ) $contact->PhxRecordLoad( $data, $row );
+ $row++;
}
fclose($handle);
}
diff --git a/import/load_sage_contacts.php b/import/load_sage_contacts.php
index a3fd92a..a07f9aa 100755
--- a/import/load_sage_contacts.php
+++ b/import/load_sage_contacts.php
@@ -28,8 +28,8 @@ if ( $handle == FALSE) {
$row = -999;
} else {
while (($data = fgetcsv($handle, 800, ",")) !== FALSE) {
- if ( $row ) $contact->SageRecordLoad( $data, 1 );
- $row++;
+ if ( $row ) $contact->SageRecordLoad( $data, 1 );
+ $row++;
}
fclose($handle);
}
@@ -42,8 +42,8 @@ if ( $handle == FALSE) {
$row = -999;
} else {
while (($data = fgetcsv($handle, 800, ",")) !== FALSE) {
- if ( $row ) $contact->SageRecordLoad( $data, 2 );
- $row++;
+ if ( $row ) $contact->SageRecordLoad( $data, 2 );
+ $row++;
}
fclose($handle);
}
diff --git a/import/load_wande_contacts.php b/import/load_wande_contacts.php
index c31070d..3b83b04 100755
--- a/import/load_wande_contacts.php
+++ b/import/load_wande_contacts.php
@@ -27,8 +27,8 @@ if ( $handle == FALSE) {
$row = -999;
} else {
while (($data = fgetcsv($handle, 800, ",")) !== FALSE) {
- if ( $row ) $contact->wandeRecordLoad( $data, $row );
- $row++;
+ if ( $row ) $contact->wandeRecordLoad( $data, $row );
+ $row++;
}
fclose($handle);
}
diff --git a/import/mime.php b/import/mime.php
index adfe2ad..8dc30e5 100755
--- a/import/mime.php
+++ b/import/mime.php
@@ -57,7 +57,6 @@
* and Sascha Schumann <sascha@schumann.cx>
*/
-
/**
* require PEAR
*
@@ -74,7 +73,6 @@ require_once 'PEAR.php';
*/
require_once 'Mail/mimePart.php';
-
/**
* The Mail_Mime class provides an OO interface to create MIME
* enabled email messages. This way you can create emails that
@@ -94,1364 +92,1363 @@ require_once 'Mail/mimePart.php';
*/
class Mail_mime
{
- /**
- * Contains the plain text part of the email
- *
- * @var string
- * @access private
- */
- var $_txtbody;
+ /**
+ * Contains the plain text part of the email
+ *
+ * @var string
+ * @access private
+ */
+ var $_txtbody;
+
+ /**
+ * Contains the html part of the email
+ *
+ * @var string
+ * @access private
+ */
+ var $_htmlbody;
+
+ /**
+ * list of the attached images
+ *
+ * @var array
+ * @access private
+ */
+ var $_html_images = [];
+
+ /**
+ * list of the attachements
+ *
+ * @var array
+ * @access private
+ */
+ var $_parts = [];
+
+ /**
+ * Headers for the mail
+ *
+ * @var array
+ * @access private
+ */
+ var $_headers = [];
+
+ /**
+ * Build parameters
+ *
+ * @var array
+ * @access private
+ */
+ var $_build_params = [
+ // What encoding to use for the headers
+ // Options: quoted-printable or base64
+ 'head_encoding' => 'quoted-printable',
+ // What encoding to use for plain text
+ // Options: 7bit, 8bit, base64, or quoted-printable
+ 'text_encoding' => 'quoted-printable',
+ // What encoding to use for html
+ // Options: 7bit, 8bit, base64, or quoted-printable
+ 'html_encoding' => 'quoted-printable',
+ // The character set to use for html
+ 'html_charset' => 'ISO-8859-1',
+ // The character set to use for text
+ 'text_charset' => 'ISO-8859-1',
+ // The character set to use for headers
+ 'head_charset' => 'ISO-8859-1',
+ // End-of-line sequence
+ 'eol' => "\r\n",
+ // Delay attachment files IO until building the message
+ 'delay_file_io' => false,
+ ];
+
+ /**
+ * Constructor function
+ *
+ * @param mixed $params Build parameters that change the way the email
+ * is built. Should be an associative array.
+ * See $_build_params.
+ *
+ * @return void
+ * @access public
+ */
+ function Mail_mime($params = [])
+ {
+ // Backward-compatible EOL setting
+ if (is_string($params)) {
+ $this->_build_params['eol'] = $params;
+ } else if (defined('MAIL_MIME_CRLF') && !isset($params['eol'])) {
+ $this->_build_params['eol'] = MAIL_MIME_CRLF;
+ }
- /**
- * Contains the html part of the email
- *
- * @var string
- * @access private
- */
- var $_htmlbody;
+ // Update build parameters
+ if (!empty($params) && is_array($params)) {
+ while (list($key, $value) = each($params)) {
+ $this->_build_params[$key] = $value;
+ }
+ }
+ }
- /**
- * list of the attached images
- *
- * @var array
- * @access private
- */
- var $_html_images = array();
+ /**
+ * Set build parameter value
+ *
+ * @param string $name Parameter name
+ * @param string $value Parameter value
+ *
+ * @return void
+ * @access public
+ * @since 1.6.0
+ */
+ function setParam($name, $value)
+ {
+ $this->_build_params[$name] = $value;
+ }
- /**
- * list of the attachements
- *
- * @var array
- * @access private
- */
- var $_parts = array();
+ /**
+ * Get build parameter value
+ *
+ * @param string $name Parameter name
+ *
+ * @return mixed Parameter value
+ * @access public
+ * @since 1.6.0
+ */
+ function getParam($name)
+ {
+ return $this->_build_params[$name] ?? null;
+ }
- /**
- * Headers for the mail
- *
- * @var array
- * @access private
- */
- var $_headers = array();
+ /**
+ * Accessor function to set the body text. Body text is used if
+ * it's not an html mail being sent or else is used to fill the
+ * text/plain part that emails clients who don't support
+ * html should show.
+ *
+ * @param string $data Either a string or
+ * the file name with the contents
+ * @param bool $isfile If true the first param should be treated
+ * as a file name, else as a string (default)
+ * @param bool $append If true the text or file is appended to
+ * the existing body, else the old body is
+ * overwritten
+ *
+ * @return mixed True on success or PEAR_Error object
+ * @access public
+ */
+ function setTXTBody($data, $isfile = false, $append = false)
+ {
+ if (!$isfile) {
+ if (!$append) {
+ $this->_txtbody = $data;
+ } else {
+ $this->_txtbody .= $data;
+ }
+ } else {
+ $cont = $this->_file2str($data);
+ if (PEAR::isError($cont)) {
+ return $cont;
+ }
+ if (!$append) {
+ $this->_txtbody = $cont;
+ } else {
+ $this->_txtbody .= $cont;
+ }
+ }
+ return true;
+ }
- /**
- * Build parameters
- *
- * @var array
- * @access private
- */
- var $_build_params = array(
- // What encoding to use for the headers
- // Options: quoted-printable or base64
- 'head_encoding' => 'quoted-printable',
- // What encoding to use for plain text
- // Options: 7bit, 8bit, base64, or quoted-printable
- 'text_encoding' => 'quoted-printable',
- // What encoding to use for html
- // Options: 7bit, 8bit, base64, or quoted-printable
- 'html_encoding' => 'quoted-printable',
- // The character set to use for html
- 'html_charset' => 'ISO-8859-1',
- // The character set to use for text
- 'text_charset' => 'ISO-8859-1',
- // The character set to use for headers
- 'head_charset' => 'ISO-8859-1',
- // End-of-line sequence
- 'eol' => "\r\n",
- // Delay attachment files IO until building the message
- 'delay_file_io' => false
- );
+ /**
+ * Get message text body
+ *
+ * @return string Text body
+ * @access public
+ * @since 1.6.0
+ */
+ function getTXTBody()
+ {
+ return $this->_txtbody;
+ }
- /**
- * Constructor function
- *
- * @param mixed $params Build parameters that change the way the email
- * is built. Should be an associative array.
- * See $_build_params.
- *
- * @return void
- * @access public
- */
- function Mail_mime($params = array())
- {
- // Backward-compatible EOL setting
- if (is_string($params)) {
- $this->_build_params['eol'] = $params;
- } else if (defined('MAIL_MIME_CRLF') && !isset($params['eol'])) {
- $this->_build_params['eol'] = MAIL_MIME_CRLF;
- }
+ /**
+ * Adds a html part to the mail.
+ *
+ * @param string $data Either a string or the file name with the
+ * contents
+ * @param bool $isfile A flag that determines whether $data is a
+ * filename, or a string(false, default)
+ *
+ * @return bool True on success
+ * @access public
+ */
+ function setHTMLBody($data, $isfile = false)
+ {
+ if (!$isfile) {
+ $this->_htmlbody = $data;
+ } else {
+ $cont = $this->_file2str($data);
+ if (PEAR::isError($cont)) {
+ return $cont;
+ }
+ $this->_htmlbody = $cont;
+ }
- // Update build parameters
- if (!empty($params) && is_array($params)) {
- while (list($key, $value) = each($params)) {
- $this->_build_params[$key] = $value;
- }
- }
- }
+ return true;
+ }
- /**
- * Set build parameter value
- *
- * @param string $name Parameter name
- * @param string $value Parameter value
- *
- * @return void
- * @access public
- * @since 1.6.0
- */
- function setParam($name, $value)
- {
- $this->_build_params[$name] = $value;
- }
+ /**
+ * Get message HTML body
+ *
+ * @return string HTML body
+ * @access public
+ * @since 1.6.0
+ */
+ function getHTMLBody()
+ {
+ return $this->_htmlbody;
+ }
- /**
- * Get build parameter value
- *
- * @param string $name Parameter name
- *
- * @return mixed Parameter value
- * @access public
- * @since 1.6.0
- */
- function getParam($name)
- {
- return isset($this->_build_params[$name]) ? $this->_build_params[$name] : null;
- }
+ /**
+ * Adds an image to the list of embedded images.
+ *
+ * @param string $file The image file name OR image data itself
+ * @param string $c_type The content type
+ * @param string $name The filename of the image.
+ * Only used if $file is the image data.
+ * @param bool $isfile Whether $file is a filename or not.
+ * Defaults to true
+ * @param string $content_id Desired Content-ID of MIME part
+ * Defaults to generated unique ID
+ *
+ * @return bool True on success
+ * @access public
+ */
+ function addHTMLImage($file,
+ $c_type='application/octet-stream',
+ $name = '',
+ $isfile = true,
+ $content_id = null,
+ ) {
+ $bodyfile = null;
- /**
- * Accessor function to set the body text. Body text is used if
- * it's not an html mail being sent or else is used to fill the
- * text/plain part that emails clients who don't support
- * html should show.
- *
- * @param string $data Either a string or
- * the file name with the contents
- * @param bool $isfile If true the first param should be treated
- * as a file name, else as a string (default)
- * @param bool $append If true the text or file is appended to
- * the existing body, else the old body is
- * overwritten
- *
- * @return mixed True on success or PEAR_Error object
- * @access public
- */
- function setTXTBody($data, $isfile = false, $append = false)
- {
- if (!$isfile) {
- if (!$append) {
- $this->_txtbody = $data;
- } else {
- $this->_txtbody .= $data;
- }
- } else {
- $cont = $this->_file2str($data);
- if (PEAR::isError($cont)) {
- return $cont;
- }
- if (!$append) {
- $this->_txtbody = $cont;
- } else {
- $this->_txtbody .= $cont;
- }
- }
- return true;
- }
+ if ($isfile) {
+ // Don't load file into memory
+ if ($this->_build_params['delay_file_io']) {
+ $filedata = null;
+ $bodyfile = $file;
+ } else {
+ if (PEAR::isError($filedata = $this->_file2str($file))) {
+ return $filedata;
+ }
+ }
+ $filename = ($name ? $name : $file);
+ } else {
+ $filedata = $file;
+ $filename = $name;
+ }
- /**
- * Get message text body
- *
- * @return string Text body
- * @access public
- * @since 1.6.0
- */
- function getTXTBody()
- {
- return $this->_txtbody;
- }
+ if (!$content_id) {
+ $content_id = md5(uniqid(time()));
+ }
- /**
- * Adds a html part to the mail.
- *
- * @param string $data Either a string or the file name with the
- * contents
- * @param bool $isfile A flag that determines whether $data is a
- * filename, or a string(false, default)
- *
- * @return bool True on success
- * @access public
- */
- function setHTMLBody($data, $isfile = false)
- {
- if (!$isfile) {
- $this->_htmlbody = $data;
- } else {
- $cont = $this->_file2str($data);
- if (PEAR::isError($cont)) {
- return $cont;
- }
- $this->_htmlbody = $cont;
- }
+ $this->_html_images[] = [
+ 'body' => $filedata,
+ 'body_file' => $bodyfile,
+ 'name' => $filename,
+ 'c_type' => $c_type,
+ 'cid' => $content_id,
+ ];
- return true;
- }
+ return true;
+ }
- /**
- * Get message HTML body
- *
- * @return string HTML body
- * @access public
- * @since 1.6.0
- */
- function getHTMLBody()
- {
- return $this->_htmlbody;
- }
+ /**
+ * Adds a file to the list of attachments.
+ *
+ * @param string $file The file name of the file to attach
+ * OR the file contents itself
+ * @param string $c_type The content type
+ * @param string $name The filename of the attachment
+ * Only use if $file is the contents
+ * @param bool $isfile Whether $file is a filename or not
+ * Defaults to true
+ * @param string $encoding The type of encoding to use.
+ * Defaults to base64.
+ * Possible values: 7bit, 8bit, base64,
+ * or quoted-printable.
+ * @param string $disposition The content-disposition of this file
+ * Defaults to attachment.
+ * Possible values: attachment, inline.
+ * @param string $charset The character set used in the filename
+ * of this attachment.
+ * @param string $language The language of the attachment
+ * @param string $location The RFC 2557.4 location of the attachment
+ * @param string $n_encoding Encoding for attachment name (Content-Type)
+ * By default filenames are encoded using RFC2231 method
+ * Here you can set RFC2047 encoding (quoted-printable
+ * or base64) instead
+ * @param string $f_encoding Encoding for attachment filename (Content-Disposition)
+ * See $n_encoding description
+ * @param string $description Content-Description header
+ *
+ * @return mixed True on success or PEAR_Error object
+ * @access public
+ */
+ function addAttachment($file,
+ $c_type = 'application/octet-stream',
+ $name = '',
+ $isfile = true,
+ $encoding = 'base64',
+ $disposition = 'attachment',
+ $charset = '',
+ $language = '',
+ $location = '',
+ $n_encoding = null,
+ $f_encoding = null,
+ $description = '',
+ ) {
+ $bodyfile = null;
- /**
- * Adds an image to the list of embedded images.
- *
- * @param string $file The image file name OR image data itself
- * @param string $c_type The content type
- * @param string $name The filename of the image.
- * Only used if $file is the image data.
- * @param bool $isfile Whether $file is a filename or not.
- * Defaults to true
- * @param string $content_id Desired Content-ID of MIME part
- * Defaults to generated unique ID
- *
- * @return bool True on success
- * @access public
- */
- function addHTMLImage($file,
- $c_type='application/octet-stream',
- $name = '',
- $isfile = true,
- $content_id = null
- ) {
- $bodyfile = null;
+ if ($isfile) {
+ // Don't load file into memory
+ if ($this->_build_params['delay_file_io']) {
+ $filedata = null;
+ $bodyfile = $file;
+ } else {
+ if (PEAR::isError($filedata = $this->_file2str($file))) {
+ return $filedata;
+ }
+ }
+ // Force the name the user supplied, otherwise use $file
+ $filename = ($name ? $name : $file);
+ } else {
+ $filedata = $file;
+ $filename = $name;
+ }
- if ($isfile) {
- // Don't load file into memory
- if ($this->_build_params['delay_file_io']) {
- $filedata = null;
- $bodyfile = $file;
- } else {
- if (PEAR::isError($filedata = $this->_file2str($file))) {
- return $filedata;
- }
- }
- $filename = ($name ? $name : $file);
- } else {
- $filedata = $file;
- $filename = $name;
- }
+ if (!strlen($filename)) {
+ $msg = "The supplied filename for the attachment can't be empty";
+ $err = PEAR::raiseError($msg);
+ return $err;
+ }
+ $filename = $this->_basename($filename);
- if (!$content_id) {
- $content_id = md5(uniqid(time()));
- }
+ $this->_parts[] = [
+ 'body' => $filedata,
+ 'body_file' => $bodyfile,
+ 'name' => $filename,
+ 'c_type' => $c_type,
+ 'encoding' => $encoding,
+ 'charset' => $charset,
+ 'language' => $language,
+ 'location' => $location,
+ 'disposition' => $disposition,
+ 'description' => $description,
+ 'name_encoding' => $n_encoding,
+ 'filename_encoding' => $f_encoding,
+ ];
- $this->_html_images[] = array(
- 'body' => $filedata,
- 'body_file' => $bodyfile,
- 'name' => $filename,
- 'c_type' => $c_type,
- 'cid' => $content_id
- );
+ return true;
+ }
- return true;
- }
+ /**
+ * Get the contents of the given file name as string
+ *
+ * @param string $file_name Path of file to process
+ *
+ * @return string Contents of $file_name
+ * @access private
+ */
+ function &_file2str($file_name)
+ {
+ // Check state of file and raise an error properly
+ if (!file_exists($file_name)) {
+ $err = PEAR::raiseError('File not found: ' . $file_name);
+ return $err;
+ }
+ if (!is_file($file_name)) {
+ $err = PEAR::raiseError('Not a regular file: ' . $file_name);
+ return $err;
+ }
+ if (!is_readable($file_name)) {
+ $err = PEAR::raiseError('File is not readable: ' . $file_name);
+ return $err;
+ }
- /**
- * Adds a file to the list of attachments.
- *
- * @param string $file The file name of the file to attach
- * OR the file contents itself
- * @param string $c_type The content type
- * @param string $name The filename of the attachment
- * Only use if $file is the contents
- * @param bool $isfile Whether $file is a filename or not
- * Defaults to true
- * @param string $encoding The type of encoding to use.
- * Defaults to base64.
- * Possible values: 7bit, 8bit, base64,
- * or quoted-printable.
- * @param string $disposition The content-disposition of this file
- * Defaults to attachment.
- * Possible values: attachment, inline.
- * @param string $charset The character set used in the filename
- * of this attachment.
- * @param string $language The language of the attachment
- * @param string $location The RFC 2557.4 location of the attachment
- * @param string $n_encoding Encoding for attachment name (Content-Type)
- * By default filenames are encoded using RFC2231 method
- * Here you can set RFC2047 encoding (quoted-printable
- * or base64) instead
- * @param string $f_encoding Encoding for attachment filename (Content-Disposition)
- * See $n_encoding description
- * @param string $description Content-Description header
- *
- * @return mixed True on success or PEAR_Error object
- * @access public
- */
- function addAttachment($file,
- $c_type = 'application/octet-stream',
- $name = '',
- $isfile = true,
- $encoding = 'base64',
- $disposition = 'attachment',
- $charset = '',
- $language = '',
- $location = '',
- $n_encoding = null,
- $f_encoding = null,
- $description = ''
- ) {
- $bodyfile = null;
+ // Temporarily reset magic_quotes_runtime and read file contents
+ if ($magic_quote_setting = get_magic_quotes_runtime()) {
+ @ini_set('magic_quotes_runtime', 0);
+ }
+ $cont = file_get_contents($file_name);
+ if ($magic_quote_setting) {
+ @ini_set('magic_quotes_runtime', $magic_quote_setting);
+ }
- if ($isfile) {
- // Don't load file into memory
- if ($this->_build_params['delay_file_io']) {
- $filedata = null;
- $bodyfile = $file;
- } else {
- if (PEAR::isError($filedata = $this->_file2str($file))) {
- return $filedata;
- }
- }
- // Force the name the user supplied, otherwise use $file
- $filename = ($name ? $name : $file);
- } else {
- $filedata = $file;
- $filename = $name;
- }
+ return $cont;
+ }
- if (!strlen($filename)) {
- $msg = "The supplied filename for the attachment can't be empty";
- $err = PEAR::raiseError($msg);
- return $err;
- }
- $filename = $this->_basename($filename);
+ /**
+ * Adds a text subpart to the mimePart object and
+ * returns it during the build process.
+ *
+ * @param mixed &$obj The object to add the part to, or
+ * null if a new object is to be created.
+ * @param string $text The text to add.
+ *
+ * @return object The text mimePart object
+ * @access private
+ */
+ function &_addTextPart(&$obj, $text)
+ {
+ $params['content_type'] = 'text/plain';
+ $params['encoding'] = $this->_build_params['text_encoding'];
+ $params['charset'] = $this->_build_params['text_charset'];
+ $params['eol'] = $this->_build_params['eol'];
- $this->_parts[] = array(
- 'body' => $filedata,
- 'body_file' => $bodyfile,
- 'name' => $filename,
- 'c_type' => $c_type,
- 'encoding' => $encoding,
- 'charset' => $charset,
- 'language' => $language,
- 'location' => $location,
- 'disposition' => $disposition,
- 'description' => $description,
- 'name_encoding' => $n_encoding,
- 'filename_encoding' => $f_encoding
- );
+ if (is_object($obj)) {
+ $ret = $obj->addSubpart($text, $params);
+ return $ret;
+ }
+ $ret = new Mail_mimePart($text, $params);
+ return $ret;
- return true;
- }
+ }
- /**
- * Get the contents of the given file name as string
- *
- * @param string $file_name Path of file to process
- *
- * @return string Contents of $file_name
- * @access private
- */
- function &_file2str($file_name)
- {
- // Check state of file and raise an error properly
- if (!file_exists($file_name)) {
- $err = PEAR::raiseError('File not found: ' . $file_name);
- return $err;
- }
- if (!is_file($file_name)) {
- $err = PEAR::raiseError('Not a regular file: ' . $file_name);
- return $err;
- }
- if (!is_readable($file_name)) {
- $err = PEAR::raiseError('File is not readable: ' . $file_name);
- return $err;
- }
+ /**
+ * Adds a html subpart to the mimePart object and
+ * returns it during the build process.
+ *
+ * @param mixed &$obj The object to add the part to, or
+ * null if a new object is to be created.
+ *
+ * @return object The html mimePart object
+ * @access private
+ */
+ function &_addHtmlPart(&$obj)
+ {
+ $params['content_type'] = 'text/html';
+ $params['encoding'] = $this->_build_params['html_encoding'];
+ $params['charset'] = $this->_build_params['html_charset'];
+ $params['eol'] = $this->_build_params['eol'];
- // Temporarily reset magic_quotes_runtime and read file contents
- if ($magic_quote_setting = get_magic_quotes_runtime()) {
- @ini_set('magic_quotes_runtime', 0);
- }
- $cont = file_get_contents($file_name);
- if ($magic_quote_setting) {
- @ini_set('magic_quotes_runtime', $magic_quote_setting);
- }
+ if (is_object($obj)) {
+ $ret = $obj->addSubpart($this->_htmlbody, $params);
+ return $ret;
+ }
+ $ret = new Mail_mimePart($this->_htmlbody, $params);
+ return $ret;
- return $cont;
- }
+ }
- /**
- * Adds a text subpart to the mimePart object and
- * returns it during the build process.
- *
- * @param mixed &$obj The object to add the part to, or
- * null if a new object is to be created.
- * @param string $text The text to add.
- *
- * @return object The text mimePart object
- * @access private
- */
- function &_addTextPart(&$obj, $text)
- {
- $params['content_type'] = 'text/plain';
- $params['encoding'] = $this->_build_params['text_encoding'];
- $params['charset'] = $this->_build_params['text_charset'];
- $params['eol'] = $this->_build_params['eol'];
+ /**
+ * Creates a new mimePart object, using multipart/mixed as
+ * the initial content-type and returns it during the
+ * build process.
+ *
+ * @return object The multipart/mixed mimePart object
+ * @access private
+ */
+ function &_addMixedPart()
+ {
+ $params = [];
+ $params['content_type'] = 'multipart/mixed';
+ $params['eol'] = $this->_build_params['eol'];
- if (is_object($obj)) {
- $ret = $obj->addSubpart($text, $params);
- return $ret;
- } else {
- $ret = new Mail_mimePart($text, $params);
- return $ret;
- }
- }
+ // Create empty multipart/mixed Mail_mimePart object to return
+ $ret = new Mail_mimePart('', $params);
+ return $ret;
+ }
- /**
- * Adds a html subpart to the mimePart object and
- * returns it during the build process.
- *
- * @param mixed &$obj The object to add the part to, or
- * null if a new object is to be created.
- *
- * @return object The html mimePart object
- * @access private
- */
- function &_addHtmlPart(&$obj)
- {
- $params['content_type'] = 'text/html';
- $params['encoding'] = $this->_build_params['html_encoding'];
- $params['charset'] = $this->_build_params['html_charset'];
- $params['eol'] = $this->_build_params['eol'];
+ /**
+ * Adds a multipart/alternative part to a mimePart
+ * object (or creates one), and returns it during
+ * the build process.
+ *
+ * @param mixed &$obj The object to add the part to, or
+ * null if a new object is to be created.
+ *
+ * @return object The multipart/mixed mimePart object
+ * @access private
+ */
+ function &_addAlternativePart(&$obj)
+ {
+ $params['content_type'] = 'multipart/alternative';
+ $params['eol'] = $this->_build_params['eol'];
- if (is_object($obj)) {
- $ret = $obj->addSubpart($this->_htmlbody, $params);
- return $ret;
- } else {
- $ret = new Mail_mimePart($this->_htmlbody, $params);
- return $ret;
- }
- }
+ if (is_object($obj)) {
+ return $obj->addSubpart('', $params);
+ }
+ $ret = new Mail_mimePart('', $params);
+ return $ret;
- /**
- * Creates a new mimePart object, using multipart/mixed as
- * the initial content-type and returns it during the
- * build process.
- *
- * @return object The multipart/mixed mimePart object
- * @access private
- */
- function &_addMixedPart()
- {
- $params = array();
- $params['content_type'] = 'multipart/mixed';
- $params['eol'] = $this->_build_params['eol'];
+ }
- // Create empty multipart/mixed Mail_mimePart object to return
- $ret = new Mail_mimePart('', $params);
- return $ret;
- }
+ /**
+ * Adds a multipart/related part to a mimePart
+ * object (or creates one), and returns it during
+ * the build process.
+ *
+ * @param mixed &$obj The object to add the part to, or
+ * null if a new object is to be created
+ *
+ * @return object The multipart/mixed mimePart object
+ * @access private
+ */
+ function &_addRelatedPart(&$obj)
+ {
+ $params['content_type'] = 'multipart/related';
+ $params['eol'] = $this->_build_params['eol'];
- /**
- * Adds a multipart/alternative part to a mimePart
- * object (or creates one), and returns it during
- * the build process.
- *
- * @param mixed &$obj The object to add the part to, or
- * null if a new object is to be created.
- *
- * @return object The multipart/mixed mimePart object
- * @access private
- */
- function &_addAlternativePart(&$obj)
- {
- $params['content_type'] = 'multipart/alternative';
- $params['eol'] = $this->_build_params['eol'];
+ if (is_object($obj)) {
+ return $obj->addSubpart('', $params);
+ }
+ $ret = new Mail_mimePart('', $params);
+ return $ret;
- if (is_object($obj)) {
- return $obj->addSubpart('', $params);
- } else {
- $ret = new Mail_mimePart('', $params);
- return $ret;
- }
- }
+ }
- /**
- * Adds a multipart/related part to a mimePart
- * object (or creates one), and returns it during
- * the build process.
- *
- * @param mixed &$obj The object to add the part to, or
- * null if a new object is to be created
- *
- * @return object The multipart/mixed mimePart object
- * @access private
- */
- function &_addRelatedPart(&$obj)
- {
- $params['content_type'] = 'multipart/related';
- $params['eol'] = $this->_build_params['eol'];
+ /**
+ * Adds an html image subpart to a mimePart object
+ * and returns it during the build process.
+ *
+ * @param object &$obj The mimePart to add the image to
+ * @param array $value The image information
+ *
+ * @return object The image mimePart object
+ * @access private
+ */
+ function &_addHtmlImagePart(&$obj, $value)
+ {
+ $params['content_type'] = $value['c_type'];
+ $params['encoding'] = 'base64';
+ $params['disposition'] = 'inline';
+ $params['dfilename'] = $value['name'];
+ $params['cid'] = $value['cid'];
+ $params['body_file'] = $value['body_file'];
+ $params['eol'] = $this->_build_params['eol'];
- if (is_object($obj)) {
- return $obj->addSubpart('', $params);
- } else {
- $ret = new Mail_mimePart('', $params);
- return $ret;
- }
- }
+ if (!empty($value['name_encoding'])) {
+ $params['name_encoding'] = $value['name_encoding'];
+ }
+ if (!empty($value['filename_encoding'])) {
+ $params['filename_encoding'] = $value['filename_encoding'];
+ }
- /**
- * Adds an html image subpart to a mimePart object
- * and returns it during the build process.
- *
- * @param object &$obj The mimePart to add the image to
- * @param array $value The image information
- *
- * @return object The image mimePart object
- * @access private
- */
- function &_addHtmlImagePart(&$obj, $value)
- {
- $params['content_type'] = $value['c_type'];
- $params['encoding'] = 'base64';
- $params['disposition'] = 'inline';
- $params['dfilename'] = $value['name'];
- $params['cid'] = $value['cid'];
- $params['body_file'] = $value['body_file'];
- $params['eol'] = $this->_build_params['eol'];
+ $ret = $obj->addSubpart($value['body'], $params);
+ return $ret;
+ }
- if (!empty($value['name_encoding'])) {
- $params['name_encoding'] = $value['name_encoding'];
- }
- if (!empty($value['filename_encoding'])) {
- $params['filename_encoding'] = $value['filename_encoding'];
- }
+ /**
+ * Adds an attachment subpart to a mimePart object
+ * and returns it during the build process.
+ *
+ * @param object &$obj The mimePart to add the image to
+ * @param array $value The attachment information
+ *
+ * @return object The image mimePart object
+ * @access private
+ */
+ function &_addAttachmentPart(&$obj, $value)
+ {
+ $params['eol'] = $this->_build_params['eol'];
+ $params['dfilename'] = $value['name'];
+ $params['encoding'] = $value['encoding'];
+ $params['content_type'] = $value['c_type'];
+ $params['body_file'] = $value['body_file'];
+ $params['disposition'] = $value['disposition'] ?? 'attachment';
+ if ($value['charset']) {
+ $params['charset'] = $value['charset'];
+ }
+ if ($value['language']) {
+ $params['language'] = $value['language'];
+ }
+ if ($value['location']) {
+ $params['location'] = $value['location'];
+ }
+ if (!empty($value['name_encoding'])) {
+ $params['name_encoding'] = $value['name_encoding'];
+ }
+ if (!empty($value['filename_encoding'])) {
+ $params['filename_encoding'] = $value['filename_encoding'];
+ }
+ if (!empty($value['description'])) {
+ $params['description'] = $value['description'];
+ }
- $ret = $obj->addSubpart($value['body'], $params);
- return $ret;
- }
+ $ret = $obj->addSubpart($value['body'], $params);
+ return $ret;
+ }
- /**
- * Adds an attachment subpart to a mimePart object
- * and returns it during the build process.
- *
- * @param object &$obj The mimePart to add the image to
- * @param array $value The attachment information
- *
- * @return object The image mimePart object
- * @access private
- */
- function &_addAttachmentPart(&$obj, $value)
- {
- $params['eol'] = $this->_build_params['eol'];
- $params['dfilename'] = $value['name'];
- $params['encoding'] = $value['encoding'];
- $params['content_type'] = $value['c_type'];
- $params['body_file'] = $value['body_file'];
- $params['disposition'] = isset($value['disposition']) ?
- $value['disposition'] : 'attachment';
- if ($value['charset']) {
- $params['charset'] = $value['charset'];
- }
- if ($value['language']) {
- $params['language'] = $value['language'];
- }
- if ($value['location']) {
- $params['location'] = $value['location'];
- }
- if (!empty($value['name_encoding'])) {
- $params['name_encoding'] = $value['name_encoding'];
- }
- if (!empty($value['filename_encoding'])) {
- $params['filename_encoding'] = $value['filename_encoding'];
- }
- if (!empty($value['description'])) {
- $params['description'] = $value['description'];
- }
+ /**
+ * Returns the complete e-mail, ready to send using an alternative
+ * mail delivery method. Note that only the mailpart that is made
+ * with Mail_Mime is created. This means that,
+ * YOU WILL HAVE NO TO: HEADERS UNLESS YOU SET IT YOURSELF
+ * using the $headers parameter!
+ *
+ * @param string $separation The separation between these two parts.
+ * @param array $params The Build parameters passed to the
+ * &get() function. See &get for more info.
+ * @param array $headers The extra headers that should be passed
+ * to the &headers() function.
+ * See that function for more info.
+ * @param bool $overwrite Overwrite the existing headers with new.
+ *
+ * @return mixed The complete e-mail or PEAR error object
+ * @access public
+ */
+ function getMessage($separation = null, $params = null, $headers = null,
+ $overwrite = false,
+ ) {
+ if ($separation === null) {
+ $separation = $this->_build_params['eol'];
+ }
- $ret = $obj->addSubpart($value['body'], $params);
- return $ret;
- }
+ $body = $this->get($params);
- /**
- * Returns the complete e-mail, ready to send using an alternative
- * mail delivery method. Note that only the mailpart that is made
- * with Mail_Mime is created. This means that,
- * YOU WILL HAVE NO TO: HEADERS UNLESS YOU SET IT YOURSELF
- * using the $headers parameter!
- *
- * @param string $separation The separation between these two parts.
- * @param array $params The Build parameters passed to the
- * &get() function. See &get for more info.
- * @param array $headers The extra headers that should be passed
- * to the &headers() function.
- * See that function for more info.
- * @param bool $overwrite Overwrite the existing headers with new.
- *
- * @return mixed The complete e-mail or PEAR error object
- * @access public
- */
- function getMessage($separation = null, $params = null, $headers = null,
- $overwrite = false
- ) {
- if ($separation === null) {
- $separation = $this->_build_params['eol'];
- }
+ if (PEAR::isError($body)) {
+ return $body;
+ }
- $body = $this->get($params);
+ $head = $this->txtHeaders($headers, $overwrite);
+ $mail = $head . $separation . $body;
+ return $mail;
+ }
- if (PEAR::isError($body)) {
- return $body;
- }
+ /**
+ * Returns the complete e-mail body, ready to send using an alternative
+ * mail delivery method.
+ *
+ * @param array $params The Build parameters passed to the
+ * &get() function. See &get for more info.
+ *
+ * @return mixed The e-mail body or PEAR error object
+ * @access public
+ * @since 1.6.0
+ */
+ function getMessageBody($params = null)
+ {
+ return $this->get($params, null, true);
+ }
- $head = $this->txtHeaders($headers, $overwrite);
- $mail = $head . $separation . $body;
- return $mail;
- }
+ /**
+ * Writes (appends) the complete e-mail into file.
+ *
+ * @param string $filename Output file location
+ * @param array $params The Build parameters passed to the
+ * &get() function. See &get for more info.
+ * @param array $headers The extra headers that should be passed
+ * to the &headers() function.
+ * See that function for more info.
+ * @param bool $overwrite Overwrite the existing headers with new.
+ *
+ * @return mixed True or PEAR error object
+ * @access public
+ * @since 1.6.0
+ */
+ function saveMessage($filename, $params = null, $headers = null, $overwrite = false)
+ {
+ // Check state of file and raise an error properly
+ if (file_exists($filename) && !is_writable($filename)) {
+ $err = PEAR::raiseError('File is not writable: ' . $filename);
+ return $err;
+ }
- /**
- * Returns the complete e-mail body, ready to send using an alternative
- * mail delivery method.
- *
- * @param array $params The Build parameters passed to the
- * &get() function. See &get for more info.
- *
- * @return mixed The e-mail body or PEAR error object
- * @access public
- * @since 1.6.0
- */
- function getMessageBody($params = null)
- {
- return $this->get($params, null, true);
- }
+ // Temporarily reset magic_quotes_runtime and read file contents
+ if ($magic_quote_setting = get_magic_quotes_runtime()) {
+ @ini_set('magic_quotes_runtime', 0);
+ }
- /**
- * Writes (appends) the complete e-mail into file.
- *
- * @param string $filename Output file location
- * @param array $params The Build parameters passed to the
- * &get() function. See &get for more info.
- * @param array $headers The extra headers that should be passed
- * to the &headers() function.
- * See that function for more info.
- * @param bool $overwrite Overwrite the existing headers with new.
- *
- * @return mixed True or PEAR error object
- * @access public
- * @since 1.6.0
- */
- function saveMessage($filename, $params = null, $headers = null, $overwrite = false)
- {
- // Check state of file and raise an error properly
- if (file_exists($filename) && !is_writable($filename)) {
- $err = PEAR::raiseError('File is not writable: ' . $filename);
- return $err;
- }
+ if (!($fh = fopen($filename, 'ab'))) {
+ $err = PEAR::raiseError('Unable to open file: ' . $filename);
+ return $err;
+ }
- // Temporarily reset magic_quotes_runtime and read file contents
- if ($magic_quote_setting = get_magic_quotes_runtime()) {
- @ini_set('magic_quotes_runtime', 0);
- }
+ // Write message headers into file (skipping Content-* headers)
+ $head = $this->txtHeaders($headers, $overwrite, true);
+ if (fwrite($fh, $head) === false) {
+ $err = PEAR::raiseError('Error writing to file: ' . $filename);
+ return $err;
+ }
- if (!($fh = fopen($filename, 'ab'))) {
- $err = PEAR::raiseError('Unable to open file: ' . $filename);
- return $err;
- }
+ fclose($fh);
- // Write message headers into file (skipping Content-* headers)
- $head = $this->txtHeaders($headers, $overwrite, true);
- if (fwrite($fh, $head) === false) {
- $err = PEAR::raiseError('Error writing to file: ' . $filename);
- return $err;
- }
+ if ($magic_quote_setting) {
+ @ini_set('magic_quotes_runtime', $magic_quote_setting);
+ }
- fclose($fh);
+ // Write the rest of the message into file
+ $res = $this->get($params, $filename);
- if ($magic_quote_setting) {
- @ini_set('magic_quotes_runtime', $magic_quote_setting);
- }
+ return $res ? $res : true;
+ }
- // Write the rest of the message into file
- $res = $this->get($params, $filename);
+ /**
+ * Writes (appends) the complete e-mail body into file.
+ *
+ * @param string $filename Output file location
+ * @param array $params The Build parameters passed to the
+ * &get() function. See &get for more info.
+ *
+ * @return mixed True or PEAR error object
+ * @access public
+ * @since 1.6.0
+ */
+ function saveMessageBody($filename, $params = null)
+ {
+ // Check state of file and raise an error properly
+ if (file_exists($filename) && !is_writable($filename)) {
+ $err = PEAR::raiseError('File is not writable: ' . $filename);
+ return $err;
+ }
- return $res ? $res : true;
- }
+ // Temporarily reset magic_quotes_runtime and read file contents
+ if ($magic_quote_setting = get_magic_quotes_runtime()) {
+ @ini_set('magic_quotes_runtime', 0);
+ }
- /**
- * Writes (appends) the complete e-mail body into file.
- *
- * @param string $filename Output file location
- * @param array $params The Build parameters passed to the
- * &get() function. See &get for more info.
- *
- * @return mixed True or PEAR error object
- * @access public
- * @since 1.6.0
- */
- function saveMessageBody($filename, $params = null)
- {
- // Check state of file and raise an error properly
- if (file_exists($filename) && !is_writable($filename)) {
- $err = PEAR::raiseError('File is not writable: ' . $filename);
- return $err;
- }
+ if (!($fh = fopen($filename, 'ab'))) {
+ $err = PEAR::raiseError('Unable to open file: ' . $filename);
+ return $err;
+ }
- // Temporarily reset magic_quotes_runtime and read file contents
- if ($magic_quote_setting = get_magic_quotes_runtime()) {
- @ini_set('magic_quotes_runtime', 0);
- }
+ // Write the rest of the message into file
+ $res = $this->get($params, $filename, true);
- if (!($fh = fopen($filename, 'ab'))) {
- $err = PEAR::raiseError('Unable to open file: ' . $filename);
- return $err;
- }
+ return $res ? $res : true;
+ }
- // Write the rest of the message into file
- $res = $this->get($params, $filename, true);
+ /**
+ * Builds the multipart message from the list ($this->_parts) and
+ * returns the mime content.
+ *
+ * @param array $params Build parameters that change the way the email
+ * is built. Should be associative. See $_build_params.
+ * @param resource $filename Output file where to save the message instead of
+ * returning it
+ * @param boolean $skip_head True if you want to return/save only the message
+ * without headers
+ *
+ * @return mixed The MIME message content string, null or PEAR error object
+ * @access public
+ */
+ function &get($params = null, $filename = null, $skip_head = false)
+ {
+ if (isset($params)) {
+ while (list($key, $value) = each($params)) {
+ $this->_build_params[$key] = $value;
+ }
+ }
- return $res ? $res : true;
- }
+ if (isset($this->_headers['From'])) {
+ // Bug #11381: Illegal characters in domain ID
+ if (preg_match('#(@[0-9a-zA-Z\-\.]+)#', $this->_headers['From'], $matches)) {
+ $domainID = $matches[1];
+ } else {
+ $domainID = '@localhost';
+ }
+ foreach ($this->_html_images as $i => $img) {
+ $cid = $this->_html_images[$i]['cid'];
+ if (!preg_match('#'.preg_quote($domainID).'$#', $cid)) {
+ $this->_html_images[$i]['cid'] = $cid . $domainID;
+ }
+ }
+ }
- /**
- * Builds the multipart message from the list ($this->_parts) and
- * returns the mime content.
- *
- * @param array $params Build parameters that change the way the email
- * is built. Should be associative. See $_build_params.
- * @param resource $filename Output file where to save the message instead of
- * returning it
- * @param boolean $skip_head True if you want to return/save only the message
- * without headers
- *
- * @return mixed The MIME message content string, null or PEAR error object
- * @access public
- */
- function &get($params = null, $filename = null, $skip_head = false)
- {
- if (isset($params)) {
- while (list($key, $value) = each($params)) {
- $this->_build_params[$key] = $value;
- }
- }
+ if (count($this->_html_images) && isset($this->_htmlbody)) {
+ foreach ($this->_html_images as $key => $value) {
+ $regex = [];
+ $regex[] = '#(\s)((?i)src|background|href(?-i))\s*=\s*(["\']?)' .
+ preg_quote($value['name'], '#') . '\3#';
+ $regex[] = '#(?i)url(?-i)\(\s*(["\']?)' .
+ preg_quote($value['name'], '#') . '\1\s*\)#';
- if (isset($this->_headers['From'])) {
- // Bug #11381: Illegal characters in domain ID
- if (preg_match('#(@[0-9a-zA-Z\-\.]+)#', $this->_headers['From'], $matches)) {
- $domainID = $matches[1];
- } else {
- $domainID = '@localhost';
- }
- foreach ($this->_html_images as $i => $img) {
- $cid = $this->_html_images[$i]['cid'];
- if (!preg_match('#'.preg_quote($domainID).'$#', $cid)) {
- $this->_html_images[$i]['cid'] = $cid . $domainID;
- }
- }
- }
+ $rep = [];
+ $rep[] = '\1\2=\3cid:' . $value['cid'] .'\3';
+ $rep[] = 'url(\1cid:' . $value['cid'] . '\1)';
- if (count($this->_html_images) && isset($this->_htmlbody)) {
- foreach ($this->_html_images as $key => $value) {
- $regex = array();
- $regex[] = '#(\s)((?i)src|background|href(?-i))\s*=\s*(["\']?)' .
- preg_quote($value['name'], '#') . '\3#';
- $regex[] = '#(?i)url(?-i)\(\s*(["\']?)' .
- preg_quote($value['name'], '#') . '\1\s*\)#';
+ $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody);
+ $this->_html_images[$key]['name']
+ = $this->_basename($this->_html_images[$key]['name']);
+ }
+ }
- $rep = array();
- $rep[] = '\1\2=\3cid:' . $value['cid'] .'\3';
- $rep[] = 'url(\1cid:' . $value['cid'] . '\1)';
+ $this->_checkParams();
- $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody);
- $this->_html_images[$key]['name']
- = $this->_basename($this->_html_images[$key]['name']);
- }
- }
+ $null = null;
+ $attachments = count($this->_parts) ? true : false;
+ $html_images = count($this->_html_images) ? true : false;
+ $html = strlen($this->_htmlbody) ? true : false;
+ $text = (!$html && strlen($this->_txtbody)) ? true : false;
- $this->_checkParams();
+ switch (true) {
+ case $text && !$attachments:
+ $message =& $this->_addTextPart($null, $this->_txtbody);
+ break;
- $null = null;
- $attachments = count($this->_parts) ? true : false;
- $html_images = count($this->_html_images) ? true : false;
- $html = strlen($this->_htmlbody) ? true : false;
- $text = (!$html && strlen($this->_txtbody)) ? true : false;
+ case !$text && !$html && $attachments:
+ $message =& $this->_addMixedPart();
+ for ($i = 0; $i < count($this->_parts); $i++) {
+ $this->_addAttachmentPart($message, $this->_parts[$i]);
+ }
+ break;
- switch (true) {
- case $text && !$attachments:
- $message =& $this->_addTextPart($null, $this->_txtbody);
- break;
+ case $text && $attachments:
+ $message =& $this->_addMixedPart();
+ $this->_addTextPart($message, $this->_txtbody);
+ for ($i = 0; $i < count($this->_parts); $i++) {
+ $this->_addAttachmentPart($message, $this->_parts[$i]);
+ }
+ break;
- case !$text && !$html && $attachments:
- $message =& $this->_addMixedPart();
- for ($i = 0; $i < count($this->_parts); $i++) {
- $this->_addAttachmentPart($message, $this->_parts[$i]);
- }
- break;
+ case $html && !$attachments && !$html_images:
+ if (isset($this->_txtbody)) {
+ $message =& $this->_addAlternativePart($null);
+ $this->_addTextPart($message, $this->_txtbody);
+ $this->_addHtmlPart($message);
+ } else {
+ $message =& $this->_addHtmlPart($null);
+ }
+ break;
- case $text && $attachments:
- $message =& $this->_addMixedPart();
- $this->_addTextPart($message, $this->_txtbody);
- for ($i = 0; $i < count($this->_parts); $i++) {
- $this->_addAttachmentPart($message, $this->_parts[$i]);
- }
- break;
+ case $html && !$attachments && $html_images:
+ // * Content-Type: multipart/alternative;
+ // * text
+ // * Content-Type: multipart/related;
+ // * html
+ // * image...
+ if (isset($this->_txtbody)) {
+ $message =& $this->_addAlternativePart($null);
+ $this->_addTextPart($message, $this->_txtbody);
- case $html && !$attachments && !$html_images:
- if (isset($this->_txtbody)) {
- $message =& $this->_addAlternativePart($null);
- $this->_addTextPart($message, $this->_txtbody);
- $this->_addHtmlPart($message);
- } else {
- $message =& $this->_addHtmlPart($null);
- }
- break;
+ $ht =& $this->_addRelatedPart($message);
+ $this->_addHtmlPart($ht);
+ for ($i = 0; $i < count($this->_html_images); $i++) {
+ $this->_addHtmlImagePart($ht, $this->_html_images[$i]);
+ }
+ } else {
+ // * Content-Type: multipart/related;
+ // * html
+ // * image...
+ $message =& $this->_addRelatedPart($null);
+ $this->_addHtmlPart($message);
+ for ($i = 0; $i < count($this->_html_images); $i++) {
+ $this->_addHtmlImagePart($message, $this->_html_images[$i]);
+ }
+ }
+ /*
+ // #13444, #9725: the code below was a non-RFC compliant hack
+ // * Content-Type: multipart/related;
+ // * Content-Type: multipart/alternative;
+ // * text
+ // * html
+ // * image...
+ $message =& $this->_addRelatedPart($null);
+ if (isset($this->_txtbody)) {
+ $alt =& $this->_addAlternativePart($message);
+ $this->_addTextPart($alt, $this->_txtbody);
+ $this->_addHtmlPart($alt);
+ } else {
+ $this->_addHtmlPart($message);
+ }
+ for ($i = 0; $i < count($this->_html_images); $i++) {
+ $this->_addHtmlImagePart($message, $this->_html_images[$i]);
+ }
+ */
+ break;
- case $html && !$attachments && $html_images:
- // * Content-Type: multipart/alternative;
- // * text
- // * Content-Type: multipart/related;
- // * html
- // * image...
- if (isset($this->_txtbody)) {
- $message =& $this->_addAlternativePart($null);
- $this->_addTextPart($message, $this->_txtbody);
+ case $html && $attachments && !$html_images:
+ $message =& $this->_addMixedPart();
+ if (isset($this->_txtbody)) {
+ $alt =& $this->_addAlternativePart($message);
+ $this->_addTextPart($alt, $this->_txtbody);
+ $this->_addHtmlPart($alt);
+ } else {
+ $this->_addHtmlPart($message);
+ }
+ for ($i = 0; $i < count($this->_parts); $i++) {
+ $this->_addAttachmentPart($message, $this->_parts[$i]);
+ }
+ break;
- $ht =& $this->_addRelatedPart($message);
- $this->_addHtmlPart($ht);
- for ($i = 0; $i < count($this->_html_images); $i++) {
- $this->_addHtmlImagePart($ht, $this->_html_images[$i]);
- }
- } else {
- // * Content-Type: multipart/related;
- // * html
- // * image...
- $message =& $this->_addRelatedPart($null);
- $this->_addHtmlPart($message);
- for ($i = 0; $i < count($this->_html_images); $i++) {
- $this->_addHtmlImagePart($message, $this->_html_images[$i]);
- }
- }
- /*
- // #13444, #9725: the code below was a non-RFC compliant hack
- // * Content-Type: multipart/related;
- // * Content-Type: multipart/alternative;
- // * text
- // * html
- // * image...
- $message =& $this->_addRelatedPart($null);
- if (isset($this->_txtbody)) {
- $alt =& $this->_addAlternativePart($message);
- $this->_addTextPart($alt, $this->_txtbody);
- $this->_addHtmlPart($alt);
- } else {
- $this->_addHtmlPart($message);
- }
- for ($i = 0; $i < count($this->_html_images); $i++) {
- $this->_addHtmlImagePart($message, $this->_html_images[$i]);
- }
- */
- break;
+ case $html && $attachments && $html_images:
+ $message =& $this->_addMixedPart();
+ if (isset($this->_txtbody)) {
+ $alt =& $this->_addAlternativePart($message);
+ $this->_addTextPart($alt, $this->_txtbody);
+ $rel =& $this->_addRelatedPart($alt);
+ } else {
+ $rel =& $this->_addRelatedPart($message);
+ }
+ $this->_addHtmlPart($rel);
+ for ($i = 0; $i < count($this->_html_images); $i++) {
+ $this->_addHtmlImagePart($rel, $this->_html_images[$i]);
+ }
+ for ($i = 0; $i < count($this->_parts); $i++) {
+ $this->_addAttachmentPart($message, $this->_parts[$i]);
+ }
+ break;
- case $html && $attachments && !$html_images:
- $message =& $this->_addMixedPart();
- if (isset($this->_txtbody)) {
- $alt =& $this->_addAlternativePart($message);
- $this->_addTextPart($alt, $this->_txtbody);
- $this->_addHtmlPart($alt);
- } else {
- $this->_addHtmlPart($message);
- }
- for ($i = 0; $i < count($this->_parts); $i++) {
- $this->_addAttachmentPart($message, $this->_parts[$i]);
- }
- break;
+ }
- case $html && $attachments && $html_images:
- $message =& $this->_addMixedPart();
- if (isset($this->_txtbody)) {
- $alt =& $this->_addAlternativePart($message);
- $this->_addTextPart($alt, $this->_txtbody);
- $rel =& $this->_addRelatedPart($alt);
- } else {
- $rel =& $this->_addRelatedPart($message);
- }
- $this->_addHtmlPart($rel);
- for ($i = 0; $i < count($this->_html_images); $i++) {
- $this->_addHtmlImagePart($rel, $this->_html_images[$i]);
- }
- for ($i = 0; $i < count($this->_parts); $i++) {
- $this->_addAttachmentPart($message, $this->_parts[$i]);
- }
- break;
+ if (!isset($message)) {
+ $ret = null;
+ return $ret;
+ }
- }
+ // Use saved boundary
+ if (!empty($this->_build_params['boundary'])) {
+ $boundary = $this->_build_params['boundary'];
+ } else {
+ $boundary = null;
+ }
- if (!isset($message)) {
- $ret = null;
- return $ret;
- }
+ // Write output to file
+ if ($filename) {
+ // Append mimePart message headers and body into file
+ $headers = $message->encodeToFile($filename, $boundary, $skip_head);
+ if (PEAR::isError($headers)) {
+ return $headers;
+ }
+ $this->_headers = array_merge($this->_headers, $headers);
+ $ret = null;
+ return $ret;
+ }
+ $output = $message->encode($boundary, $skip_head);
+ if (PEAR::isError($output)) {
+ return $output;
+ }
+ $this->_headers = array_merge($this->_headers, $output['headers']);
+ $body = $output['body'];
+ return $body;
- // Use saved boundary
- if (!empty($this->_build_params['boundary'])) {
- $boundary = $this->_build_params['boundary'];
- } else {
- $boundary = null;
- }
+ }
- // Write output to file
- if ($filename) {
- // Append mimePart message headers and body into file
- $headers = $message->encodeToFile($filename, $boundary, $skip_head);
- if (PEAR::isError($headers)) {
- return $headers;
- }
- $this->_headers = array_merge($this->_headers, $headers);
- $ret = null;
- return $ret;
- } else {
- $output = $message->encode($boundary, $skip_head);
- if (PEAR::isError($output)) {
- return $output;
- }
- $this->_headers = array_merge($this->_headers, $output['headers']);
- $body = $output['body'];
- return $body;
- }
- }
+ /**
+ * Returns an array with the headers needed to prepend to the email
+ * (MIME-Version and Content-Type). Format of argument is:
+ * $array['header-name'] = 'header-value';
+ *
+ * @param array $xtra_headers Assoc array with any extra headers (optional)
+ * (Don't set Content-Type for multipart messages here!)
+ * @param bool $overwrite Overwrite already existing headers.
+ * @param bool $skip_content Don't return content headers: Content-Type,
+ * Content-Disposition and Content-Transfer-Encoding
+ *
+ * @return array Assoc array with the mime headers
+ * @access public
+ */
+ function &headers($xtra_headers = null, $overwrite = false, $skip_content = false)
+ {
+ // Add mime version header
+ $headers['MIME-Version'] = '1.0';
- /**
- * Returns an array with the headers needed to prepend to the email
- * (MIME-Version and Content-Type). Format of argument is:
- * $array['header-name'] = 'header-value';
- *
- * @param array $xtra_headers Assoc array with any extra headers (optional)
- * (Don't set Content-Type for multipart messages here!)
- * @param bool $overwrite Overwrite already existing headers.
- * @param bool $skip_content Don't return content headers: Content-Type,
- * Content-Disposition and Content-Transfer-Encoding
- *
- * @return array Assoc array with the mime headers
- * @access public
- */
- function &headers($xtra_headers = null, $overwrite = false, $skip_content = false)
- {
- // Add mime version header
- $headers['MIME-Version'] = '1.0';
+ // Content-Type and Content-Transfer-Encoding headers should already
+ // be present if get() was called, but we'll re-set them to make sure
+ // we got them when called before get() or something in the message
+ // has been changed after get() [#14780]
+ if (!$skip_content) {
+ $headers += $this->_contentHeaders();
+ }
- // Content-Type and Content-Transfer-Encoding headers should already
- // be present if get() was called, but we'll re-set them to make sure
- // we got them when called before get() or something in the message
- // has been changed after get() [#14780]
- if (!$skip_content) {
- $headers += $this->_contentHeaders();
- }
+ if (!empty($xtra_headers)) {
+ $headers = array_merge($headers, $xtra_headers);
+ }
- if (!empty($xtra_headers)) {
- $headers = array_merge($headers, $xtra_headers);
- }
+ if ($overwrite) {
+ $this->_headers = array_merge($this->_headers, $headers);
+ } else {
+ $this->_headers = array_merge($headers, $this->_headers);
+ }
- if ($overwrite) {
- $this->_headers = array_merge($this->_headers, $headers);
- } else {
- $this->_headers = array_merge($headers, $this->_headers);
- }
+ $headers = $this->_headers;
- $headers = $this->_headers;
+ if ($skip_content) {
+ unset($headers['Content-Type']);
+ unset($headers['Content-Transfer-Encoding']);
+ unset($headers['Content-Disposition']);
+ } else if (!empty($this->_build_params['ctype'])) {
+ $headers['Content-Type'] = $this->_build_params['ctype'];
+ }
- if ($skip_content) {
- unset($headers['Content-Type']);
- unset($headers['Content-Transfer-Encoding']);
- unset($headers['Content-Disposition']);
- } else if (!empty($this->_build_params['ctype'])) {
- $headers['Content-Type'] = $this->_build_params['ctype'];
- }
+ $encodedHeaders = $this->_encodeHeaders($headers);
+ return $encodedHeaders;
+ }
- $encodedHeaders = $this->_encodeHeaders($headers);
- return $encodedHeaders;
- }
+ /**
+ * Get the text version of the headers
+ * (usefull if you want to use the PHP mail() function)
+ *
+ * @param array $xtra_headers Assoc array with any extra headers (optional)
+ * (Don't set Content-Type for multipart messages here!)
+ * @param bool $overwrite Overwrite the existing headers with new.
+ * @param bool $skip_content Don't return content headers: Content-Type,
+ * Content-Disposition and Content-Transfer-Encoding
+ *
+ * @return string Plain text headers
+ * @access public
+ */
+ function txtHeaders($xtra_headers = null, $overwrite = false, $skip_content = false)
+ {
+ $headers = $this->headers($xtra_headers, $overwrite, $skip_content);
- /**
- * Get the text version of the headers
- * (usefull if you want to use the PHP mail() function)
- *
- * @param array $xtra_headers Assoc array with any extra headers (optional)
- * (Don't set Content-Type for multipart messages here!)
- * @param bool $overwrite Overwrite the existing headers with new.
- * @param bool $skip_content Don't return content headers: Content-Type,
- * Content-Disposition and Content-Transfer-Encoding
- *
- * @return string Plain text headers
- * @access public
- */
- function txtHeaders($xtra_headers = null, $overwrite = false, $skip_content = false)
- {
- $headers = $this->headers($xtra_headers, $overwrite, $skip_content);
+ // Place Received: headers at the beginning of the message
+ // Spam detectors often flag messages with it after the Subject: as spam
+ if (isset($headers['Received'])) {
+ $received = $headers['Received'];
+ unset($headers['Received']);
+ $headers = ['Received' => $received] + $headers;
+ }
- // Place Received: headers at the beginning of the message
- // Spam detectors often flag messages with it after the Subject: as spam
- if (isset($headers['Received'])) {
- $received = $headers['Received'];
- unset($headers['Received']);
- $headers = array('Received' => $received) + $headers;
- }
+ $ret = '';
+ $eol = $this->_build_params['eol'];
- $ret = '';
- $eol = $this->_build_params['eol'];
+ foreach ($headers as $key => $val) {
+ if (is_array($val)) {
+ foreach ($val as $value) {
+ $ret .= "$key: $value" . $eol;
+ }
+ } else {
+ $ret .= "$key: $val" . $eol;
+ }
+ }
- foreach ($headers as $key => $val) {
- if (is_array($val)) {
- foreach ($val as $value) {
- $ret .= "$key: $value" . $eol;
- }
- } else {
- $ret .= "$key: $val" . $eol;
- }
- }
+ return $ret;
+ }
- return $ret;
- }
+ /**
+ * Sets message Content-Type header.
+ * Use it to build messages with various content-types e.g. miltipart/raport
+ * not supported by _contentHeaders() function.
+ *
+ * @param string $type Type name
+ * @param array $params Hash array of header parameters
+ *
+ * @return void
+ * @access public
+ * @since 1.7.0
+ */
+ function setContentType($type, $params = [])
+ {
+ $header = $type;
- /**
- * Sets message Content-Type header.
- * Use it to build messages with various content-types e.g. miltipart/raport
- * not supported by _contentHeaders() function.
- *
- * @param string $type Type name
- * @param array $params Hash array of header parameters
- *
- * @return void
- * @access public
- * @since 1.7.0
- */
- function setContentType($type, $params = array())
- {
- $header = $type;
+ $eol = !empty($this->_build_params['eol'])
+ ? $this->_build_params['eol'] : "\r\n";
- $eol = !empty($this->_build_params['eol'])
- ? $this->_build_params['eol'] : "\r\n";
+ // add parameters
+ $token_regexp = '#([^\x21,\x23-\x27,\x2A,\x2B,\x2D'
+ . ',\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#';
+ if (is_array($params)) {
+ foreach ($params as $name => $value) {
+ if ($name == 'boundary') {
+ $this->_build_params['boundary'] = $value;
+ }
+ if (!preg_match($token_regexp, $value)) {
+ $header .= ";$eol $name=$value";
+ } else {
+ $value = addcslashes($value, '\\"');
+ $header .= ";$eol $name=\"$value\"";
+ }
+ }
+ }
- // add parameters
- $token_regexp = '#([^\x21,\x23-\x27,\x2A,\x2B,\x2D'
- . ',\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#';
- if (is_array($params)) {
- foreach ($params as $name => $value) {
- if ($name == 'boundary') {
- $this->_build_params['boundary'] = $value;
- }
- if (!preg_match($token_regexp, $value)) {
- $header .= ";$eol $name=$value";
- } else {
- $value = addcslashes($value, '\\"');
- $header .= ";$eol $name=\"$value\"";
- }
- }
- }
+ // add required boundary parameter if not defined
+ if (preg_match('/^multipart\//i', $type)) {
+ if (empty($this->_build_params['boundary'])) {
+ $this->_build_params['boundary'] = '=_' . md5(rand() . microtime());
+ }
- // add required boundary parameter if not defined
- if (preg_match('/^multipart\//i', $type)) {
- if (empty($this->_build_params['boundary'])) {
- $this->_build_params['boundary'] = '=_' . md5(rand() . microtime());
- }
+ $header .= ";$eol boundary=\"".$this->_build_params['boundary']."\"";
+ }
- $header .= ";$eol boundary=\"".$this->_build_params['boundary']."\"";
- }
+ $this->_build_params['ctype'] = $header;
+ }
- $this->_build_params['ctype'] = $header;
- }
+ /**
+ * Sets the Subject header
+ *
+ * @param string $subject String to set the subject to.
+ *
+ * @return void
+ * @access public
+ */
+ function setSubject($subject)
+ {
+ $this->_headers['Subject'] = $subject;
+ }
- /**
- * Sets the Subject header
- *
- * @param string $subject String to set the subject to.
- *
- * @return void
- * @access public
- */
- function setSubject($subject)
- {
- $this->_headers['Subject'] = $subject;
- }
+ /**
+ * Set an email to the From (the sender) header
+ *
+ * @param string $email The email address to use
+ *
+ * @return void
+ * @access public
+ */
+ function setFrom($email)
+ {
+ $this->_headers['From'] = $email;
+ }
- /**
- * Set an email to the From (the sender) header
- *
- * @param string $email The email address to use
- *
- * @return void
- * @access public
- */
- function setFrom($email)
- {
- $this->_headers['From'] = $email;
- }
+ /**
+ * Add an email to the To header
+ * (multiple calls to this method are allowed)
+ *
+ * @param string $email The email direction to add
+ *
+ * @return void
+ * @access public
+ */
+ function addTo($email)
+ {
+ if (isset($this->_headers['To'])) {
+ $this->_headers['To'] .= ", $email";
+ } else {
+ $this->_headers['To'] = $email;
+ }
+ }
- /**
- * Add an email to the To header
- * (multiple calls to this method are allowed)
- *
- * @param string $email The email direction to add
- *
- * @return void
- * @access public
- */
- function addTo($email)
- {
- if (isset($this->_headers['To'])) {
- $this->_headers['To'] .= ", $email";
- } else {
- $this->_headers['To'] = $email;
- }
- }
+ /**
+ * Add an email to the Cc (carbon copy) header
+ * (multiple calls to this method are allowed)
+ *
+ * @param string $email The email direction to add
+ *
+ * @return void
+ * @access public
+ */
+ function addCc($email)
+ {
+ if (isset($this->_headers['Cc'])) {
+ $this->_headers['Cc'] .= ", $email";
+ } else {
+ $this->_headers['Cc'] = $email;
+ }
+ }
- /**
- * Add an email to the Cc (carbon copy) header
- * (multiple calls to this method are allowed)
- *
- * @param string $email The email direction to add
- *
- * @return void
- * @access public
- */
- function addCc($email)
- {
- if (isset($this->_headers['Cc'])) {
- $this->_headers['Cc'] .= ", $email";
- } else {
- $this->_headers['Cc'] = $email;
- }
- }
+ /**
+ * Add an email to the Bcc (blank carbon copy) header
+ * (multiple calls to this method are allowed)
+ *
+ * @param string $email The email direction to add
+ *
+ * @return void
+ * @access public
+ */
+ function addBcc($email)
+ {
+ if (isset($this->_headers['Bcc'])) {
+ $this->_headers['Bcc'] .= ", $email";
+ } else {
+ $this->_headers['Bcc'] = $email;
+ }
+ }
- /**
- * Add an email to the Bcc (blank carbon copy) header
- * (multiple calls to this method are allowed)
- *
- * @param string $email The email direction to add
- *
- * @return void
- * @access public
- */
- function addBcc($email)
- {
- if (isset($this->_headers['Bcc'])) {
- $this->_headers['Bcc'] .= ", $email";
- } else {
- $this->_headers['Bcc'] = $email;
- }
- }
+ /**
+ * Since the PHP send function requires you to specify
+ * recipients (To: header) separately from the other
+ * headers, the To: header is not properly encoded.
+ * To fix this, you can use this public method to
+ * encode your recipients before sending to the send
+ * function
+ *
+ * @param string $recipients A comma-delimited list of recipients
+ *
+ * @return string Encoded data
+ * @access public
+ */
+ function encodeRecipients($recipients)
+ {
+ $input = ["To" => $recipients];
+ $retval = $this->_encodeHeaders($input);
+ return $retval["To"] ;
+ }
- /**
- * Since the PHP send function requires you to specify
- * recipients (To: header) separately from the other
- * headers, the To: header is not properly encoded.
- * To fix this, you can use this public method to
- * encode your recipients before sending to the send
- * function
- *
- * @param string $recipients A comma-delimited list of recipients
- *
- * @return string Encoded data
- * @access public
- */
- function encodeRecipients($recipients)
- {
- $input = array("To" => $recipients);
- $retval = $this->_encodeHeaders($input);
- return $retval["To"] ;
- }
+ /**
+ * Encodes headers as per RFC2047
+ *
+ * @param array $input The header data to encode
+ * @param array $params Extra build parameters
+ *
+ * @return array Encoded data
+ * @access private
+ */
+ function _encodeHeaders($input, $params = [])
+ {
+ $build_params = $this->_build_params;
+ while (list($key, $value) = each($params)) {
+ $build_params[$key] = $value;
+ }
- /**
- * Encodes headers as per RFC2047
- *
- * @param array $input The header data to encode
- * @param array $params Extra build parameters
- *
- * @return array Encoded data
- * @access private
- */
- function _encodeHeaders($input, $params = array())
- {
- $build_params = $this->_build_params;
- while (list($key, $value) = each($params)) {
- $build_params[$key] = $value;
- }
+ foreach ($input as $hdr_name => $hdr_value) {
+ if (is_array($hdr_value)) {
+ foreach ($hdr_value as $idx => $value) {
+ $input[$hdr_name][$idx] = $this->encodeHeader(
+ $hdr_name, $value,
+ $build_params['head_charset'], $build_params['head_encoding'],
+ );
+ }
+ } else {
+ $input[$hdr_name] = $this->encodeHeader(
+ $hdr_name, $hdr_value,
+ $build_params['head_charset'], $build_params['head_encoding'],
+ );
+ }
+ }
- foreach ($input as $hdr_name => $hdr_value) {
- if (is_array($hdr_value)) {
- foreach ($hdr_value as $idx => $value) {
- $input[$hdr_name][$idx] = $this->encodeHeader(
- $hdr_name, $value,
- $build_params['head_charset'], $build_params['head_encoding']
- );
- }
- } else {
- $input[$hdr_name] = $this->encodeHeader(
- $hdr_name, $hdr_value,
- $build_params['head_charset'], $build_params['head_encoding']
- );
- }
- }
+ return $input;
+ }
- return $input;
- }
+ /**
+ * Encodes a header as per RFC2047
+ *
+ * @param string $name The header name
+ * @param string $value The header data to encode
+ * @param string $charset Character set name
+ * @param string $encoding Encoding name (base64 or quoted-printable)
+ *
+ * @return string Encoded header data (without a name)
+ * @access public
+ * @since 1.5.3
+ */
+ function encodeHeader($name, $value, $charset, $encoding)
+ {
+ return Mail_mimePart::encodeHeader(
+ $name, $value, $charset, $encoding, $this->_build_params['eol'],
+ );
+ }
- /**
- * Encodes a header as per RFC2047
- *
- * @param string $name The header name
- * @param string $value The header data to encode
- * @param string $charset Character set name
- * @param string $encoding Encoding name (base64 or quoted-printable)
- *
- * @return string Encoded header data (without a name)
- * @access public
- * @since 1.5.3
- */
- function encodeHeader($name, $value, $charset, $encoding)
- {
- return Mail_mimePart::encodeHeader(
- $name, $value, $charset, $encoding, $this->_build_params['eol']
- );
- }
+ /**
+ * Get file's basename (locale independent)
+ *
+ * @param string $filename Filename
+ *
+ * @return string Basename
+ * @access private
+ */
+ function _basename($filename)
+ {
+ // basename() is not unicode safe and locale dependent
+ if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware')) {
+ return preg_replace('/^.*[\\\\\\/]/', '', $filename);
+ }
+ return preg_replace('/^.*[\/]/', '', $filename);
- /**
- * Get file's basename (locale independent)
- *
- * @param string $filename Filename
- *
- * @return string Basename
- * @access private
- */
- function _basename($filename)
- {
- // basename() is not unicode safe and locale dependent
- if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware')) {
- return preg_replace('/^.*[\\\\\\/]/', '', $filename);
- } else {
- return preg_replace('/^.*[\/]/', '', $filename);
- }
- }
+ }
- /**
- * Get Content-Type and Content-Transfer-Encoding headers of the message
- *
- * @return array Headers array
- * @access private
- */
- function _contentHeaders()
- {
- $attachments = count($this->_parts) ? true : false;
- $html_images = count($this->_html_images) ? true : false;
- $html = strlen($this->_htmlbody) ? true : false;
- $text = (!$html && strlen($this->_txtbody)) ? true : false;
- $headers = array();
+ /**
+ * Get Content-Type and Content-Transfer-Encoding headers of the message
+ *
+ * @return array Headers array
+ * @access private
+ */
+ function _contentHeaders()
+ {
+ $attachments = count($this->_parts) ? true : false;
+ $html_images = count($this->_html_images) ? true : false;
+ $html = strlen($this->_htmlbody) ? true : false;
+ $text = (!$html && strlen($this->_txtbody)) ? true : false;
+ $headers = [];
- // See get()
- switch (true) {
- case $text && !$attachments:
- $headers['Content-Type'] = 'text/plain';
- break;
+ // See get()
+ switch (true) {
+ case $text && !$attachments:
+ $headers['Content-Type'] = 'text/plain';
+ break;
- case !$text && !$html && $attachments:
- case $text && $attachments:
- case $html && $attachments && !$html_images:
- case $html && $attachments && $html_images:
- $headers['Content-Type'] = 'multipart/mixed';
- break;
+ case !$text && !$html && $attachments:
+ case $text && $attachments:
+ case $html && $attachments && !$html_images:
+ case $html && $attachments && $html_images:
+ $headers['Content-Type'] = 'multipart/mixed';
+ break;
- case $html && !$attachments && !$html_images && isset($this->_txtbody):
- case $html && !$attachments && $html_images && isset($this->_txtbody):
- $headers['Content-Type'] = 'multipart/alternative';
- break;
+ case $html && !$attachments && !$html_images && isset($this->_txtbody):
+ case $html && !$attachments && $html_images && isset($this->_txtbody):
+ $headers['Content-Type'] = 'multipart/alternative';
+ break;
- case $html && !$attachments && !$html_images && !isset($this->_txtbody):
- $headers['Content-Type'] = 'text/html';
- break;
+ case $html && !$attachments && !$html_images && !isset($this->_txtbody):
+ $headers['Content-Type'] = 'text/html';
+ break;
- case $html && !$attachments && $html_images && !isset($this->_txtbody):
- $headers['Content-Type'] = 'multipart/related';
- break;
+ case $html && !$attachments && $html_images && !isset($this->_txtbody):
+ $headers['Content-Type'] = 'multipart/related';
+ break;
- default:
- return $headers;
- }
+ default:
+ return $headers;
+ }
- $this->_checkParams();
+ $this->_checkParams();
- $eol = !empty($this->_build_params['eol'])
- ? $this->_build_params['eol'] : "\r\n";
+ $eol = !empty($this->_build_params['eol'])
+ ? $this->_build_params['eol'] : "\r\n";
- if ($headers['Content-Type'] == 'text/plain') {
- // single-part message: add charset and encoding
- $headers['Content-Type']
- .= ";$eol charset=" . $this->_build_params['text_charset'];
- $headers['Content-Transfer-Encoding']
- = $this->_build_params['text_encoding'];
- } else if ($headers['Content-Type'] == 'text/html') {
- // single-part message: add charset and encoding
- $headers['Content-Type']
- .= ";$eol charset=" . $this->_build_params['html_charset'];
- $headers['Content-Transfer-Encoding']
- = $this->_build_params['html_encoding'];
- } else {
- // multipart message: add charset and boundary
- if (!empty($this->_build_params['boundary'])) {
- $boundary = $this->_build_params['boundary'];
- } else if (!empty($this->_headers['Content-Type'])
- && preg_match('/boundary="([^"]+)"/', $this->_headers['Content-Type'], $m)
- ) {
- $boundary = $m[1];
- } else {
- $boundary = '=_' . md5(rand() . microtime());
- }
+ if ($headers['Content-Type'] == 'text/plain') {
+ // single-part message: add charset and encoding
+ $headers['Content-Type']
+ .= ";$eol charset=" . $this->_build_params['text_charset'];
+ $headers['Content-Transfer-Encoding']
+ = $this->_build_params['text_encoding'];
+ } else if ($headers['Content-Type'] == 'text/html') {
+ // single-part message: add charset and encoding
+ $headers['Content-Type']
+ .= ";$eol charset=" . $this->_build_params['html_charset'];
+ $headers['Content-Transfer-Encoding']
+ = $this->_build_params['html_encoding'];
+ } else {
+ // multipart message: add charset and boundary
+ if (!empty($this->_build_params['boundary'])) {
+ $boundary = $this->_build_params['boundary'];
+ } else if (!empty($this->_headers['Content-Type'])
+ && preg_match('/boundary="([^"]+)"/', $this->_headers['Content-Type'], $m)
+ ) {
+ $boundary = $m[1];
+ } else {
+ $boundary = '=_' . md5(rand() . microtime());
+ }
- $this->_build_params['boundary'] = $boundary;
- $headers['Content-Type'] .= ";$eol boundary=\"$boundary\"";
- }
+ $this->_build_params['boundary'] = $boundary;
+ $headers['Content-Type'] .= ";$eol boundary=\"$boundary\"";
+ }
- return $headers;
- }
+ return $headers;
+ }
- /**
- * Validate and set build parameters
- *
- * @return void
- * @access private
- */
- function _checkParams()
- {
- $encodings = array('7bit', '8bit', 'base64', 'quoted-printable');
+ /**
+ * Validate and set build parameters
+ *
+ * @return void
+ * @access private
+ */
+ function _checkParams()
+ {
+ $encodings = ['7bit', '8bit', 'base64', 'quoted-printable'];
- $this->_build_params['text_encoding']
- = strtolower($this->_build_params['text_encoding']);
- $this->_build_params['html_encoding']
- = strtolower($this->_build_params['html_encoding']);
+ $this->_build_params['text_encoding']
+ = strtolower($this->_build_params['text_encoding']);
+ $this->_build_params['html_encoding']
+ = strtolower($this->_build_params['html_encoding']);
- if (!in_array($this->_build_params['text_encoding'], $encodings)) {
- $this->_build_params['text_encoding'] = '7bit';
- }
- if (!in_array($this->_build_params['html_encoding'], $encodings)) {
- $this->_build_params['html_encoding'] = '7bit';
- }
+ if (!in_array($this->_build_params['text_encoding'], $encodings)) {
+ $this->_build_params['text_encoding'] = '7bit';
+ }
+ if (!in_array($this->_build_params['html_encoding'], $encodings)) {
+ $this->_build_params['html_encoding'] = '7bit';
+ }
- // text body
- if ($this->_build_params['text_encoding'] == '7bit'
- && !preg_match('/ascii/i', $this->_build_params['text_charset'])
- && preg_match('/[^\x00-\x7F]/', $this->_txtbody)
- ) {
- $this->_build_params['text_encoding'] = 'quoted-printable';
- }
- // html body
- if ($this->_build_params['html_encoding'] == '7bit'
- && !preg_match('/ascii/i', $this->_build_params['html_charset'])
- && preg_match('/[^\x00-\x7F]/', $this->_htmlbody)
- ) {
- $this->_build_params['html_encoding'] = 'quoted-printable';
- }
- }
+ // text body
+ if ($this->_build_params['text_encoding'] == '7bit'
+ && !preg_match('/ascii/i', $this->_build_params['text_charset'])
+ && preg_match('/[^\x00-\x7F]/', $this->_txtbody)
+ ) {
+ $this->_build_params['text_encoding'] = 'quoted-printable';
+ }
+ // html body
+ if ($this->_build_params['html_encoding'] == '7bit'
+ && !preg_match('/ascii/i', $this->_build_params['html_charset'])
+ && preg_match('/[^\x00-\x7F]/', $this->_htmlbody)
+ ) {
+ $this->_build_params['html_encoding'] = 'quoted-printable';
+ }
+ }
} // End of class
diff --git a/import/mimeDecode.php b/import/mimeDecode.php
index ace371a..754f430 100755
--- a/import/mimeDecode.php
+++ b/import/mimeDecode.php
@@ -56,7 +56,6 @@
* @link http://pear.php.net/package/Mail_mime
*/
-
/**
* require PEAR
*
@@ -64,7 +63,6 @@
*/
require_once 'PEAR.php';
-
/**
* The Mail_mimeDecode class is used to decode mail/mime messages
*
@@ -90,912 +88,903 @@ require_once 'PEAR.php';
*/
class Mail_mimeDecode extends PEAR
{
- /**
- * The raw email to decode
- *
- * @var string
- * @access private
- */
- var $_input;
+ /**
+ * The raw email to decode
+ *
+ * @var string
+ * @access private
+ */
+ var $_input;
- /**
- * The header part of the input
- *
- * @var string
- * @access private
- */
- var $_header;
+ /**
+ * The header part of the input
+ *
+ * @var string
+ * @access private
+ */
+ var $_header;
- /**
- * The body part of the input
- *
- * @var string
- * @access private
- */
- var $_body;
+ /**
+ * The body part of the input
+ *
+ * @var string
+ * @access private
+ */
+ var $_body;
- /**
- * If an error occurs, this is used to store the message
- *
- * @var string
- * @access private
- */
- var $_error;
+ /**
+ * If an error occurs, this is used to store the message
+ *
+ * @var string
+ * @access private
+ */
+ var $_error;
- /**
- * Flag to determine whether to include bodies in the
- * returned object.
- *
- * @var boolean
- * @access private
- */
- var $_include_bodies;
+ /**
+ * Flag to determine whether to include bodies in the
+ * returned object.
+ *
+ * @var boolean
+ * @access private
+ */
+ var $_include_bodies;
- /**
- * Flag to determine whether to decode bodies
- *
- * @var boolean
- * @access private
- */
- var $_decode_bodies;
+ /**
+ * Flag to determine whether to decode bodies
+ *
+ * @var boolean
+ * @access private
+ */
+ var $_decode_bodies;
- /**
- * Flag to determine whether to decode headers
- *
- * @var boolean
- * @access private
- */
- var $_decode_headers;
+ /**
+ * Flag to determine whether to decode headers
+ *
+ * @var boolean
+ * @access private
+ */
+ var $_decode_headers;
- /**
- * Flag to determine whether to include attached messages
- * as body in the returned object. Depends on $_include_bodies
- *
- * @var boolean
- * @access private
- */
- var $_rfc822_bodies;
+ /**
+ * Flag to determine whether to include attached messages
+ * as body in the returned object. Depends on $_include_bodies
+ *
+ * @var boolean
+ * @access private
+ */
+ var $_rfc822_bodies;
- /**
- * Constructor.
- *
- * Sets up the object, initialise the variables, and splits and
- * stores the header and body of the input.
- *
- * @param string The input to decode
- * @access public
- */
- function Mail_mimeDecode($input)
- {
- list($header, $body) = $this->_splitBodyHeader($input);
+ /**
+ * Constructor.
+ *
+ * Sets up the object, initialise the variables, and splits and
+ * stores the header and body of the input.
+ *
+ * @param string The input to decode
+ * @access public
+ */
+ function Mail_mimeDecode($input)
+ {
+ list($header, $body) = $this->_splitBodyHeader($input);
- $this->_input = $input;
- $this->_header = $header;
- $this->_body = $body;
- $this->_decode_bodies = false;
- $this->_include_bodies = true;
- $this->_rfc822_bodies = false;
- }
+ $this->_input = $input;
+ $this->_header = $header;
+ $this->_body = $body;
+ $this->_decode_bodies = false;
+ $this->_include_bodies = true;
+ $this->_rfc822_bodies = false;
+ }
- /**
- * Begins the decoding process. If called statically
- * it will create an object and call the decode() method
- * of it.
- *
- * @param array An array of various parameters that determine
- * various things:
- * include_bodies - Whether to include the body in the returned
- * object.
- * decode_bodies - Whether to decode the bodies
- * of the parts. (Transfer encoding)
- * decode_headers - Whether to decode headers
- * input - If called statically, this will be treated
- * as the input
- * @return object Decoded results
- * @access public
- */
- function decode($params = null)
- {
- // determine if this method has been called statically
- $isStatic = empty($this) || !is_a($this, __CLASS__);
+ /**
+ * Begins the decoding process. If called statically
+ * it will create an object and call the decode() method
+ * of it.
+ *
+ * @param array An array of various parameters that determine
+ * various things:
+ * include_bodies - Whether to include the body in the returned
+ * object.
+ * decode_bodies - Whether to decode the bodies
+ * of the parts. (Transfer encoding)
+ * decode_headers - Whether to decode headers
+ * input - If called statically, this will be treated
+ * as the input
+ * @return object Decoded results
+ * @access public
+ */
+ function decode($params = null)
+ {
+ // determine if this method has been called statically
+ $isStatic = empty($this) || !is_a($this, __CLASS__);
- // Have we been called statically?
+ // Have we been called statically?
// If so, create an object and pass details to that.
- if ($isStatic AND isset($params['input'])) {
+ if ($isStatic AND isset($params['input'])) {
- $obj = new Mail_mimeDecode($params['input']);
- $structure = $obj->decode($params);
+ $obj = new Mail_mimeDecode($params['input']);
+ $structure = $obj->decode($params);
- // Called statically but no input
- } elseif ($isStatic) {
- return PEAR::raiseError('Called statically and no input given');
+ // Called statically but no input
+ } elseif ($isStatic) {
+ return PEAR::raiseError('Called statically and no input given');
- // Called via an object
- } else {
- $this->_include_bodies = isset($params['include_bodies']) ?
- $params['include_bodies'] : false;
- $this->_decode_bodies = isset($params['decode_bodies']) ?
- $params['decode_bodies'] : false;
- $this->_decode_headers = isset($params['decode_headers']) ?
- $params['decode_headers'] : false;
- $this->_rfc822_bodies = isset($params['rfc_822bodies']) ?
- $params['rfc_822bodies'] : false;
+ // Called via an object
+ } else {
+ $this->_include_bodies = $params['include_bodies'] ?? false;
+ $this->_decode_bodies = $params['decode_bodies'] ?? false;
+ $this->_decode_headers = $params['decode_headers'] ?? false;
+ $this->_rfc822_bodies = $params['rfc_822bodies'] ?? false;
- $structure = $this->_decode($this->_header, $this->_body);
- if ($structure === false) {
- $structure = $this->raiseError($this->_error);
- }
- }
+ $structure = $this->_decode($this->_header, $this->_body);
+ if ($structure === false) {
+ $structure = $this->raiseError($this->_error);
+ }
+ }
- return $structure;
- }
+ return $structure;
+ }
- /**
- * Performs the decoding. Decodes the body string passed to it
- * If it finds certain content-types it will call itself in a
- * recursive fashion
- *
- * @param string Header section
- * @param string Body section
- * @return object Results of decoding process
- * @access private
- */
- function _decode($headers, $body, $default_ctype = 'text/plain')
- {
- $return = new stdClass;
- $return->headers = array();
- $headers = $this->_parseHeaders($headers);
+ /**
+ * Performs the decoding. Decodes the body string passed to it
+ * If it finds certain content-types it will call itself in a
+ * recursive fashion
+ *
+ * @param string Header section
+ * @param string Body section
+ * @return object Results of decoding process
+ * @access private
+ */
+ function _decode($headers, $body, $default_ctype = 'text/plain')
+ {
+ $return = new stdClass;
+ $return->headers = [];
+ $headers = $this->_parseHeaders($headers);
- foreach ($headers as $value) {
- $value['value'] = $this->_decode_headers ? $this->_decodeHeader($value['value']) : $value['value'];
- if (isset($return->headers[strtolower($value['name'])]) AND !is_array($return->headers[strtolower($value['name'])])) {
- $return->headers[strtolower($value['name'])] = array($return->headers[strtolower($value['name'])]);
- $return->headers[strtolower($value['name'])][] = $value['value'];
+ foreach ($headers as $value) {
+ $value['value'] = $this->_decode_headers ? $this->_decodeHeader($value['value']) : $value['value'];
+ if (isset($return->headers[strtolower($value['name'])]) AND !is_array($return->headers[strtolower($value['name'])])) {
+ $return->headers[strtolower($value['name'])] = [$return->headers[strtolower($value['name'])]];
+ $return->headers[strtolower($value['name'])][] = $value['value'];
- } elseif (isset($return->headers[strtolower($value['name'])])) {
- $return->headers[strtolower($value['name'])][] = $value['value'];
+ } elseif (isset($return->headers[strtolower($value['name'])])) {
+ $return->headers[strtolower($value['name'])][] = $value['value'];
- } else {
- $return->headers[strtolower($value['name'])] = $value['value'];
- }
- }
+ } else {
+ $return->headers[strtolower($value['name'])] = $value['value'];
+ }
+ }
+ foreach ($headers as $key => $value) {
+ $headers[$key]['name'] = strtolower($headers[$key]['name']);
+ switch ($headers[$key]['name']) {
- foreach ($headers as $key => $value) {
- $headers[$key]['name'] = strtolower($headers[$key]['name']);
- switch ($headers[$key]['name']) {
+ case 'content-type':
+ $content_type = $this->_parseHeaderValue($headers[$key]['value']);
- case 'content-type':
- $content_type = $this->_parseHeaderValue($headers[$key]['value']);
-
- if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) {
- $return->ctype_primary = $regs[1];
- $return->ctype_secondary = $regs[2];
- }
+ if (preg_match('/([0-9a-z+.-]+)\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) {
+ $return->ctype_primary = $regs[1];
+ $return->ctype_secondary = $regs[2];
+ }
- if (isset($content_type['other'])) {
- foreach($content_type['other'] as $p_name => $p_value) {
- $return->ctype_parameters[$p_name] = $p_value;
- }
- }
- break;
+ if (isset($content_type['other'])) {
+ foreach($content_type['other'] as $p_name => $p_value) {
+ $return->ctype_parameters[$p_name] = $p_value;
+ }
+ }
+ break;
- case 'content-disposition':
- $content_disposition = $this->_parseHeaderValue($headers[$key]['value']);
- $return->disposition = $content_disposition['value'];
- if (isset($content_disposition['other'])) {
- foreach($content_disposition['other'] as $p_name => $p_value) {
- $return->d_parameters[$p_name] = $p_value;
- }
- }
- break;
+ case 'content-disposition':
+ $content_disposition = $this->_parseHeaderValue($headers[$key]['value']);
+ $return->disposition = $content_disposition['value'];
+ if (isset($content_disposition['other'])) {
+ foreach($content_disposition['other'] as $p_name => $p_value) {
+ $return->d_parameters[$p_name] = $p_value;
+ }
+ }
+ break;
- case 'content-transfer-encoding':
- $content_transfer_encoding = $this->_parseHeaderValue($headers[$key]['value']);
- break;
- }
- }
+ case 'content-transfer-encoding':
+ $content_transfer_encoding = $this->_parseHeaderValue($headers[$key]['value']);
+ break;
+ }
+ }
- if (isset($content_type)) {
- switch (strtolower($content_type['value'])) {
- case 'text/plain':
- $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
- $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;
- break;
+ if (isset($content_type)) {
+ switch (strtolower($content_type['value'])) {
+ case 'text/plain':
+ $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
+ $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;
+ break;
- case 'text/html':
- $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
- $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;
- break;
+ case 'text/html':
+ $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
+ $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body) : null;
+ break;
- case 'multipart/parallel':
- case 'multipart/appledouble': // Appledouble mail
- case 'multipart/report': // RFC1892
- case 'multipart/signed': // PGP
- case 'multipart/digest':
- case 'multipart/alternative':
- case 'multipart/related':
- case 'multipart/mixed':
- case 'application/vnd.wap.multipart.related':
- if(!isset($content_type['other']['boundary'])){
- $this->_error = 'No boundary found for ' . $content_type['value'] . ' part';
- return false;
- }
+ case 'multipart/parallel':
+ case 'multipart/appledouble': // Appledouble mail
+ case 'multipart/report': // RFC1892
+ case 'multipart/signed': // PGP
+ case 'multipart/digest':
+ case 'multipart/alternative':
+ case 'multipart/related':
+ case 'multipart/mixed':
+ case 'application/vnd.wap.multipart.related':
+ if(!isset($content_type['other']['boundary'])){
+ $this->_error = 'No boundary found for ' . $content_type['value'] . ' part';
+ return false;
+ }
- $default_ctype = (strtolower($content_type['value']) === 'multipart/digest') ? 'message/rfc822' : 'text/plain';
+ $default_ctype = (strtolower($content_type['value']) === 'multipart/digest') ? 'message/rfc822' : 'text/plain';
- $parts = $this->_boundarySplit($body, $content_type['other']['boundary']);
- for ($i = 0; $i < count($parts); $i++) {
- list($part_header, $part_body) = $this->_splitBodyHeader($parts[$i]);
- $part = $this->_decode($part_header, $part_body, $default_ctype);
- if($part === false)
- $part = $this->raiseError($this->_error);
- $return->parts[] = $part;
- }
- break;
+ $parts = $this->_boundarySplit($body, $content_type['other']['boundary']);
+ for ($i = 0; $i < count($parts); $i++) {
+ list($part_header, $part_body) = $this->_splitBodyHeader($parts[$i]);
+ $part = $this->_decode($part_header, $part_body, $default_ctype);
+ if($part === false)
+ $part = $this->raiseError($this->_error);
+ $return->parts[] = $part;
+ }
+ break;
- case 'message/rfc822':
+ case 'message/rfc822':
if ($this->_rfc822_bodies) {
$encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
$return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body);
}
- $obj = new Mail_mimeDecode($body);
- $return->parts[] = $obj->decode(array('include_bodies' => $this->_include_bodies,
- 'decode_bodies' => $this->_decode_bodies,
- 'decode_headers' => $this->_decode_headers));
- unset($obj);
- break;
+ $obj = new Mail_mimeDecode($body);
+ $return->parts[] = $obj->decode(['include_bodies' => $this->_include_bodies,
+ 'decode_bodies' => $this->_decode_bodies,
+ 'decode_headers' => $this->_decode_headers, ]);
+ unset($obj);
+ break;
- default:
- if(!isset($content_transfer_encoding['value']))
- $content_transfer_encoding['value'] = '7bit';
- $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $content_transfer_encoding['value']) : $body) : null;
- break;
- }
+ default:
+ if(!isset($content_transfer_encoding['value']))
+ $content_transfer_encoding['value'] = '7bit';
+ $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body, $content_transfer_encoding['value']) : $body) : null;
+ break;
+ }
- } else {
- $ctype = explode('/', $default_ctype);
- $return->ctype_primary = $ctype[0];
- $return->ctype_secondary = $ctype[1];
- $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body) : $body) : null;
- }
+ } else {
+ $ctype = explode('/', $default_ctype);
+ $return->ctype_primary = $ctype[0];
+ $return->ctype_secondary = $ctype[1];
+ $this->_include_bodies ? $return->body = ($this->_decode_bodies ? $this->_decodeBody($body) : $body) : null;
+ }
- return $return;
- }
+ return $return;
+ }
- /**
- * Given the output of the above function, this will return an
- * array of references to the parts, indexed by mime number.
- *
- * @param object $structure The structure to go through
- * @param string $mime_number Internal use only.
- * @return array Mime numbers
- */
- function &getMimeNumbers(&$structure, $no_refs = false, $mime_number = '', $prepend = '')
- {
- $return = array();
- if (!empty($structure->parts)) {
- if ($mime_number != '') {
- $structure->mime_id = $prepend . $mime_number;
- $return[$prepend . $mime_number] = &$structure;
- }
- for ($i = 0; $i < count($structure->parts); $i++) {
+ /**
+ * Given the output of the above function, this will return an
+ * array of references to the parts, indexed by mime number.
+ *
+ * @param object $structure The structure to go through
+ * @param string $mime_number Internal use only.
+ * @return array Mime numbers
+ */
+ function &getMimeNumbers(&$structure, $no_refs = false, $mime_number = '', $prepend = '')
+ {
+ $return = [];
+ if (!empty($structure->parts)) {
+ if ($mime_number != '') {
+ $structure->mime_id = $prepend . $mime_number;
+ $return[$prepend . $mime_number] = &$structure;
+ }
+ for ($i = 0; $i < count($structure->parts); $i++) {
-
- if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') {
- $prepend = $prepend . $mime_number . '.';
- $_mime_number = '';
- } else {
- $_mime_number = ($mime_number == '' ? $i + 1 : sprintf('%s.%s', $mime_number, $i + 1));
- }
+ if (!empty($structure->headers['content-type']) AND substr(strtolower($structure->headers['content-type']), 0, 8) == 'message/') {
+ $prepend = $prepend . $mime_number . '.';
+ $_mime_number = '';
+ } else {
+ $_mime_number = ($mime_number == '' ? $i + 1 : sprintf('%s.%s', $mime_number, $i + 1));
+ }
- $arr = &Mail_mimeDecode::getMimeNumbers($structure->parts[$i], $no_refs, $_mime_number, $prepend);
- foreach ($arr as $key => $val) {
- $no_refs ? $return[$key] = '' : $return[$key] = &$arr[$key];
- }
- }
- } else {
- if ($mime_number == '') {
- $mime_number = '1';
- }
- $structure->mime_id = $prepend . $mime_number;
- $no_refs ? $return[$prepend . $mime_number] = '' : $return[$prepend . $mime_number] = &$structure;
- }
-
- return $return;
- }
+ $arr = &Mail_mimeDecode::getMimeNumbers($structure->parts[$i], $no_refs, $_mime_number, $prepend);
+ foreach ($arr as $key => $val) {
+ $no_refs ? $return[$key] = '' : $return[$key] = &$arr[$key];
+ }
+ }
+ } else {
+ if ($mime_number == '') {
+ $mime_number = '1';
+ }
+ $structure->mime_id = $prepend . $mime_number;
+ $no_refs ? $return[$prepend . $mime_number] = '' : $return[$prepend . $mime_number] = &$structure;
+ }
- /**
- * Given a string containing a header and body
- * section, this function will split them (at the first
- * blank line) and return them.
- *
- * @param string Input to split apart
- * @return array Contains header and body section
- * @access private
- */
- function _splitBodyHeader($input)
- {
- if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $match)) {
- return array($match[1], $match[2]);
- }
- // bug #17325 - empty bodies are allowed. - we just check that at least one line
- // of headers exist..
- if (count(explode("\n",$input))) {
- return array($input, '');
- }
- $this->_error = 'Could not split header and body';
- return false;
- }
+ return $return;
+ }
- /**
- * Parse headers given in $input and return
- * as assoc array.
- *
- * @param string Headers to parse
- * @return array Contains parsed headers
- * @access private
- */
- function _parseHeaders($input)
- {
+ /**
+ * Given a string containing a header and body
+ * section, this function will split them (at the first
+ * blank line) and return them.
+ *
+ * @param string Input to split apart
+ * @return array Contains header and body section
+ * @access private
+ */
+ function _splitBodyHeader($input)
+ {
+ if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $match)) {
+ return [$match[1], $match[2]];
+ }
+ // bug #17325 - empty bodies are allowed. - we just check that at least one line
+ // of headers exist..
+ if (count(explode("\n",$input))) {
+ return [$input, ''];
+ }
+ $this->_error = 'Could not split header and body';
+ return false;
+ }
- if ($input !== '') {
- // Unfold the input
- $input = preg_replace("/\r?\n/", "\r\n", $input);
- //#7065 - wrapping.. with encoded stuff.. - probably not needed,
- // wrapping just get's removed now.. this looks like it should be the correct solution.
- //$input = preg_replace("/=\r\n(\t| )+=/", '==', $input);
- //$input = preg_replace("/\r\n(\t| )+/", ' ', $input);
- $input = preg_replace("/\r\n(\t| )+/", '', $input);
- $headers = explode("\r\n", trim($input));
+ /**
+ * Parse headers given in $input and return
+ * as assoc array.
+ *
+ * @param string Headers to parse
+ * @return array Contains parsed headers
+ * @access private
+ */
+ function _parseHeaders($input)
+ {
- foreach ($headers as $value) {
- $hdr_name = substr($value, 0, $pos = strpos($value, ':'));
- $hdr_value = substr($value, $pos+1);
- if($hdr_value[0] == ' ')
- $hdr_value = substr($hdr_value, 1);
+ if ($input !== '') {
+ // Unfold the input
+ $input = preg_replace("/\r?\n/", "\r\n", $input);
+ //#7065 - wrapping.. with encoded stuff.. - probably not needed,
+ // wrapping just get's removed now.. this looks like it should be the correct solution.
+ //$input = preg_replace("/=\r\n(\t| )+=/", '==', $input);
+ //$input = preg_replace("/\r\n(\t| )+/", ' ', $input);
+ $input = preg_replace("/\r\n(\t| )+/", '', $input);
+ $headers = explode("\r\n", trim($input));
- $return[] = array(
- 'name' => $hdr_name,
- 'value' => $hdr_value
- );
- }
- } else {
- $return = array();
- }
+ foreach ($headers as $value) {
+ $hdr_name = substr($value, 0, $pos = strpos($value, ':'));
+ $hdr_value = substr($value, $pos+1);
+ if($hdr_value[0] == ' ')
+ $hdr_value = substr($hdr_value, 1);
- return $return;
- }
+ $return[] = [
+ 'name' => $hdr_name,
+ 'value' => $hdr_value,
+ ];
+ }
+ } else {
+ $return = [];
+ }
- /**
- * Function to parse a header value,
- * extract first part, and any secondary
- * parts (after ;) This function is not as
- * robust as it could be. Eg. header comments
- * in the wrong place will probably break it.
- *
- * @param string Header value to parse
- * @return array Contains parsed result
- * @access private
- */
- function _parseHeaderValue($input)
- {
+ return $return;
+ }
- if (($pos = strpos($input, ';')) === false) {
- $input = $this->_decode_headers ? $this->_decodeHeader($input) : $input;
- $return['value'] = trim($input);
- return $return;
- }
+ /**
+ * Function to parse a header value,
+ * extract first part, and any secondary
+ * parts (after ;) This function is not as
+ * robust as it could be. Eg. header comments
+ * in the wrong place will probably break it.
+ *
+ * @param string Header value to parse
+ * @return array Contains parsed result
+ * @access private
+ */
+ function _parseHeaderValue($input)
+ {
+ if (($pos = strpos($input, ';')) === false) {
+ $input = $this->_decode_headers ? $this->_decodeHeader($input) : $input;
+ $return['value'] = trim($input);
+ return $return;
+ }
+ $value = substr($input, 0, $pos);
+ $value = $this->_decode_headers ? $this->_decodeHeader($value) : $value;
+ $return['value'] = trim($value);
+ $input = trim(substr($input, $pos+1));
- $value = substr($input, 0, $pos);
- $value = $this->_decode_headers ? $this->_decodeHeader($value) : $value;
- $return['value'] = trim($value);
- $input = trim(substr($input, $pos+1));
+ if (!strlen($input) > 0) {
+ return $return;
+ }
+ // at this point input contains xxxx=".....";zzzz="...."
+ // since we are dealing with quoted strings, we need to handle this properly..
+ $i = 0;
+ $l = strlen($input);
+ $key = '';
+ $val = false; // our string - including quotes..
+ $q = false; // in quote..
+ $lq = ''; // last quote..
- if (!strlen($input) > 0) {
- return $return;
- }
- // at this point input contains xxxx=".....";zzzz="...."
- // since we are dealing with quoted strings, we need to handle this properly..
- $i = 0;
- $l = strlen($input);
- $key = '';
- $val = false; // our string - including quotes..
- $q = false; // in quote..
- $lq = ''; // last quote..
+ while ($i < $l) {
- while ($i < $l) {
-
- $c = $input[$i];
- //var_dump(array('i'=>$i,'c'=>$c,'q'=>$q, 'lq'=>$lq, 'key'=>$key, 'val' =>$val));
+ $c = $input[$i];
+ //var_dump(array('i'=>$i,'c'=>$c,'q'=>$q, 'lq'=>$lq, 'key'=>$key, 'val' =>$val));
- $escaped = false;
- if ($c == '\\') {
- $i++;
- if ($i == $l-1) { // end of string.
- break;
- }
- $escaped = true;
- $c = $input[$i];
- }
+ $escaped = false;
+ if ($c == '\\') {
+ $i++;
+ if ($i == $l-1) { // end of string.
+ break;
+ }
+ $escaped = true;
+ $c = $input[$i];
+ }
+ // state - in key..
+ if ($val === false) {
+ if (!$escaped && $c == '=') {
+ $val = '';
+ $key = trim($key);
+ $i++;
+ continue;
+ }
+ if (!$escaped && $c == ';') {
+ if ($key) { // a key without a value..
+ $key= trim($key);
+ $return['other'][$key] = '';
+ $return['other'][strtolower($key)] = '';
+ }
+ $key = '';
+ }
+ $key .= $c;
+ $i++;
+ continue;
+ }
+
+ // state - in value.. (as $val is set..)
+
+ if ($q === false) {
+ // not in quote yet.
+ if ((!strlen($val) || $lq !== false) && $c == ' ' || $c == "\t") {
+ $i++;
+ continue; // skip leading spaces after '=' or after '"'
+ }
+ if (!$escaped && ($c == '"' || $c == "'")) {
+ // start quoted area..
+ $q = $c;
+ // in theory should not happen raw text in value part..
+ // but we will handle it as a merged part of the string..
+ $val = !strlen(trim($val)) ? '' : trim($val);
+ $i++;
+ continue;
+ }
+ // got end....
+ if (!$escaped && $c == ';') {
+
+ $val = trim($val);
+ $added = false;
+ if (preg_match('/\*[0-9]+$/', $key)) {
+ // this is the extended aaa*0=...;aaa*1=.... code
+ // it assumes the pieces arrive in order, and are valid...
+ $key = preg_replace('/\*[0-9]+$/', '', $key);
+ if (isset($return['other'][$key])) {
+ $return['other'][$key] .= $val;
+ if (strtolower($key) != $key) {
+ $return['other'][strtolower($key)] .= $val;
+ }
+ $added = true;
+ }
+ // continue and use standard setters..
+ }
+ if (!$added) {
+ $return['other'][$key] = $val;
+ $return['other'][strtolower($key)] = $val;
+ }
+ $val = false;
+ $key = '';
+ $lq = false;
+ $i++;
+ continue;
+ }
- // state - in key..
- if ($val === false) {
- if (!$escaped && $c == '=') {
- $val = '';
- $key = trim($key);
- $i++;
- continue;
- }
- if (!$escaped && $c == ';') {
- if ($key) { // a key without a value..
- $key= trim($key);
- $return['other'][$key] = '';
- $return['other'][strtolower($key)] = '';
- }
- $key = '';
- }
- $key .= $c;
- $i++;
- continue;
- }
-
- // state - in value.. (as $val is set..)
+ $val .= $c;
+ $i++;
+ continue;
+ }
- if ($q === false) {
- // not in quote yet.
- if ((!strlen($val) || $lq !== false) && $c == ' ' || $c == "\t") {
- $i++;
- continue; // skip leading spaces after '=' or after '"'
- }
- if (!$escaped && ($c == '"' || $c == "'")) {
- // start quoted area..
- $q = $c;
- // in theory should not happen raw text in value part..
- // but we will handle it as a merged part of the string..
- $val = !strlen(trim($val)) ? '' : trim($val);
- $i++;
- continue;
- }
- // got end....
- if (!$escaped && $c == ';') {
+ // state - in quote..
+ if (!$escaped && $c == $q) { // potential exit state..
- $val = trim($val);
- $added = false;
- if (preg_match('/\*[0-9]+$/', $key)) {
- // this is the extended aaa*0=...;aaa*1=.... code
- // it assumes the pieces arrive in order, and are valid...
- $key = preg_replace('/\*[0-9]+$/', '', $key);
- if (isset($return['other'][$key])) {
- $return['other'][$key] .= $val;
- if (strtolower($key) != $key) {
- $return['other'][strtolower($key)] .= $val;
- }
- $added = true;
- }
- // continue and use standard setters..
- }
- if (!$added) {
- $return['other'][$key] = $val;
- $return['other'][strtolower($key)] = $val;
- }
- $val = false;
- $key = '';
- $lq = false;
- $i++;
- continue;
- }
+ // end of quoted string..
+ $lq = $q;
+ $q = false;
+ $i++;
+ continue;
+ }
- $val .= $c;
- $i++;
- continue;
- }
-
- // state - in quote..
- if (!$escaped && $c == $q) { // potential exit state..
+ // normal char inside of quoted string..
+ $val.= $c;
+ $i++;
+ }
- // end of quoted string..
- $lq = $q;
- $q = false;
- $i++;
- continue;
- }
-
- // normal char inside of quoted string..
- $val.= $c;
- $i++;
- }
-
- // do we have anything left..
- if (strlen(trim($key)) || $val !== false) {
-
- $val = trim($val);
- $added = false;
- if ($val !== false && preg_match('/\*[0-9]+$/', $key)) {
- // no dupes due to our crazy regexp.
- $key = preg_replace('/\*[0-9]+$/', '', $key);
- if (isset($return['other'][$key])) {
- $return['other'][$key] .= $val;
- if (strtolower($key) != $key) {
- $return['other'][strtolower($key)] .= $val;
- }
- $added = true;
- }
- // continue and use standard setters..
- }
- if (!$added) {
- $return['other'][$key] = $val;
- $return['other'][strtolower($key)] = $val;
- }
- }
- // decode values.
- foreach($return['other'] as $key =>$val) {
- $return['other'][$key] = $this->_decode_headers ? $this->_decodeHeader($val) : $val;
- }
- //print_r($return);
- return $return;
- }
+ // do we have anything left..
+ if (strlen(trim($key)) || $val !== false) {
+
+ $val = trim($val);
+ $added = false;
+ if ($val !== false && preg_match('/\*[0-9]+$/', $key)) {
+ // no dupes due to our crazy regexp.
+ $key = preg_replace('/\*[0-9]+$/', '', $key);
+ if (isset($return['other'][$key])) {
+ $return['other'][$key] .= $val;
+ if (strtolower($key) != $key) {
+ $return['other'][strtolower($key)] .= $val;
+ }
+ $added = true;
+ }
+ // continue and use standard setters..
+ }
+ if (!$added) {
+ $return['other'][$key] = $val;
+ $return['other'][strtolower($key)] = $val;
+ }
+ }
+ // decode values.
+ foreach($return['other'] as $key =>$val) {
+ $return['other'][$key] = $this->_decode_headers ? $this->_decodeHeader($val) : $val;
+ }
+ //print_r($return);
+ return $return;
+ }
- /**
- * This function splits the input based
- * on the given boundary
- *
- * @param string Input to parse
- * @return array Contains array of resulting mime parts
- * @access private
- */
- function _boundarySplit($input, $boundary)
- {
- $parts = array();
+ /**
+ * This function splits the input based
+ * on the given boundary
+ *
+ * @param string Input to parse
+ * @return array Contains array of resulting mime parts
+ * @access private
+ */
+ function _boundarySplit($input, $boundary)
+ {
+ $parts = [];
- $bs_possible = substr($boundary, 2, -2);
- $bs_check = '\"' . $bs_possible . '\"';
+ $bs_possible = substr($boundary, 2, -2);
+ $bs_check = '\"' . $bs_possible . '\"';
- if ($boundary == $bs_check) {
- $boundary = $bs_possible;
- }
+ if ($boundary == $bs_check) {
+ $boundary = $bs_possible;
+ }
- $tmp = preg_split("/--".preg_quote($boundary, '/')."(\b|--)/", $input);
- $len = count($tmp) -1;
- for ($i = 1; $i < $len; $i++) {
- if (strlen(trim($tmp[$i]))) {
- $parts[] = $tmp[$i];
- }
- }
- // add the last part on if it does not end with the 'closing indicator'
- if (!empty($tmp[$len]) && $tmp[$len][0] != '-') {
- $parts[] = $tmp[$len];
- }
- return $parts;
- }
+ $tmp = preg_split("/--".preg_quote($boundary, '/')."(\b|--)/", $input);
+ $len = count($tmp) -1;
+ for ($i = 1; $i < $len; $i++) {
+ if (strlen(trim($tmp[$i]))) {
+ $parts[] = $tmp[$i];
+ }
+ }
+ // add the last part on if it does not end with the 'closing indicator'
+ if (!empty($tmp[$len]) && $tmp[$len][0] != '-') {
+ $parts[] = $tmp[$len];
+ }
+ return $parts;
+ }
- /**
- * Given a header, this function will decode it
- * according to RFC2047. Probably not *exactly*
- * conformant, but it does pass all the given
- * examples (in RFC2047).
- *
- * @param string Input header value to decode
- * @return string Decoded header value
- * @access private
- */
- function _decodeHeader($input)
- {
- // Remove white space between encoded-words
- $input = preg_replace('/(=\?[^?]+\?(q|b)\?[^?]*\?=)(\s)+=\?/i', '\1=?', $input);
+ /**
+ * Given a header, this function will decode it
+ * according to RFC2047. Probably not *exactly*
+ * conformant, but it does pass all the given
+ * examples (in RFC2047).
+ *
+ * @param string Input header value to decode
+ * @return string Decoded header value
+ * @access private
+ */
+ function _decodeHeader($input)
+ {
+ // Remove white space between encoded-words
+ $input = preg_replace('/(=\?[^?]+\?(q|b)\?[^?]*\?=)(\s)+=\?/i', '\1=?', $input);
- // For each encoded-word...
- while (preg_match('/(=\?([^?]+)\?(q|b)\?([^?]*)\?=)/i', $input, $matches)) {
+ // For each encoded-word...
+ while (preg_match('/(=\?([^?]+)\?(q|b)\?([^?]*)\?=)/i', $input, $matches)) {
- $encoded = $matches[1];
- $charset = $matches[2];
- $encoding = $matches[3];
- $text = $matches[4];
+ $encoded = $matches[1];
+ $charset = $matches[2];
+ $encoding = $matches[3];
+ $text = $matches[4];
- switch (strtolower($encoding)) {
- case 'b':
- $text = base64_decode($text);
- break;
+ switch (strtolower($encoding)) {
+ case 'b':
+ $text = base64_decode($text);
+ break;
- case 'q':
- $text = str_replace('_', ' ', $text);
- preg_match_all('/=([a-f0-9]{2})/i', $text, $matches);
- foreach($matches[1] as $value)
- $text = str_replace('='.$value, chr(hexdec($value)), $text);
- break;
- }
+ case 'q':
+ $text = str_replace('_', ' ', $text);
+ preg_match_all('/=([a-f0-9]{2})/i', $text, $matches);
+ foreach($matches[1] as $value)
+ $text = str_replace('='.$value, chr(hexdec($value)), $text);
+ break;
+ }
- $input = str_replace($encoded, $text, $input);
- }
+ $input = str_replace($encoded, $text, $input);
+ }
- return $input;
- }
+ return $input;
+ }
- /**
- * Given a body string and an encoding type,
- * this function will decode and return it.
- *
- * @param string Input body to decode
- * @param string Encoding type to use.
- * @return string Decoded body
- * @access private
- */
- function _decodeBody($input, $encoding = '7bit')
- {
- switch (strtolower($encoding)) {
- case '7bit':
- return $input;
- break;
+ /**
+ * Given a body string and an encoding type,
+ * this function will decode and return it.
+ *
+ * @param string Input body to decode
+ * @param string Encoding type to use.
+ * @return string Decoded body
+ * @access private
+ */
+ function _decodeBody($input, $encoding = '7bit')
+ {
+ switch (strtolower($encoding)) {
+ case '7bit':
+ return $input;
+ break;
- case 'quoted-printable':
- return $this->_quotedPrintableDecode($input);
- break;
+ case 'quoted-printable':
+ return $this->_quotedPrintableDecode($input);
+ break;
- case 'base64':
- return base64_decode($input);
- break;
+ case 'base64':
+ return base64_decode($input);
+ break;
- default:
- return $input;
- }
- }
+ default:
+ return $input;
+ }
+ }
- /**
- * Given a quoted-printable string, this
- * function will decode and return it.
- *
- * @param string Input body to decode
- * @return string Decoded body
- * @access private
- */
- function _quotedPrintableDecode($input)
- {
- // Remove soft line breaks
- $input = preg_replace("/=\r?\n/", '', $input);
+ /**
+ * Given a quoted-printable string, this
+ * function will decode and return it.
+ *
+ * @param string Input body to decode
+ * @return string Decoded body
+ * @access private
+ */
+ function _quotedPrintableDecode($input)
+ {
+ // Remove soft line breaks
+ $input = preg_replace("/=\r?\n/", '', $input);
- // Replace encoded characters
+ // Replace encoded characters
$input = preg_replace('/=([a-f0-9]{2})/ie', "chr(hexdec('\\1'))", $input);
- return $input;
- }
+ return $input;
+ }
- /**
- * Checks the input for uuencoded files and returns
- * an array of them. Can be called statically, eg:
- *
- * $files =& Mail_mimeDecode::uudecode($some_text);
- *
- * It will check for the begin 666 ... end syntax
- * however and won't just blindly decode whatever you
- * pass it.
- *
- * @param string Input body to look for attahcments in
- * @return array Decoded bodies, filenames and permissions
- * @access public
- * @author Unknown
- */
- function &uudecode($input)
- {
- // Find all uuencoded sections
- preg_match_all("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $input, $matches);
+ /**
+ * Checks the input for uuencoded files and returns
+ * an array of them. Can be called statically, eg:
+ *
+ * $files =& Mail_mimeDecode::uudecode($some_text);
+ *
+ * It will check for the begin 666 ... end syntax
+ * however and won't just blindly decode whatever you
+ * pass it.
+ *
+ * @param string Input body to look for attahcments in
+ * @return array Decoded bodies, filenames and permissions
+ * @access public
+ * @author Unknown
+ */
+ function &uudecode($input)
+ {
+ // Find all uuencoded sections
+ preg_match_all("/begin ([0-7]{3}) (.+)\r?\n(.+)\r?\nend/Us", $input, $matches);
- for ($j = 0; $j < count($matches[3]); $j++) {
+ for ($j = 0; $j < count($matches[3]); $j++) {
- $str = $matches[3][$j];
- $filename = $matches[2][$j];
- $fileperm = $matches[1][$j];
+ $str = $matches[3][$j];
+ $filename = $matches[2][$j];
+ $fileperm = $matches[1][$j];
- $file = '';
- $str = preg_split("/\r?\n/", trim($str));
- $strlen = count($str);
+ $file = '';
+ $str = preg_split("/\r?\n/", trim($str));
+ $strlen = count($str);
- for ($i = 0; $i < $strlen; $i++) {
- $pos = 1;
- $d = 0;
- $len=(int)(((ord(substr($str[$i],0,1)) -32) - ' ') & 077);
+ for ($i = 0; $i < $strlen; $i++) {
+ $pos = 1;
+ $d = 0;
+ $len=(int)(((ord(substr($str[$i],0,1)) -32) - ' ') & 077);
- while (($d + 3 <= $len) AND ($pos + 4 <= strlen($str[$i]))) {
- $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
- $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
- $c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);
- $c3 = (ord(substr($str[$i],$pos+3,1)) ^ 0x20);
- $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
+ while (($d + 3 <= $len) AND ($pos + 4 <= strlen($str[$i]))) {
+ $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
+ $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
+ $c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);
+ $c3 = (ord(substr($str[$i],$pos+3,1)) ^ 0x20);
+ $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
- $file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));
+ $file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));
- $file .= chr(((($c2 - ' ') & 077) << 6) | (($c3 - ' ') & 077));
+ $file .= chr(((($c2 - ' ') & 077) << 6) | (($c3 - ' ') & 077));
- $pos += 4;
- $d += 3;
- }
+ $pos += 4;
+ $d += 3;
+ }
- if (($d + 2 <= $len) && ($pos + 3 <= strlen($str[$i]))) {
- $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
- $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
- $c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);
- $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
+ if (($d + 2 <= $len) && ($pos + 3 <= strlen($str[$i]))) {
+ $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
+ $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
+ $c2 = (ord(substr($str[$i],$pos+2,1)) ^ 0x20);
+ $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
- $file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));
+ $file .= chr(((($c1 - ' ') & 077) << 4) | ((($c2 - ' ') & 077) >> 2));
- $pos += 3;
- $d += 2;
- }
+ $pos += 3;
+ $d += 2;
+ }
- if (($d + 1 <= $len) && ($pos + 2 <= strlen($str[$i]))) {
- $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
- $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
- $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
+ if (($d + 1 <= $len) && ($pos + 2 <= strlen($str[$i]))) {
+ $c0 = (ord(substr($str[$i],$pos,1)) ^ 0x20);
+ $c1 = (ord(substr($str[$i],$pos+1,1)) ^ 0x20);
+ $file .= chr(((($c0 - ' ') & 077) << 2) | ((($c1 - ' ') & 077) >> 4));
- }
- }
- $files[] = array('filename' => $filename, 'fileperm' => $fileperm, 'filedata' => $file);
- }
+ }
+ }
+ $files[] = ['filename' => $filename, 'fileperm' => $fileperm, 'filedata' => $file];
+ }
- return $files;
- }
+ return $files;
+ }
- /**
- * getSendArray() returns the arguments required for Mail::send()
- * used to build the arguments for a mail::send() call
- *
- * Usage:
- * $mailtext = Full email (for example generated by a template)
- * $decoder = new Mail_mimeDecode($mailtext);
- * $parts = $decoder->getSendArray();
- * if (!PEAR::isError($parts) {
- * list($recipents,$headers,$body) = $parts;
- * $mail = Mail::factory('smtp');
- * $mail->send($recipents,$headers,$body);
- * } else {
- * echo $parts->message;
- * }
- * @return mixed array of recipeint, headers,body or Pear_Error
- * @access public
- * @author Alan Knowles <alan@akbkhome.com>
- */
- function getSendArray()
- {
- // prevent warning if this is not set
- $this->_decode_headers = FALSE;
- $headerlist =$this->_parseHeaders($this->_header);
- $to = "";
- if (!$headerlist) {
- return $this->raiseError("Message did not contain headers");
- }
- foreach($headerlist as $item) {
- $header[$item['name']] = $item['value'];
- switch (strtolower($item['name'])) {
- case "to":
- case "cc":
- case "bcc":
- $to .= ",".$item['value'];
- default:
- break;
- }
- }
- if ($to == "") {
- return $this->raiseError("Message did not contain any recipents");
- }
- $to = substr($to,1);
- return array($to,$header,$this->_body);
- }
+ /**
+ * getSendArray() returns the arguments required for Mail::send()
+ * used to build the arguments for a mail::send() call
+ *
+ * Usage:
+ * $mailtext = Full email (for example generated by a template)
+ * $decoder = new Mail_mimeDecode($mailtext);
+ * $parts = $decoder->getSendArray();
+ * if (!PEAR::isError($parts) {
+ * list($recipents,$headers,$body) = $parts;
+ * $mail = Mail::factory('smtp');
+ * $mail->send($recipents,$headers,$body);
+ * } else {
+ * echo $parts->message;
+ * }
+ * @return mixed array of recipeint, headers,body or Pear_Error
+ * @access public
+ * @author Alan Knowles <alan@akbkhome.com>
+ */
+ function getSendArray()
+ {
+ // prevent warning if this is not set
+ $this->_decode_headers = FALSE;
+ $headerlist =$this->_parseHeaders($this->_header);
+ $to = "";
+ if (!$headerlist) {
+ return $this->raiseError("Message did not contain headers");
+ }
+ foreach($headerlist as $item) {
+ $header[$item['name']] = $item['value'];
+ switch (strtolower($item['name'])) {
+ case "to":
+ case "cc":
+ case "bcc":
+ $to .= ",".$item['value'];
+ default:
+ break;
+ }
+ }
+ if ($to == "") {
+ return $this->raiseError("Message did not contain any recipents");
+ }
+ $to = substr($to,1);
+ return [$to,$header,$this->_body];
+ }
- /**
- * Returns a xml copy of the output of
- * Mail_mimeDecode::decode. Pass the output in as the
- * argument. This function can be called statically. Eg:
- *
- * $output = $obj->decode();
- * $xml = Mail_mimeDecode::getXML($output);
- *
- * The DTD used for this should have been in the package. Or
- * alternatively you can get it from cvs, or here:
- * http://www.phpguru.org/xmail/xmail.dtd.
- *
- * @param object Input to convert to xml. This should be the
- * output of the Mail_mimeDecode::decode function
- * @return string XML version of input
- * @access public
- */
- function getXML($input)
- {
- $crlf = "\r\n";
- $output = '<?xml version=\'1.0\'?>' . $crlf .
- '<!DOCTYPE email SYSTEM "http://www.phpguru.org/xmail/xmail.dtd">' . $crlf .
- '<email>' . $crlf .
- Mail_mimeDecode::_getXML($input) .
- '</email>';
+ /**
+ * Returns a xml copy of the output of
+ * Mail_mimeDecode::decode. Pass the output in as the
+ * argument. This function can be called statically. Eg:
+ *
+ * $output = $obj->decode();
+ * $xml = Mail_mimeDecode::getXML($output);
+ *
+ * The DTD used for this should have been in the package. Or
+ * alternatively you can get it from cvs, or here:
+ * http://www.phpguru.org/xmail/xmail.dtd.
+ *
+ * @param object Input to convert to xml. This should be the
+ * output of the Mail_mimeDecode::decode function
+ * @return string XML version of input
+ * @access public
+ */
+ function getXML($input)
+ {
+ $crlf = "\r\n";
+ $output = '<?xml version=\'1.0\'?>' . $crlf .
+ '<!DOCTYPE email SYSTEM "http://www.phpguru.org/xmail/xmail.dtd">' . $crlf .
+ '<email>' . $crlf .
+ Mail_mimeDecode::_getXML($input) .
+ '</email>';
- return $output;
- }
+ return $output;
+ }
- /**
- * Function that does the actual conversion to xml. Does a single
- * mimepart at a time.
- *
- * @param object Input to convert to xml. This is a mimepart object.
- * It may or may not contain subparts.
- * @param integer Number of tabs to indent
- * @return string XML version of input
- * @access private
- */
- function _getXML($input, $indent = 1)
- {
- $htab = "\t";
- $crlf = "\r\n";
- $output = '';
- $headers = @(array)$input->headers;
+ /**
+ * Function that does the actual conversion to xml. Does a single
+ * mimepart at a time.
+ *
+ * @param object Input to convert to xml. This is a mimepart object.
+ * It may or may not contain subparts.
+ * @param integer Number of tabs to indent
+ * @return string XML version of input
+ * @access private
+ */
+ function _getXML($input, $indent = 1)
+ {
+ $htab = "\t";
+ $crlf = "\r\n";
+ $output = '';
+ $headers = @(array)$input->headers;
- foreach ($headers as $hdr_name => $hdr_value) {
+ foreach ($headers as $hdr_name => $hdr_value) {
- // Multiple headers with this name
- if (is_array($headers[$hdr_name])) {
- for ($i = 0; $i < count($hdr_value); $i++) {
- $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value[$i], $indent);
- }
+ // Multiple headers with this name
+ if (is_array($headers[$hdr_name])) {
+ for ($i = 0; $i < count($hdr_value); $i++) {
+ $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value[$i], $indent);
+ }
- // Only one header of this sort
- } else {
- $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value, $indent);
- }
- }
+ // Only one header of this sort
+ } else {
+ $output .= Mail_mimeDecode::_getXML_helper($hdr_name, $hdr_value, $indent);
+ }
+ }
- if (!empty($input->parts)) {
- for ($i = 0; $i < count($input->parts); $i++) {
- $output .= $crlf . str_repeat($htab, $indent) . '<mimepart>' . $crlf .
- Mail_mimeDecode::_getXML($input->parts[$i], $indent+1) .
- str_repeat($htab, $indent) . '</mimepart>' . $crlf;
- }
- } elseif (isset($input->body)) {
- $output .= $crlf . str_repeat($htab, $indent) . '<body><![CDATA[' .
- $input->body . ']]></body>' . $crlf;
- }
+ if (!empty($input->parts)) {
+ for ($i = 0; $i < count($input->parts); $i++) {
+ $output .= $crlf . str_repeat($htab, $indent) . '<mimepart>' . $crlf .
+ Mail_mimeDecode::_getXML($input->parts[$i], $indent+1) .
+ str_repeat($htab, $indent) . '</mimepart>' . $crlf;
+ }
+ } elseif (isset($input->body)) {
+ $output .= $crlf . str_repeat($htab, $indent) . '<body><![CDATA[' .
+ $input->body . ']]></body>' . $crlf;
+ }
- return $output;
- }
+ return $output;
+ }
- /**
- * Helper function to _getXML(). Returns xml of a header.
- *
- * @param string Name of header
- * @param string Value of header
- * @param integer Number of tabs to indent
- * @return string XML version of input
- * @access private
- */
- function _getXML_helper($hdr_name, $hdr_value, $indent)
- {
- $htab = "\t";
- $crlf = "\r\n";
- $return = '';
+ /**
+ * Helper function to _getXML(). Returns xml of a header.
+ *
+ * @param string Name of header
+ * @param string Value of header
+ * @param integer Number of tabs to indent
+ * @return string XML version of input
+ * @access private
+ */
+ function _getXML_helper($hdr_name, $hdr_value, $indent)
+ {
+ $htab = "\t";
+ $crlf = "\r\n";
+ $return = '';
- $new_hdr_value = ($hdr_name != 'received') ? Mail_mimeDecode::_parseHeaderValue($hdr_value) : array('value' => $hdr_value);
- $new_hdr_name = str_replace(' ', '-', ucwords(str_replace('-', ' ', $hdr_name)));
+ $new_hdr_value = ($hdr_name != 'received') ? Mail_mimeDecode::_parseHeaderValue($hdr_value) : ['value' => $hdr_value];
+ $new_hdr_name = str_replace(' ', '-', ucwords(str_replace('-', ' ', $hdr_name)));
- // Sort out any parameters
- if (!empty($new_hdr_value['other'])) {
- foreach ($new_hdr_value['other'] as $paramname => $paramvalue) {
- $params[] = str_repeat($htab, $indent) . $htab . '<parameter>' . $crlf .
- str_repeat($htab, $indent) . $htab . $htab . '<paramname>' . htmlspecialchars($paramname) . '</paramname>' . $crlf .
- str_repeat($htab, $indent) . $htab . $htab . '<paramvalue>' . htmlspecialchars($paramvalue) . '</paramvalue>' . $crlf .
- str_repeat($htab, $indent) . $htab . '</parameter>' . $crlf;
- }
+ // Sort out any parameters
+ if (!empty($new_hdr_value['other'])) {
+ foreach ($new_hdr_value['other'] as $paramname => $paramvalue) {
+ $params[] = str_repeat($htab, $indent) . $htab . '<parameter>' . $crlf .
+ str_repeat($htab, $indent) . $htab . $htab . '<paramname>' . htmlspecialchars($paramname) . '</paramname>' . $crlf .
+ str_repeat($htab, $indent) . $htab . $htab . '<paramvalue>' . htmlspecialchars($paramvalue) . '</paramvalue>' . $crlf .
+ str_repeat($htab, $indent) . $htab . '</parameter>' . $crlf;
+ }
- $params = implode('', $params);
- } else {
- $params = '';
- }
+ $params = implode('', $params);
+ } else {
+ $params = '';
+ }
- $return = str_repeat($htab, $indent) . '<header>' . $crlf .
- str_repeat($htab, $indent) . $htab . '<headername>' . htmlspecialchars($new_hdr_name) . '</headername>' . $crlf .
- str_repeat($htab, $indent) . $htab . '<headervalue>' . htmlspecialchars($new_hdr_value['value']) . '</headervalue>' . $crlf .
- $params .
- str_repeat($htab, $indent) . '</header>' . $crlf;
+ $return = str_repeat($htab, $indent) . '<header>' . $crlf .
+ str_repeat($htab, $indent) . $htab . '<headername>' . htmlspecialchars($new_hdr_name) . '</headername>' . $crlf .
+ str_repeat($htab, $indent) . $htab . '<headervalue>' . htmlspecialchars($new_hdr_value['value']) . '</headervalue>' . $crlf .
+ $params .
+ str_repeat($htab, $indent) . '</header>' . $crlf;
- return $return;
- }
+ return $return;
+ }
} // End of class
diff --git a/import/mimePart.php b/import/mimePart.php
index 34317ad..626da57 100755
--- a/import/mimePart.php
+++ b/import/mimePart.php
@@ -52,7 +52,6 @@
* @link http://pear.php.net/package/Mail_mime
*/
-
/**
* The Mail_mimePart class is used to create MIME E-mail messages
*
@@ -75,1140 +74,1140 @@
*/
class Mail_mimePart
{
- /**
- * The encoding type of this part
- *
- * @var string
- * @access private
- */
- var $_encoding;
+ /**
+ * The encoding type of this part
+ *
+ * @var string
+ * @access private
+ */
+ var $_encoding;
- /**
- * An array of subparts
- *
- * @var array
- * @access private
- */
- var $_subparts;
+ /**
+ * An array of subparts
+ *
+ * @var array
+ * @access private
+ */
+ var $_subparts;
- /**
- * The output of this part after being built
- *
- * @var string
- * @access private
- */
- var $_encoded;
+ /**
+ * The output of this part after being built
+ *
+ * @var string
+ * @access private
+ */
+ var $_encoded;
- /**
- * Headers for this part
- *
- * @var array
- * @access private
- */
- var $_headers;
+ /**
+ * Headers for this part
+ *
+ * @var array
+ * @access private
+ */
+ var $_headers;
- /**
- * The body of this part (not encoded)
- *
- * @var string
- * @access private
- */
- var $_body;
+ /**
+ * The body of this part (not encoded)
+ *
+ * @var string
+ * @access private
+ */
+ var $_body;
- /**
- * The location of file with body of this part (not encoded)
- *
- * @var string
- * @access private
- */
- var $_body_file;
+ /**
+ * The location of file with body of this part (not encoded)
+ *
+ * @var string
+ * @access private
+ */
+ var $_body_file;
- /**
- * The end-of-line sequence
- *
- * @var string
- * @access private
- */
- var $_eol = "\r\n";
+ /**
+ * The end-of-line sequence
+ *
+ * @var string
+ * @access private
+ */
+ var $_eol = "\r\n";
- /**
- * Constructor.
- *
- * Sets up the object.
- *
- * @param string $body The body of the mime part if any.
- * @param array $params An associative array of optional parameters:
- * content_type - The content type for this part eg multipart/mixed
- * encoding - The encoding to use, 7bit, 8bit,
- * base64, or quoted-printable
- * cid - Content ID to apply
- * disposition - Content disposition, inline or attachment
- * dfilename - Filename parameter for content disposition
- * description - Content description
- * charset - Character set to use
- * name_encoding - Encoding for attachment name (Content-Type)
- * By default filenames are encoded using RFC2231
- * Here you can set RFC2047 encoding (quoted-printable
- * or base64) instead
- * filename_encoding - Encoding for attachment filename (Content-Disposition)
- * See 'name_encoding'
- * eol - End of line sequence. Default: "\r\n"
- * body_file - Location of file with part's body (instead of $body)
- *
- * @access public
- */
- function Mail_mimePart($body = '', $params = array())
- {
- if (!empty($params['eol'])) {
- $this->_eol = $params['eol'];
- } else if (defined('MAIL_MIMEPART_CRLF')) { // backward-copat.
- $this->_eol = MAIL_MIMEPART_CRLF;
- }
+ /**
+ * Constructor.
+ *
+ * Sets up the object.
+ *
+ * @param string $body The body of the mime part if any.
+ * @param array $params An associative array of optional parameters:
+ * content_type - The content type for this part eg multipart/mixed
+ * encoding - The encoding to use, 7bit, 8bit,
+ * base64, or quoted-printable
+ * cid - Content ID to apply
+ * disposition - Content disposition, inline or attachment
+ * dfilename - Filename parameter for content disposition
+ * description - Content description
+ * charset - Character set to use
+ * name_encoding - Encoding for attachment name (Content-Type)
+ * By default filenames are encoded using RFC2231
+ * Here you can set RFC2047 encoding (quoted-printable
+ * or base64) instead
+ * filename_encoding - Encoding for attachment filename (Content-Disposition)
+ * See 'name_encoding'
+ * eol - End of line sequence. Default: "\r\n"
+ * body_file - Location of file with part's body (instead of $body)
+ *
+ * @access public
+ */
+ function Mail_mimePart($body = '', $params = [])
+ {
+ if (!empty($params['eol'])) {
+ $this->_eol = $params['eol'];
+ } else if (defined('MAIL_MIMEPART_CRLF')) { // backward-copat.
+ $this->_eol = MAIL_MIMEPART_CRLF;
+ }
- $c_type = array();
- $c_disp = array();
- foreach ($params as $key => $value) {
- switch ($key) {
- case 'content_type':
- $c_type['type'] = $value;
- break;
+ $c_type = [];
+ $c_disp = [];
+ foreach ($params as $key => $value) {
+ switch ($key) {
+ case 'content_type':
+ $c_type['type'] = $value;
+ break;
- case 'encoding':
- $this->_encoding = $value;
- $headers['Content-Transfer-Encoding'] = $value;
- break;
+ case 'encoding':
+ $this->_encoding = $value;
+ $headers['Content-Transfer-Encoding'] = $value;
+ break;
- case 'cid':
- $headers['Content-ID'] = '<' . $value . '>';
- break;
+ case 'cid':
+ $headers['Content-ID'] = '<' . $value . '>';
+ break;
- case 'disposition':
- $c_disp['disp'] = $value;
- break;
+ case 'disposition':
+ $c_disp['disp'] = $value;
+ break;
- case 'dfilename':
- $c_disp['filename'] = $value;
- $c_type['name'] = $value;
- break;
+ case 'dfilename':
+ $c_disp['filename'] = $value;
+ $c_type['name'] = $value;
+ break;
- case 'description':
- $headers['Content-Description'] = $value;
- break;
+ case 'description':
+ $headers['Content-Description'] = $value;
+ break;
- case 'charset':
- $c_type['charset'] = $value;
- $c_disp['charset'] = $value;
- break;
+ case 'charset':
+ $c_type['charset'] = $value;
+ $c_disp['charset'] = $value;
+ break;
- case 'language':
- $c_type['language'] = $value;
- $c_disp['language'] = $value;
- break;
+ case 'language':
+ $c_type['language'] = $value;
+ $c_disp['language'] = $value;
+ break;
- case 'location':
- $headers['Content-Location'] = $value;
- break;
+ case 'location':
+ $headers['Content-Location'] = $value;
+ break;
- case 'body_file':
- $this->_body_file = $value;
- break;
- }
- }
+ case 'body_file':
+ $this->_body_file = $value;
+ break;
+ }
+ }
- // Default content-type
- if (empty($c_type['type'])) {
- $c_type['type'] = 'text/plain';
- }
+ // Default content-type
+ if (empty($c_type['type'])) {
+ $c_type['type'] = 'text/plain';
+ }
- // Content-Type
- if (!empty($c_type['type'])) {
- $headers['Content-Type'] = $c_type['type'];
- if (!empty($c_type['charset'])) {
- $charset = "charset={$c_type['charset']}";
- // place charset parameter in the same line, if possible
- if ((strlen($headers['Content-Type']) + strlen($charset) + 16) <= 76) {
- $headers['Content-Type'] .= '; ';
- } else {
- $headers['Content-Type'] .= ';' . $this->_eol . ' ';
- }
- $headers['Content-Type'] .= $charset;
- }
- if (!empty($c_type['name'])) {
- $headers['Content-Type'] .= ';' . $this->_eol;
- $headers['Content-Type'] .= $this->_buildHeaderParam(
- 'name', $c_type['name'],
- isset($c_type['charset']) ? $c_type['charset'] : 'US-ASCII',
- isset($c_type['language']) ? $c_type['language'] : null,
- isset($params['name_encoding']) ? $params['name_encoding'] : null
- );
- }
- }
+ // Content-Type
+ if (!empty($c_type['type'])) {
+ $headers['Content-Type'] = $c_type['type'];
+ if (!empty($c_type['charset'])) {
+ $charset = "charset={$c_type['charset']}";
+ // place charset parameter in the same line, if possible
+ if ((strlen($headers['Content-Type']) + strlen($charset) + 16) <= 76) {
+ $headers['Content-Type'] .= '; ';
+ } else {
+ $headers['Content-Type'] .= ';' . $this->_eol . ' ';
+ }
+ $headers['Content-Type'] .= $charset;
+ }
+ if (!empty($c_type['name'])) {
+ $headers['Content-Type'] .= ';' . $this->_eol;
+ $headers['Content-Type'] .= $this->_buildHeaderParam(
+ 'name', $c_type['name'],
+ $c_type['charset'] ?? 'US-ASCII',
+ $c_type['language'] ?? null,
+ $params['name_encoding'] ?? null,
+ );
+ }
+ }
- // Content-Disposition
- if (!empty($c_disp['disp'])) {
- $headers['Content-Disposition'] = $c_disp['disp'];
- if (!empty($c_disp['filename'])) {
- $headers['Content-Disposition'] .= ';' . $this->_eol;
- $headers['Content-Disposition'] .= $this->_buildHeaderParam(
- 'filename', $c_disp['filename'],
- isset($c_disp['charset']) ? $c_disp['charset'] : 'US-ASCII',
- isset($c_disp['language']) ? $c_disp['language'] : null,
- isset($params['filename_encoding']) ? $params['filename_encoding'] : null
- );
- }
- }
+ // Content-Disposition
+ if (!empty($c_disp['disp'])) {
+ $headers['Content-Disposition'] = $c_disp['disp'];
+ if (!empty($c_disp['filename'])) {
+ $headers['Content-Disposition'] .= ';' . $this->_eol;
+ $headers['Content-Disposition'] .= $this->_buildHeaderParam(
+ 'filename', $c_disp['filename'],
+ $c_disp['charset'] ?? 'US-ASCII',
+ $c_disp['language'] ?? null,
+ $params['filename_encoding'] ?? null,
+ );
+ }
+ }
- if (!empty($headers['Content-Description'])) {
- $headers['Content-Description'] = $this->encodeHeader(
- 'Content-Description', $headers['Content-Description'],
- isset($c_type['charset']) ? $c_type['charset'] : 'US-ASCII',
- isset($params['name_encoding']) ? $params['name_encoding'] : 'quoted-printable',
- $this->_eol
- );
- }
+ if (!empty($headers['Content-Description'])) {
+ $headers['Content-Description'] = $this->encodeHeader(
+ 'Content-Description', $headers['Content-Description'],
+ $c_type['charset'] ?? 'US-ASCII',
+ $params['name_encoding'] ?? 'quoted-printable',
+ $this->_eol,
+ );
+ }
- // Default encoding
- if (!isset($this->_encoding)) {
- $this->_encoding = '7bit';
- }
+ // Default encoding
+ if (!isset($this->_encoding)) {
+ $this->_encoding = '7bit';
+ }
- // Assign stuff to member variables
- $this->_encoded = array();
- $this->_headers = $headers;
- $this->_body = $body;
- }
+ // Assign stuff to member variables
+ $this->_encoded = [];
+ $this->_headers = $headers;
+ $this->_body = $body;
+ }
- /**
- * Encodes and returns the email. Also stores
- * it in the encoded member variable
- *
- * @param string $boundary Pre-defined boundary string
- *
- * @return An associative array containing two elements,
- * body and headers. The headers element is itself
- * an indexed array. On error returns PEAR error object.
- * @access public
- */
- function encode($boundary=null)
- {
- $encoded =& $this->_encoded;
+ /**
+ * Encodes and returns the email. Also stores
+ * it in the encoded member variable
+ *
+ * @param string $boundary Pre-defined boundary string
+ *
+ * @return An associative array containing two elements,
+ * body and headers. The headers element is itself
+ * an indexed array. On error returns PEAR error object.
+ * @access public
+ */
+ function encode($boundary=null)
+ {
+ $encoded =& $this->_encoded;
- if (count($this->_subparts)) {
- $boundary = $boundary ? $boundary : '=_' . md5(rand() . microtime());
- $eol = $this->_eol;
+ if (count($this->_subparts)) {
+ $boundary = $boundary ? $boundary : '=_' . md5(rand() . microtime());
+ $eol = $this->_eol;
- $this->_headers['Content-Type'] .= ";$eol boundary=\"$boundary\"";
+ $this->_headers['Content-Type'] .= ";$eol boundary=\"$boundary\"";
- $encoded['body'] = '';
+ $encoded['body'] = '';
- for ($i = 0; $i < count($this->_subparts); $i++) {
- $encoded['body'] .= '--' . $boundary . $eol;
- $tmp = $this->_subparts[$i]->encode();
- if (PEAR::isError($tmp)) {
- return $tmp;
- }
- foreach ($tmp['headers'] as $key => $value) {
- $encoded['body'] .= $key . ': ' . $value . $eol;
- }
- $encoded['body'] .= $eol . $tmp['body'] . $eol;
- }
+ for ($i = 0; $i < count($this->_subparts); $i++) {
+ $encoded['body'] .= '--' . $boundary . $eol;
+ $tmp = $this->_subparts[$i]->encode();
+ if (PEAR::isError($tmp)) {
+ return $tmp;
+ }
+ foreach ($tmp['headers'] as $key => $value) {
+ $encoded['body'] .= $key . ': ' . $value . $eol;
+ }
+ $encoded['body'] .= $eol . $tmp['body'] . $eol;
+ }
- $encoded['body'] .= '--' . $boundary . '--' . $eol;
+ $encoded['body'] .= '--' . $boundary . '--' . $eol;
- } else if ($this->_body) {
- $encoded['body'] = $this->_getEncodedData($this->_body, $this->_encoding);
- } else if ($this->_body_file) {
- // Temporarily reset magic_quotes_runtime for file reads and writes
- if ($magic_quote_setting = get_magic_quotes_runtime()) {
- @ini_set('magic_quotes_runtime', 0);
- }
- $body = $this->_getEncodedDataFromFile($this->_body_file, $this->_encoding);
- if ($magic_quote_setting) {
- @ini_set('magic_quotes_runtime', $magic_quote_setting);
- }
+ } else if ($this->_body) {
+ $encoded['body'] = $this->_getEncodedData($this->_body, $this->_encoding);
+ } else if ($this->_body_file) {
+ // Temporarily reset magic_quotes_runtime for file reads and writes
+ if ($magic_quote_setting = get_magic_quotes_runtime()) {
+ @ini_set('magic_quotes_runtime', 0);
+ }
+ $body = $this->_getEncodedDataFromFile($this->_body_file, $this->_encoding);
+ if ($magic_quote_setting) {
+ @ini_set('magic_quotes_runtime', $magic_quote_setting);
+ }
- if (PEAR::isError($body)) {
- return $body;
- }
- $encoded['body'] = $body;
- } else {
- $encoded['body'] = '';
- }
+ if (PEAR::isError($body)) {
+ return $body;
+ }
+ $encoded['body'] = $body;
+ } else {
+ $encoded['body'] = '';
+ }
- // Add headers to $encoded
- $encoded['headers'] =& $this->_headers;
+ // Add headers to $encoded
+ $encoded['headers'] =& $this->_headers;
- return $encoded;
- }
+ return $encoded;
+ }
- /**
- * Encodes and saves the email into file. File must exist.
- * Data will be appended to the file.
- *
- * @param string $filename Output file location
- * @param string $boundary Pre-defined boundary string
- * @param boolean $skip_head True if you don't want to save headers
- *
- * @return array An associative array containing message headers
- * or PEAR error object
- * @access public
- * @since 1.6.0
- */
- function encodeToFile($filename, $boundary=null, $skip_head=false)
- {
- if (file_exists($filename) && !is_writable($filename)) {
- $err = PEAR::raiseError('File is not writeable: ' . $filename);
- return $err;
- }
+ /**
+ * Encodes and saves the email into file. File must exist.
+ * Data will be appended to the file.
+ *
+ * @param string $filename Output file location
+ * @param string $boundary Pre-defined boundary string
+ * @param boolean $skip_head True if you don't want to save headers
+ *
+ * @return array An associative array containing message headers
+ * or PEAR error object
+ * @access public
+ * @since 1.6.0
+ */
+ function encodeToFile($filename, $boundary=null, $skip_head=false)
+ {
+ if (file_exists($filename) && !is_writable($filename)) {
+ $err = PEAR::raiseError('File is not writeable: ' . $filename);
+ return $err;
+ }
- if (!($fh = fopen($filename, 'ab'))) {
- $err = PEAR::raiseError('Unable to open file: ' . $filename);
- return $err;
- }
+ if (!($fh = fopen($filename, 'ab'))) {
+ $err = PEAR::raiseError('Unable to open file: ' . $filename);
+ return $err;
+ }
- // Temporarily reset magic_quotes_runtime for file reads and writes
- if ($magic_quote_setting = get_magic_quotes_runtime()) {
- @ini_set('magic_quotes_runtime', 0);
- }
+ // Temporarily reset magic_quotes_runtime for file reads and writes
+ if ($magic_quote_setting = get_magic_quotes_runtime()) {
+ @ini_set('magic_quotes_runtime', 0);
+ }
- $res = $this->_encodePartToFile($fh, $boundary, $skip_head);
+ $res = $this->_encodePartToFile($fh, $boundary, $skip_head);
- fclose($fh);
+ fclose($fh);
- if ($magic_quote_setting) {
- @ini_set('magic_quotes_runtime', $magic_quote_setting);
- }
+ if ($magic_quote_setting) {
+ @ini_set('magic_quotes_runtime', $magic_quote_setting);
+ }
- return PEAR::isError($res) ? $res : $this->_headers;
- }
+ return PEAR::isError($res) ? $res : $this->_headers;
+ }
- /**
- * Encodes given email part into file
- *
- * @param string $fh Output file handle
- * @param string $boundary Pre-defined boundary string
- * @param boolean $skip_head True if you don't want to save headers
- *
- * @return array True on sucess or PEAR error object
- * @access private
- */
- function _encodePartToFile($fh, $boundary=null, $skip_head=false)
- {
- $eol = $this->_eol;
+ /**
+ * Encodes given email part into file
+ *
+ * @param string $fh Output file handle
+ * @param string $boundary Pre-defined boundary string
+ * @param boolean $skip_head True if you don't want to save headers
+ *
+ * @return array True on sucess or PEAR error object
+ * @access private
+ */
+ function _encodePartToFile($fh, $boundary=null, $skip_head=false)
+ {
+ $eol = $this->_eol;
- if (count($this->_subparts)) {
- $boundary = $boundary ? $boundary : '=_' . md5(rand() . microtime());
- $this->_headers['Content-Type'] .= ";$eol boundary=\"$boundary\"";
- }
+ if (count($this->_subparts)) {
+ $boundary = $boundary ? $boundary : '=_' . md5(rand() . microtime());
+ $this->_headers['Content-Type'] .= ";$eol boundary=\"$boundary\"";
+ }
- if (!$skip_head) {
- foreach ($this->_headers as $key => $value) {
- fwrite($fh, $key . ': ' . $value . $eol);
- }
- $f_eol = $eol;
- } else {
- $f_eol = '';
- }
+ if (!$skip_head) {
+ foreach ($this->_headers as $key => $value) {
+ fwrite($fh, $key . ': ' . $value . $eol);
+ }
+ $f_eol = $eol;
+ } else {
+ $f_eol = '';
+ }
- if (count($this->_subparts)) {
- for ($i = 0; $i < count($this->_subparts); $i++) {
- fwrite($fh, $f_eol . '--' . $boundary . $eol);
- $res = $this->_subparts[$i]->_encodePartToFile($fh);
- if (PEAR::isError($res)) {
- return $res;
- }
- $f_eol = $eol;
- }
+ if (count($this->_subparts)) {
+ for ($i = 0; $i < count($this->_subparts); $i++) {
+ fwrite($fh, $f_eol . '--' . $boundary . $eol);
+ $res = $this->_subparts[$i]->_encodePartToFile($fh);
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ $f_eol = $eol;
+ }
- fwrite($fh, $eol . '--' . $boundary . '--' . $eol);
+ fwrite($fh, $eol . '--' . $boundary . '--' . $eol);
- } else if ($this->_body) {
- fwrite($fh, $f_eol . $this->_getEncodedData($this->_body, $this->_encoding));
- } else if ($this->_body_file) {
- fwrite($fh, $f_eol);
- $res = $this->_getEncodedDataFromFile(
- $this->_body_file, $this->_encoding, $fh
- );
- if (PEAR::isError($res)) {
- return $res;
- }
- }
+ } else if ($this->_body) {
+ fwrite($fh, $f_eol . $this->_getEncodedData($this->_body, $this->_encoding));
+ } else if ($this->_body_file) {
+ fwrite($fh, $f_eol);
+ $res = $this->_getEncodedDataFromFile(
+ $this->_body_file, $this->_encoding, $fh,
+ );
+ if (PEAR::isError($res)) {
+ return $res;
+ }
+ }
- return true;
- }
+ return true;
+ }
- /**
- * Adds a subpart to current mime part and returns
- * a reference to it
- *
- * @param string $body The body of the subpart, if any.
- * @param array $params The parameters for the subpart, same
- * as the $params argument for constructor.
- *
- * @return Mail_mimePart A reference to the part you just added. It is
- * crucial if using multipart/* in your subparts that
- * you use =& in your script when calling this function,
- * otherwise you will not be able to add further subparts.
- * @access public
- */
- function &addSubpart($body, $params)
- {
- $this->_subparts[] = new Mail_mimePart($body, $params);
- return $this->_subparts[count($this->_subparts) - 1];
- }
+ /**
+ * Adds a subpart to current mime part and returns
+ * a reference to it
+ *
+ * @param string $body The body of the subpart, if any.
+ * @param array $params The parameters for the subpart, same
+ * as the $params argument for constructor.
+ *
+ * @return Mail_mimePart A reference to the part you just added. It is
+ * crucial if using multipart/* in your subparts that
+ * you use =& in your script when calling this function,
+ * otherwise you will not be able to add further subparts.
+ * @access public
+ */
+ function &addSubpart($body, $params)
+ {
+ $this->_subparts[] = new Mail_mimePart($body, $params);
+ return $this->_subparts[count($this->_subparts) - 1];
+ }
- /**
- * Returns encoded data based upon encoding passed to it
- *
- * @param string $data The data to encode.
- * @param string $encoding The encoding type to use, 7bit, base64,
- * or quoted-printable.
- *
- * @return string
- * @access private
- */
- function _getEncodedData($data, $encoding)
- {
- switch ($encoding) {
- case 'quoted-printable':
- return $this->_quotedPrintableEncode($data);
- break;
+ /**
+ * Returns encoded data based upon encoding passed to it
+ *
+ * @param string $data The data to encode.
+ * @param string $encoding The encoding type to use, 7bit, base64,
+ * or quoted-printable.
+ *
+ * @return string
+ * @access private
+ */
+ function _getEncodedData($data, $encoding)
+ {
+ switch ($encoding) {
+ case 'quoted-printable':
+ return $this->_quotedPrintableEncode($data);
+ break;
- case 'base64':
- return rtrim(chunk_split(base64_encode($data), 76, $this->_eol));
- break;
+ case 'base64':
+ return rtrim(chunk_split(base64_encode($data), 76, $this->_eol));
+ break;
- case '8bit':
- case '7bit':
- default:
- return $data;
- }
- }
+ case '8bit':
+ case '7bit':
+ default:
+ return $data;
+ }
+ }
- /**
- * Returns encoded data based upon encoding passed to it
- *
- * @param string $filename Data file location
- * @param string $encoding The encoding type to use, 7bit, base64,
- * or quoted-printable.
- * @param resource $fh Output file handle. If set, data will be
- * stored into it instead of returning it
- *
- * @return string Encoded data or PEAR error object
- * @access private
- */
- function _getEncodedDataFromFile($filename, $encoding, $fh=null)
- {
- if (!is_readable($filename)) {
- $err = PEAR::raiseError('Unable to read file: ' . $filename);
- return $err;
- }
+ /**
+ * Returns encoded data based upon encoding passed to it
+ *
+ * @param string $filename Data file location
+ * @param string $encoding The encoding type to use, 7bit, base64,
+ * or quoted-printable.
+ * @param resource $fh Output file handle. If set, data will be
+ * stored into it instead of returning it
+ *
+ * @return string Encoded data or PEAR error object
+ * @access private
+ */
+ function _getEncodedDataFromFile($filename, $encoding, $fh=null)
+ {
+ if (!is_readable($filename)) {
+ $err = PEAR::raiseError('Unable to read file: ' . $filename);
+ return $err;
+ }
- if (!($fd = fopen($filename, 'rb'))) {
- $err = PEAR::raiseError('Could not open file: ' . $filename);
- return $err;
- }
+ if (!($fd = fopen($filename, 'rb'))) {
+ $err = PEAR::raiseError('Could not open file: ' . $filename);
+ return $err;
+ }
- $data = '';
+ $data = '';
- switch ($encoding) {
- case 'quoted-printable':
- while (!feof($fd)) {
- $buffer = $this->_quotedPrintableEncode(fgets($fd));
- if ($fh) {
- fwrite($fh, $buffer);
- } else {
- $data .= $buffer;
- }
- }
- break;
+ switch ($encoding) {
+ case 'quoted-printable':
+ while (!feof($fd)) {
+ $buffer = $this->_quotedPrintableEncode(fgets($fd));
+ if ($fh) {
+ fwrite($fh, $buffer);
+ } else {
+ $data .= $buffer;
+ }
+ }
+ break;
- case 'base64':
- while (!feof($fd)) {
- // Should read in a multiple of 57 bytes so that
- // the output is 76 bytes per line. Don't use big chunks
- // because base64 encoding is memory expensive
- $buffer = fread($fd, 57 * 9198); // ca. 0.5 MB
- $buffer = base64_encode($buffer);
- $buffer = chunk_split($buffer, 76, $this->_eol);
- if (feof($fd)) {
- $buffer = rtrim($buffer);
- }
+ case 'base64':
+ while (!feof($fd)) {
+ // Should read in a multiple of 57 bytes so that
+ // the output is 76 bytes per line. Don't use big chunks
+ // because base64 encoding is memory expensive
+ $buffer = fread($fd, 57 * 9198); // ca. 0.5 MB
+ $buffer = base64_encode($buffer);
+ $buffer = chunk_split($buffer, 76, $this->_eol);
+ if (feof($fd)) {
+ $buffer = rtrim($buffer);
+ }
- if ($fh) {
- fwrite($fh, $buffer);
- } else {
- $data .= $buffer;
- }
- }
- break;
+ if ($fh) {
+ fwrite($fh, $buffer);
+ } else {
+ $data .= $buffer;
+ }
+ }
+ break;
- case '8bit':
- case '7bit':
- default:
- while (!feof($fd)) {
- $buffer = fread($fd, 1048576); // 1 MB
- if ($fh) {
- fwrite($fh, $buffer);
- } else {
- $data .= $buffer;
- }
- }
- }
+ case '8bit':
+ case '7bit':
+ default:
+ while (!feof($fd)) {
+ $buffer = fread($fd, 1048576); // 1 MB
+ if ($fh) {
+ fwrite($fh, $buffer);
+ } else {
+ $data .= $buffer;
+ }
+ }
+ }
- fclose($fd);
+ fclose($fd);
- if (!$fh) {
- return $data;
- }
- }
+ if (!$fh) {
+ return $data;
+ }
+ }
- /**
- * Encodes data to quoted-printable standard.
- *
- * @param string $input The data to encode
- * @param int $line_max Optional max line length. Should
- * not be more than 76 chars
- *
- * @return string Encoded data
- *
- * @access private
- */
- function _quotedPrintableEncode($input , $line_max = 76)
- {
- $eol = $this->_eol;
- /*
- // imap_8bit() is extremely fast, but doesn't handle properly some characters
- if (function_exists('imap_8bit') && $line_max == 76) {
- $input = preg_replace('/\r?\n/', "\r\n", $input);
- $input = imap_8bit($input);
- if ($eol != "\r\n") {
- $input = str_replace("\r\n", $eol, $input);
- }
- return $input;
- }
- */
- $lines = preg_split("/\r?\n/", $input);
- $escape = '=';
- $output = '';
+ /**
+ * Encodes data to quoted-printable standard.
+ *
+ * @param string $input The data to encode
+ * @param int $line_max Optional max line length. Should
+ * not be more than 76 chars
+ *
+ * @return string Encoded data
+ *
+ * @access private
+ */
+ function _quotedPrintableEncode($input , $line_max = 76)
+ {
+ $eol = $this->_eol;
+ /*
+ // imap_8bit() is extremely fast, but doesn't handle properly some characters
+ if (function_exists('imap_8bit') && $line_max == 76) {
+ $input = preg_replace('/\r?\n/', "\r\n", $input);
+ $input = imap_8bit($input);
+ if ($eol != "\r\n") {
+ $input = str_replace("\r\n", $eol, $input);
+ }
+ return $input;
+ }
+ */
+ $lines = preg_split("/\r?\n/", $input);
+ $escape = '=';
+ $output = '';
- while (list($idx, $line) = each($lines)) {
- $newline = '';
- $i = 0;
+ while (list($idx, $line) = each($lines)) {
+ $newline = '';
+ $i = 0;
- while (isset($line[$i])) {
- $char = $line[$i];
- $dec = ord($char);
- $i++;
+ while (isset($line[$i])) {
+ $char = $line[$i];
+ $dec = ord($char);
+ $i++;
- if (($dec == 32) && (!isset($line[$i]))) {
- // convert space at eol only
- $char = '=20';
- } elseif ($dec == 9 && isset($line[$i])) {
- ; // Do nothing if a TAB is not on eol
- } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) {
- $char = $escape . sprintf('%02X', $dec);
- } elseif (($dec == 46) && (($newline == '')
- || ((strlen($newline) + strlen("=2E")) >= $line_max))
- ) {
- // Bug #9722: convert full-stop at bol,
- // some Windows servers need this, won't break anything (cipri)
- // Bug #11731: full-stop at bol also needs to be encoded
- // if this line would push us over the line_max limit.
- $char = '=2E';
- }
+ if (($dec == 32) && (!isset($line[$i]))) {
+ // convert space at eol only
+ $char = '=20';
+ } elseif ($dec == 9 && isset($line[$i])) {
+ ; // Do nothing if a TAB is not on eol
+ } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) {
+ $char = $escape . sprintf('%02X', $dec);
+ } elseif (($dec == 46) && (($newline == '')
+ || ((strlen($newline) + strlen("=2E")) >= $line_max))
+ ) {
+ // Bug #9722: convert full-stop at bol,
+ // some Windows servers need this, won't break anything (cipri)
+ // Bug #11731: full-stop at bol also needs to be encoded
+ // if this line would push us over the line_max limit.
+ $char = '=2E';
+ }
- // Note, when changing this line, also change the ($dec == 46)
- // check line, as it mimics this line due to Bug #11731
- // EOL is not counted
- if ((strlen($newline) + strlen($char)) >= $line_max) {
- // soft line break; " =\r\n" is okay
- $output .= $newline . $escape . $eol;
- $newline = '';
- }
- $newline .= $char;
- } // end of for
- $output .= $newline . $eol;
- unset($lines[$idx]);
- }
- // Don't want last crlf
- $output = substr($output, 0, -1 * strlen($eol));
- return $output;
- }
+ // Note, when changing this line, also change the ($dec == 46)
+ // check line, as it mimics this line due to Bug #11731
+ // EOL is not counted
+ if ((strlen($newline) + strlen($char)) >= $line_max) {
+ // soft line break; " =\r\n" is okay
+ $output .= $newline . $escape . $eol;
+ $newline = '';
+ }
+ $newline .= $char;
+ } // end of for
+ $output .= $newline . $eol;
+ unset($lines[$idx]);
+ }
+ // Don't want last crlf
+ $output = substr($output, 0, -1 * strlen($eol));
+ return $output;
+ }
- /**
- * Encodes the paramater of a header.
- *
- * @param string $name The name of the header-parameter
- * @param string $value The value of the paramter
- * @param string $charset The characterset of $value
- * @param string $language The language used in $value
- * @param string $encoding Parameter encoding. If not set, parameter value
- * is encoded according to RFC2231
- * @param int $maxLength The maximum length of a line. Defauls to 75
- *
- * @return string
- *
- * @access private
- */
- function _buildHeaderParam($name, $value, $charset=null, $language=null,
- $encoding=null, $maxLength=75
- ) {
- // RFC 2045:
- // value needs encoding if contains non-ASCII chars or is longer than 78 chars
- if (!preg_match('#[^\x20-\x7E]#', $value)) {
- $token_regexp = '#([^\x21,\x23-\x27,\x2A,\x2B,\x2D'
- . ',\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#';
- if (!preg_match($token_regexp, $value)) {
- // token
- if (strlen($name) + strlen($value) + 3 <= $maxLength) {
- return " {$name}={$value}";
- }
- } else {
- // quoted-string
- $quoted = addcslashes($value, '\\"');
- if (strlen($name) + strlen($quoted) + 5 <= $maxLength) {
- return " {$name}=\"{$quoted}\"";
- }
- }
- }
+ /**
+ * Encodes the paramater of a header.
+ *
+ * @param string $name The name of the header-parameter
+ * @param string $value The value of the paramter
+ * @param string $charset The characterset of $value
+ * @param string $language The language used in $value
+ * @param string $encoding Parameter encoding. If not set, parameter value
+ * is encoded according to RFC2231
+ * @param int $maxLength The maximum length of a line. Defauls to 75
+ *
+ * @return string
+ *
+ * @access private
+ */
+ function _buildHeaderParam($name, $value, $charset=null, $language=null,
+ $encoding=null, $maxLength=75,
+ ) {
+ // RFC 2045:
+ // value needs encoding if contains non-ASCII chars or is longer than 78 chars
+ if (!preg_match('#[^\x20-\x7E]#', $value)) {
+ $token_regexp = '#([^\x21,\x23-\x27,\x2A,\x2B,\x2D'
+ . ',\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#';
+ if (!preg_match($token_regexp, $value)) {
+ // token
+ if (strlen($name) + strlen($value) + 3 <= $maxLength) {
+ return " {$name}={$value}";
+ }
+ } else {
+ // quoted-string
+ $quoted = addcslashes($value, '\\"');
+ if (strlen($name) + strlen($quoted) + 5 <= $maxLength) {
+ return " {$name}=\"{$quoted}\"";
+ }
+ }
+ }
- // RFC2047: use quoted-printable/base64 encoding
- if ($encoding == 'quoted-printable' || $encoding == 'base64') {
- return $this->_buildRFC2047Param($name, $value, $charset, $encoding);
- }
+ // RFC2047: use quoted-printable/base64 encoding
+ if ($encoding == 'quoted-printable' || $encoding == 'base64') {
+ return $this->_buildRFC2047Param($name, $value, $charset, $encoding);
+ }
- // RFC2231:
- $encValue = preg_replace_callback(
- '/([^\x21,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])/',
- array($this, '_encodeReplaceCallback'), $value
- );
- $value = "$charset'$language'$encValue";
+ // RFC2231:
+ $encValue = preg_replace_callback(
+ '/([^\x21,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])/',
+ [$this, '_encodeReplaceCallback'], $value,
+ );
+ $value = "$charset'$language'$encValue";
- $header = " {$name}*={$value}";
- if (strlen($header) <= $maxLength) {
- return $header;
- }
+ $header = " {$name}*={$value}";
+ if (strlen($header) <= $maxLength) {
+ return $header;
+ }
- $preLength = strlen(" {$name}*0*=");
- $maxLength = max(16, $maxLength - $preLength - 3);
- $maxLengthReg = "|(.{0,$maxLength}[^\%][^\%])|";
+ $preLength = strlen(" {$name}*0*=");
+ $maxLength = max(16, $maxLength - $preLength - 3);
+ $maxLengthReg = "|(.{0,$maxLength}[^\%][^\%])|";
- $headers = array();
- $headCount = 0;
- while ($value) {
- $matches = array();
- $found = preg_match($maxLengthReg, $value, $matches);
- if ($found) {
- $headers[] = " {$name}*{$headCount}*={$matches[0]}";
- $value = substr($value, strlen($matches[0]));
- } else {
- $headers[] = " {$name}*{$headCount}*={$value}";
- $value = '';
- }
- $headCount++;
- }
+ $headers = [];
+ $headCount = 0;
+ while ($value) {
+ $matches = [];
+ $found = preg_match($maxLengthReg, $value, $matches);
+ if ($found) {
+ $headers[] = " {$name}*{$headCount}*={$matches[0]}";
+ $value = substr($value, strlen($matches[0]));
+ } else {
+ $headers[] = " {$name}*{$headCount}*={$value}";
+ $value = '';
+ }
+ $headCount++;
+ }
- $headers = implode(';' . $this->_eol, $headers);
- return $headers;
- }
+ $headers = implode(';' . $this->_eol, $headers);
+ return $headers;
+ }
- /**
- * Encodes header parameter as per RFC2047 if needed
- *
- * @param string $name The parameter name
- * @param string $value The parameter value
- * @param string $charset The parameter charset
- * @param string $encoding Encoding type (quoted-printable or base64)
- * @param int $maxLength Encoded parameter max length. Default: 76
- *
- * @return string Parameter line
- * @access private
- */
- function _buildRFC2047Param($name, $value, $charset,
- $encoding='quoted-printable', $maxLength=76
- ) {
- // WARNING: RFC 2047 says: "An 'encoded-word' MUST NOT be used in
- // parameter of a MIME Content-Type or Content-Disposition field",
- // but... it's supported by many clients/servers
- $quoted = '';
+ /**
+ * Encodes header parameter as per RFC2047 if needed
+ *
+ * @param string $name The parameter name
+ * @param string $value The parameter value
+ * @param string $charset The parameter charset
+ * @param string $encoding Encoding type (quoted-printable or base64)
+ * @param int $maxLength Encoded parameter max length. Default: 76
+ *
+ * @return string Parameter line
+ * @access private
+ */
+ function _buildRFC2047Param($name, $value, $charset,
+ $encoding='quoted-printable', $maxLength=76,
+ ) {
+ // WARNING: RFC 2047 says: "An 'encoded-word' MUST NOT be used in
+ // parameter of a MIME Content-Type or Content-Disposition field",
+ // but... it's supported by many clients/servers
+ $quoted = '';
- if ($encoding == 'base64') {
- $value = base64_encode($value);
- $prefix = '=?' . $charset . '?B?';
- $suffix = '?=';
+ if ($encoding == 'base64') {
+ $value = base64_encode($value);
+ $prefix = '=?' . $charset . '?B?';
+ $suffix = '?=';
- // 2 x SPACE, 2 x '"', '=', ';'
- $add_len = strlen($prefix . $suffix) + strlen($name) + 6;
- $len = $add_len + strlen($value);
+ // 2 x SPACE, 2 x '"', '=', ';'
+ $add_len = strlen($prefix . $suffix) + strlen($name) + 6;
+ $len = $add_len + strlen($value);
- while ($len > $maxLength) {
- // We can cut base64-encoded string every 4 characters
- $real_len = floor(($maxLength - $add_len) / 4) * 4;
- $_quote = substr($value, 0, $real_len);
- $value = substr($value, $real_len);
+ while ($len > $maxLength) {
+ // We can cut base64-encoded string every 4 characters
+ $real_len = floor(($maxLength - $add_len) / 4) * 4;
+ $_quote = substr($value, 0, $real_len);
+ $value = substr($value, $real_len);
- $quoted .= $prefix . $_quote . $suffix . $this->_eol . ' ';
- $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'
- $len = strlen($value) + $add_len;
- }
- $quoted .= $prefix . $value . $suffix;
+ $quoted .= $prefix . $_quote . $suffix . $this->_eol . ' ';
+ $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'
+ $len = strlen($value) + $add_len;
+ }
+ $quoted .= $prefix . $value . $suffix;
- } else {
- // quoted-printable
- $value = $this->encodeQP($value);
- $prefix = '=?' . $charset . '?Q?';
- $suffix = '?=';
+ } else {
+ // quoted-printable
+ $value = $this->encodeQP($value);
+ $prefix = '=?' . $charset . '?Q?';
+ $suffix = '?=';
- // 2 x SPACE, 2 x '"', '=', ';'
- $add_len = strlen($prefix . $suffix) + strlen($name) + 6;
- $len = $add_len + strlen($value);
+ // 2 x SPACE, 2 x '"', '=', ';'
+ $add_len = strlen($prefix . $suffix) + strlen($name) + 6;
+ $len = $add_len + strlen($value);
- while ($len > $maxLength) {
- $length = $maxLength - $add_len;
- // don't break any encoded letters
- if (preg_match("/^(.{0,$length}[^\=][^\=])/", $value, $matches)) {
- $_quote = $matches[1];
- }
+ while ($len > $maxLength) {
+ $length = $maxLength - $add_len;
+ // don't break any encoded letters
+ if (preg_match("/^(.{0,$length}[^\=][^\=])/", $value, $matches)) {
+ $_quote = $matches[1];
+ }
- $quoted .= $prefix . $_quote . $suffix . $this->_eol . ' ';
- $value = substr($value, strlen($_quote));
- $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'
- $len = strlen($value) + $add_len;
- }
+ $quoted .= $prefix . $_quote . $suffix . $this->_eol . ' ';
+ $value = substr($value, strlen($_quote));
+ $add_len = strlen($prefix . $suffix) + 4; // 2 x SPACE, '"', ';'
+ $len = strlen($value) + $add_len;
+ }
- $quoted .= $prefix . $value . $suffix;
- }
+ $quoted .= $prefix . $value . $suffix;
+ }
- return " {$name}=\"{$quoted}\"";
- }
+ return " {$name}=\"{$quoted}\"";
+ }
- /**
- * Encodes a header as per RFC2047
- *
- * @param string $name The header name
- * @param string $value The header data to encode
- * @param string $charset Character set name
- * @param string $encoding Encoding name (base64 or quoted-printable)
- * @param string $eol End-of-line sequence. Default: "\r\n"
- *
- * @return string Encoded header data (without a name)
- * @access public
- * @since 1.6.1
- */
- function encodeHeader($name, $value, $charset='ISO-8859-1',
- $encoding='quoted-printable', $eol="\r\n"
- ) {
- // Structured headers
- $comma_headers = array(
- 'from', 'to', 'cc', 'bcc', 'sender', 'reply-to',
- 'resent-from', 'resent-to', 'resent-cc', 'resent-bcc',
- 'resent-sender', 'resent-reply-to',
- 'return-receipt-to', 'disposition-notification-to',
- );
- $other_headers = array(
- 'references', 'in-reply-to', 'message-id', 'resent-message-id',
- );
+ /**
+ * Encodes a header as per RFC2047
+ *
+ * @param string $name The header name
+ * @param string $value The header data to encode
+ * @param string $charset Character set name
+ * @param string $encoding Encoding name (base64 or quoted-printable)
+ * @param string $eol End-of-line sequence. Default: "\r\n"
+ *
+ * @return string Encoded header data (without a name)
+ * @access public
+ * @since 1.6.1
+ */
+ function encodeHeader($name, $value, $charset='ISO-8859-1',
+ $encoding='quoted-printable', $eol="\r\n",
+ ) {
+ // Structured headers
+ $comma_headers = [
+ 'from', 'to', 'cc', 'bcc', 'sender', 'reply-to',
+ 'resent-from', 'resent-to', 'resent-cc', 'resent-bcc',
+ 'resent-sender', 'resent-reply-to',
+ 'return-receipt-to', 'disposition-notification-to',
+ ];
+ $other_headers = [
+ 'references', 'in-reply-to', 'message-id', 'resent-message-id',
+ ];
- $name = strtolower($name);
+ $name = strtolower($name);
- if (in_array($name, $comma_headers)) {
- $separator = ',';
- } else if (in_array($name, $other_headers)) {
- $separator = ' ';
- }
+ if (in_array($name, $comma_headers)) {
+ $separator = ',';
+ } else if (in_array($name, $other_headers)) {
+ $separator = ' ';
+ }
- if (!$charset) {
- $charset = 'ISO-8859-1';
- }
+ if (!$charset) {
+ $charset = 'ISO-8859-1';
+ }
- // Structured header (make sure addr-spec inside is not encoded)
- if (!empty($separator)) {
- $parts = Mail_mimePart::_explodeQuotedString($separator, $value);
- $value = '';
+ // Structured header (make sure addr-spec inside is not encoded)
+ if (!empty($separator)) {
+ $parts = Mail_mimePart::_explodeQuotedString($separator, $value);
+ $value = '';
- foreach ($parts as $part) {
- $part = preg_replace('/\r?\n[\s\t]*/', $eol . ' ', $part);
- $part = trim($part);
+ foreach ($parts as $part) {
+ $part = preg_replace('/\r?\n[\s\t]*/', $eol . ' ', $part);
+ $part = trim($part);
- if (!$part) {
- continue;
- }
- if ($value) {
- $value .= $separator==',' ? $separator.' ' : ' ';
- } else {
- $value = $name . ': ';
- }
+ if (!$part) {
+ continue;
+ }
+ if ($value) {
+ $value .= $separator==',' ? $separator.' ' : ' ';
+ } else {
+ $value = $name . ': ';
+ }
- // let's find phrase (name) and/or addr-spec
- if (preg_match('/^<\S+@\S+>$/', $part)) {
- $value .= $part;
- } else if (preg_match('/^\S+@\S+$/', $part)) {
- // address without brackets and without name
- $value .= $part;
- } else if (preg_match('/<*\S+@\S+>*$/', $part, $matches)) {
- // address with name (handle name)
- $address = $matches[0];
- $word = str_replace($address, '', $part);
- $word = trim($word);
- // check if phrase requires quoting
- if ($word) {
- // non-ASCII: require encoding
- if (preg_match('#([\x80-\xFF]){1}#', $word)) {
- if ($word[0] == '"' && $word[strlen($word)-1] == '"') {
- // de-quote quoted-string, encoding changes
- // string to atom
- $search = array("\\\"", "\\\\");
- $replace = array("\"", "\\");
- $word = str_replace($search, $replace, $word);
- $word = substr($word, 1, -1);
- }
- // find length of last line
- if (($pos = strrpos($value, $eol)) !== false) {
- $last_len = strlen($value) - $pos;
- } else {
- $last_len = strlen($value);
- }
- $word = Mail_mimePart::encodeHeaderValue(
- $word, $charset, $encoding, $last_len, $eol
- );
- } else if (($word[0] != '"' || $word[strlen($word)-1] != '"')
- && preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $word)
- ) {
- // ASCII: quote string if needed
- $word = '"'.addcslashes($word, '\\"').'"';
- }
- }
- $value .= $word.' '.$address;
- } else {
- // addr-spec not found, don't encode (?)
- $value .= $part;
- }
+ // let's find phrase (name) and/or addr-spec
+ if (preg_match('/^<\S+@\S+>$/', $part)) {
+ $value .= $part;
+ } else if (preg_match('/^\S+@\S+$/', $part)) {
+ // address without brackets and without name
+ $value .= $part;
+ } else if (preg_match('/<*\S+@\S+>*$/', $part, $matches)) {
+ // address with name (handle name)
+ $address = $matches[0];
+ $word = str_replace($address, '', $part);
+ $word = trim($word);
+ // check if phrase requires quoting
+ if ($word) {
+ // non-ASCII: require encoding
+ if (preg_match('#([\x80-\xFF]){1}#', $word)) {
+ if ($word[0] == '"' && $word[strlen($word)-1] == '"') {
+ // de-quote quoted-string, encoding changes
+ // string to atom
+ $search = ["\\\"", "\\\\"];
+ $replace = ["\"", "\\"];
+ $word = str_replace($search, $replace, $word);
+ $word = substr($word, 1, -1);
+ }
+ // find length of last line
+ if (($pos = strrpos($value, $eol)) !== false) {
+ $last_len = strlen($value) - $pos;
+ } else {
+ $last_len = strlen($value);
+ }
+ $word = Mail_mimePart::encodeHeaderValue(
+ $word, $charset, $encoding, $last_len, $eol,
+ );
+ } else if (($word[0] != '"' || $word[strlen($word)-1] != '"')
+ && preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $word)
+ ) {
+ // ASCII: quote string if needed
+ $word = '"'.addcslashes($word, '\\"').'"';
+ }
+ }
+ $value .= $word.' '.$address;
+ } else {
+ // addr-spec not found, don't encode (?)
+ $value .= $part;
+ }
- // RFC2822 recommends 78 characters limit, use 76 from RFC2047
- $value = wordwrap($value, 76, $eol . ' ');
- }
+ // RFC2822 recommends 78 characters limit, use 76 from RFC2047
+ $value = wordwrap($value, 76, $eol . ' ');
+ }
- // remove header name prefix (there could be EOL too)
- $value = preg_replace(
- '/^'.$name.':('.preg_quote($eol, '/').')* /', '', $value
- );
+ // remove header name prefix (there could be EOL too)
+ $value = preg_replace(
+ '/^'.$name.':('.preg_quote($eol, '/').')* /', '', $value,
+ );
- } else {
- // Unstructured header
- // non-ASCII: require encoding
- if (preg_match('#([\x80-\xFF]){1}#', $value)) {
- if ($value[0] == '"' && $value[strlen($value)-1] == '"') {
- // de-quote quoted-string, encoding changes
- // string to atom
- $search = array("\\\"", "\\\\");
- $replace = array("\"", "\\");
- $value = str_replace($search, $replace, $value);
- $value = substr($value, 1, -1);
- }
- $value = Mail_mimePart::encodeHeaderValue(
- $value, $charset, $encoding, strlen($name) + 2, $eol
- );
- } else if (strlen($name.': '.$value) > 78) {
- // ASCII: check if header line isn't too long and use folding
- $value = preg_replace('/\r?\n[\s\t]*/', $eol . ' ', $value);
- $tmp = wordwrap($name.': '.$value, 78, $eol . ' ');
- $value = preg_replace('/^'.$name.':\s*/', '', $tmp);
- // hard limit 998 (RFC2822)
- $value = wordwrap($value, 998, $eol . ' ', true);
- }
- }
+ } else {
+ // Unstructured header
+ // non-ASCII: require encoding
+ if (preg_match('#([\x80-\xFF]){1}#', $value)) {
+ if ($value[0] == '"' && $value[strlen($value)-1] == '"') {
+ // de-quote quoted-string, encoding changes
+ // string to atom
+ $search = ["\\\"", "\\\\"];
+ $replace = ["\"", "\\"];
+ $value = str_replace($search, $replace, $value);
+ $value = substr($value, 1, -1);
+ }
+ $value = Mail_mimePart::encodeHeaderValue(
+ $value, $charset, $encoding, strlen($name) + 2, $eol,
+ );
+ } else if (strlen($name.': '.$value) > 78) {
+ // ASCII: check if header line isn't too long and use folding
+ $value = preg_replace('/\r?\n[\s\t]*/', $eol . ' ', $value);
+ $tmp = wordwrap($name.': '.$value, 78, $eol . ' ');
+ $value = preg_replace('/^'.$name.':\s*/', '', $tmp);
+ // hard limit 998 (RFC2822)
+ $value = wordwrap($value, 998, $eol . ' ', true);
+ }
+ }
- return $value;
- }
+ return $value;
+ }
- /**
- * Explode quoted string
- *
- * @param string $delimiter Delimiter expression string for preg_match()
- * @param string $string Input string
- *
- * @return array String tokens array
- * @access private
- */
- function _explodeQuotedString($delimiter, $string)
- {
- $result = array();
- $strlen = strlen($string);
+ /**
+ * Explode quoted string
+ *
+ * @param string $delimiter Delimiter expression string for preg_match()
+ * @param string $string Input string
+ *
+ * @return array String tokens array
+ * @access private
+ */
+ function _explodeQuotedString($delimiter, $string)
+ {
+ $result = [];
+ $strlen = strlen($string);
- for ($q=$p=$i=0; $i < $strlen; $i++) {
- if ($string[$i] == "\""
- && (empty($string[$i-1]) || $string[$i-1] != "\\")
- ) {
- $q = $q ? false : true;
- } else if (!$q && preg_match("/$delimiter/", $string[$i])) {
- $result[] = substr($string, $p, $i - $p);
- $p = $i + 1;
- }
- }
+ for ($q=$p=$i=0; $i < $strlen; $i++) {
+ if ($string[$i] == "\""
+ && (empty($string[$i-1]) || $string[$i-1] != "\\")
+ ) {
+ $q = $q ? false : true;
+ } else if (!$q && preg_match("/$delimiter/", $string[$i])) {
+ $result[] = substr($string, $p, $i - $p);
+ $p = $i + 1;
+ }
+ }
- $result[] = substr($string, $p);
- return $result;
- }
+ $result[] = substr($string, $p);
+ return $result;
+ }
- /**
- * Encodes a header value as per RFC2047
- *
- * @param string $value The header data to encode
- * @param string $charset Character set name
- * @param string $encoding Encoding name (base64 or quoted-printable)
- * @param int $prefix_len Prefix length. Default: 0
- * @param string $eol End-of-line sequence. Default: "\r\n"
- *
- * @return string Encoded header data
- * @access public
- * @since 1.6.1
- */
- function encodeHeaderValue($value, $charset, $encoding, $prefix_len=0, $eol="\r\n")
- {
- // #17311: Use multibyte aware method (requires mbstring extension)
- if ($result = Mail_mimePart::encodeMB($value, $charset, $encoding, $prefix_len, $eol)) {
- return $result;
- }
+ /**
+ * Encodes a header value as per RFC2047
+ *
+ * @param string $value The header data to encode
+ * @param string $charset Character set name
+ * @param string $encoding Encoding name (base64 or quoted-printable)
+ * @param int $prefix_len Prefix length. Default: 0
+ * @param string $eol End-of-line sequence. Default: "\r\n"
+ *
+ * @return string Encoded header data
+ * @access public
+ * @since 1.6.1
+ */
+ function encodeHeaderValue($value, $charset, $encoding, $prefix_len=0, $eol="\r\n")
+ {
+ // #17311: Use multibyte aware method (requires mbstring extension)
+ if ($result = Mail_mimePart::encodeMB($value, $charset, $encoding, $prefix_len, $eol)) {
+ return $result;
+ }
- // Generate the header using the specified params and dynamicly
- // determine the maximum length of such strings.
- // 75 is the value specified in the RFC.
- $encoding = $encoding == 'base64' ? 'B' : 'Q';
- $prefix = '=?' . $charset . '?' . $encoding .'?';
- $suffix = '?=';
- $maxLength = 75 - strlen($prefix . $suffix);
- $maxLength1stLine = $maxLength - $prefix_len;
+ // Generate the header using the specified params and dynamicly
+ // determine the maximum length of such strings.
+ // 75 is the value specified in the RFC.
+ $encoding = $encoding == 'base64' ? 'B' : 'Q';
+ $prefix = '=?' . $charset . '?' . $encoding .'?';
+ $suffix = '?=';
+ $maxLength = 75 - strlen($prefix . $suffix);
+ $maxLength1stLine = $maxLength - $prefix_len;
- if ($encoding == 'B') {
- // Base64 encode the entire string
- $value = base64_encode($value);
+ if ($encoding == 'B') {
+ // Base64 encode the entire string
+ $value = base64_encode($value);
- // We can cut base64 every 4 characters, so the real max
- // we can get must be rounded down.
- $maxLength = $maxLength - ($maxLength % 4);
- $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4);
+ // We can cut base64 every 4 characters, so the real max
+ // we can get must be rounded down.
+ $maxLength = $maxLength - ($maxLength % 4);
+ $maxLength1stLine = $maxLength1stLine - ($maxLength1stLine % 4);
- $cutpoint = $maxLength1stLine;
- $output = '';
+ $cutpoint = $maxLength1stLine;
+ $output = '';
- while ($value) {
- // Split translated string at every $maxLength
- $part = substr($value, 0, $cutpoint);
- $value = substr($value, $cutpoint);
- $cutpoint = $maxLength;
- // RFC 2047 specifies that any split header should
- // be seperated by a CRLF SPACE.
- if ($output) {
- $output .= $eol . ' ';
- }
- $output .= $prefix . $part . $suffix;
- }
- $value = $output;
- } else {
- // quoted-printable encoding has been selected
- $value = Mail_mimePart::encodeQP($value);
+ while ($value) {
+ // Split translated string at every $maxLength
+ $part = substr($value, 0, $cutpoint);
+ $value = substr($value, $cutpoint);
+ $cutpoint = $maxLength;
+ // RFC 2047 specifies that any split header should
+ // be seperated by a CRLF SPACE.
+ if ($output) {
+ $output .= $eol . ' ';
+ }
+ $output .= $prefix . $part . $suffix;
+ }
+ $value = $output;
+ } else {
+ // quoted-printable encoding has been selected
+ $value = Mail_mimePart::encodeQP($value);
- // This regexp will break QP-encoded text at every $maxLength
- // but will not break any encoded letters.
- $reg1st = "|(.{0,$maxLength1stLine}[^\=][^\=])|";
- $reg2nd = "|(.{0,$maxLength}[^\=][^\=])|";
+ // This regexp will break QP-encoded text at every $maxLength
+ // but will not break any encoded letters.
+ $reg1st = "|(.{0,$maxLength1stLine}[^\=][^\=])|";
+ $reg2nd = "|(.{0,$maxLength}[^\=][^\=])|";
- if (strlen($value) > $maxLength1stLine) {
- // Begin with the regexp for the first line.
- $reg = $reg1st;
- $output = '';
- while ($value) {
- // Split translated string at every $maxLength
- // But make sure not to break any translated chars.
- $found = preg_match($reg, $value, $matches);
+ if (strlen($value) > $maxLength1stLine) {
+ // Begin with the regexp for the first line.
+ $reg = $reg1st;
+ $output = '';
+ while ($value) {
+ // Split translated string at every $maxLength
+ // But make sure not to break any translated chars.
+ $found = preg_match($reg, $value, $matches);
- // After this first line, we need to use a different
- // regexp for the first line.
- $reg = $reg2nd;
+ // After this first line, we need to use a different
+ // regexp for the first line.
+ $reg = $reg2nd;
- // Save the found part and encapsulate it in the
- // prefix & suffix. Then remove the part from the
- // $value_out variable.
- if ($found) {
- $part = $matches[0];
- $len = strlen($matches[0]);
- $value = substr($value, $len);
- } else {
- $part = $value;
- $value = '';
- }
+ // Save the found part and encapsulate it in the
+ // prefix & suffix. Then remove the part from the
+ // $value_out variable.
+ if ($found) {
+ $part = $matches[0];
+ $len = strlen($matches[0]);
+ $value = substr($value, $len);
+ } else {
+ $part = $value;
+ $value = '';
+ }
- // RFC 2047 specifies that any split header should
- // be seperated by a CRLF SPACE
- if ($output) {
- $output .= $eol . ' ';
- }
- $output .= $prefix . $part . $suffix;
- }
- $value = $output;
- } else {
- $value = $prefix . $value . $suffix;
- }
- }
+ // RFC 2047 specifies that any split header should
+ // be seperated by a CRLF SPACE
+ if ($output) {
+ $output .= $eol . ' ';
+ }
+ $output .= $prefix . $part . $suffix;
+ }
+ $value = $output;
+ } else {
+ $value = $prefix . $value . $suffix;
+ }
+ }
- return $value;
- }
+ return $value;
+ }
- /**
- * Encodes the given string using quoted-printable
- *
- * @param string $str String to encode
- *
- * @return string Encoded string
- * @access public
- * @since 1.6.0
- */
- function encodeQP($str)
- {
- // Bug #17226 RFC 2047 restricts some characters
- // if the word is inside a phrase, permitted chars are only:
- // ASCII letters, decimal digits, "!", "*", "+", "-", "/", "=", and "_"
+ /**
+ * Encodes the given string using quoted-printable
+ *
+ * @param string $str String to encode
+ *
+ * @return string Encoded string
+ * @access public
+ * @since 1.6.0
+ */
+ function encodeQP($str)
+ {
+ // Bug #17226 RFC 2047 restricts some characters
+ // if the word is inside a phrase, permitted chars are only:
+ // ASCII letters, decimal digits, "!", "*", "+", "-", "/", "=", and "_"
- // "=", "_", "?" must be encoded
- $regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/';
- $str = preg_replace_callback(
- $regexp, array('Mail_mimePart', '_qpReplaceCallback'), $str
- );
+ // "=", "_", "?" must be encoded
+ $regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/';
+ $str = preg_replace_callback(
+ $regexp, ['Mail_mimePart', '_qpReplaceCallback'], $str,
+ );
- return str_replace(' ', '_', $str);
- }
+ return str_replace(' ', '_', $str);
+ }
- /**
- * Encodes the given string using base64 or quoted-printable.
- * This method makes sure that encoded-word represents an integral
- * number of characters as per RFC2047.
- *
- * @param string $str String to encode
- * @param string $charset Character set name
- * @param string $encoding Encoding name (base64 or quoted-printable)
- * @param int $prefix_len Prefix length. Default: 0
- * @param string $eol End-of-line sequence. Default: "\r\n"
- *
- * @return string Encoded string
- * @access public
- * @since 1.8.0
- */
- function encodeMB($str, $charset, $encoding, $prefix_len=0, $eol="\r\n")
- {
- if (!function_exists('mb_substr') || !function_exists('mb_strlen')) {
- return;
- }
+ /**
+ * Encodes the given string using base64 or quoted-printable.
+ * This method makes sure that encoded-word represents an integral
+ * number of characters as per RFC2047.
+ *
+ * @param string $str String to encode
+ * @param string $charset Character set name
+ * @param string $encoding Encoding name (base64 or quoted-printable)
+ * @param int $prefix_len Prefix length. Default: 0
+ * @param string $eol End-of-line sequence. Default: "\r\n"
+ *
+ * @return string Encoded string
+ * @access public
+ * @since 1.8.0
+ */
+ function encodeMB($str, $charset, $encoding, $prefix_len=0, $eol="\r\n")
+ {
+ if (!function_exists('mb_substr') || !function_exists('mb_strlen')) {
+ return;
+ }
- $encoding = $encoding == 'base64' ? 'B' : 'Q';
- // 75 is the value specified in the RFC
- $prefix = '=?' . $charset . '?'.$encoding.'?';
- $suffix = '?=';
- $maxLength = 75 - strlen($prefix . $suffix);
+ $encoding = $encoding == 'base64' ? 'B' : 'Q';
+ // 75 is the value specified in the RFC
+ $prefix = '=?' . $charset . '?'.$encoding.'?';
+ $suffix = '?=';
+ $maxLength = 75 - strlen($prefix . $suffix);
- // A multi-octet character may not be split across adjacent encoded-words
- // So, we'll loop over each character
- // mb_stlen() with wrong charset will generate a warning here and return null
- $length = mb_strlen($str, $charset);
- $result = '';
- $line_length = $prefix_len;
+ // A multi-octet character may not be split across adjacent encoded-words
+ // So, we'll loop over each character
+ // mb_stlen() with wrong charset will generate a warning here and return null
+ $length = mb_strlen($str, $charset);
+ $result = '';
+ $line_length = $prefix_len;
- if ($encoding == 'B') {
- // base64
- $start = 0;
- $prev = '';
+ if ($encoding == 'B') {
+ // base64
+ $start = 0;
+ $prev = '';
- for ($i=1; $i<=$length; $i++) {
- // See #17311
- $chunk = mb_substr($str, $start, $i-$start, $charset);
- $chunk = base64_encode($chunk);
- $chunk_len = strlen($chunk);
+ for ($i=1; $i<=$length; $i++) {
+ // See #17311
+ $chunk = mb_substr($str, $start, $i-$start, $charset);
+ $chunk = base64_encode($chunk);
+ $chunk_len = strlen($chunk);
- if ($line_length + $chunk_len == $maxLength || $i == $length) {
- if ($result) {
- $result .= "\n";
- }
- $result .= $chunk;
- $line_length = 0;
- $start = $i;
- } else if ($line_length + $chunk_len > $maxLength) {
- if ($result) {
- $result .= "\n";
- }
- if ($prev) {
- $result .= $prev;
- }
- $line_length = 0;
- $start = $i - 1;
- } else {
- $prev = $chunk;
- }
- }
- } else {
- // quoted-printable
- // see encodeQP()
- $regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/';
+ if ($line_length + $chunk_len == $maxLength || $i == $length) {
+ if ($result) {
+ $result .= "\n";
+ }
+ $result .= $chunk;
+ $line_length = 0;
+ $start = $i;
+ } else if ($line_length + $chunk_len > $maxLength) {
+ if ($result) {
+ $result .= "\n";
+ }
+ if ($prev) {
+ $result .= $prev;
+ }
+ $line_length = 0;
+ $start = $i - 1;
+ } else {
+ $prev = $chunk;
+ }
+ }
+ } else {
+ // quoted-printable
+ // see encodeQP()
+ $regexp = '/([\x22-\x29\x2C\x2E\x3A-\x40\x5B-\x60\x7B-\x7E\x80-\xFF])/';
- for ($i=0; $i<=$length; $i++) {
- $char = mb_substr($str, $i, 1, $charset);
- // RFC recommends underline (instead of =20) in place of the space
- // that's one of the reasons why we're not using iconv_mime_encode()
- if ($char == ' ') {
- $char = '_';
- $char_len = 1;
- } else {
- $char = preg_replace_callback(
- $regexp, array('Mail_mimePart', '_qpReplaceCallback'), $char
- );
- $char_len = strlen($char);
- }
+ for ($i=0; $i<=$length; $i++) {
+ $char = mb_substr($str, $i, 1, $charset);
+ // RFC recommends underline (instead of =20) in place of the space
+ // that's one of the reasons why we're not using iconv_mime_encode()
+ if ($char == ' ') {
+ $char = '_';
+ $char_len = 1;
+ } else {
+ $char = preg_replace_callback(
+ $regexp, ['Mail_mimePart', '_qpReplaceCallback'], $char,
+ );
+ $char_len = strlen($char);
+ }
- if ($line_length + $char_len > $maxLength) {
- if ($result) {
- $result .= "\n";
- }
- $line_length = 0;
- }
+ if ($line_length + $char_len > $maxLength) {
+ if ($result) {
+ $result .= "\n";
+ }
+ $line_length = 0;
+ }
- $result .= $char;
- $line_length += $char_len;
- }
- }
+ $result .= $char;
+ $line_length += $char_len;
+ }
+ }
- if ($result) {
- $result = $prefix
- .str_replace("\n", $suffix.$eol.' '.$prefix, $result).$suffix;
- }
+ if ($result) {
+ $result = $prefix
+ .str_replace("\n", $suffix.$eol.' '.$prefix, $result).$suffix;
+ }
- return $result;
- }
+ return $result;
+ }
- /**
- * Callback function to replace extended characters (\x80-xFF) with their
- * ASCII values (RFC2047: quoted-printable)
- *
- * @param array $matches Preg_replace's matches array
- *
- * @return string Encoded character string
- * @access private
- */
- function _qpReplaceCallback($matches)
- {
- return sprintf('=%02X', ord($matches[1]));
- }
+ /**
+ * Callback function to replace extended characters (\x80-xFF) with their
+ * ASCII values (RFC2047: quoted-printable)
+ *
+ * @param array $matches Preg_replace's matches array
+ *
+ * @return string Encoded character string
+ * @access private
+ */
+ function _qpReplaceCallback($matches)
+ {
+ return sprintf('=%02X', ord($matches[1]));
+ }
- /**
- * Callback function to replace extended characters (\x80-xFF) with their
- * ASCII values (RFC2231)
- *
- * @param array $matches Preg_replace's matches array
- *
- * @return string Encoded character string
- * @access private
- */
- function _encodeReplaceCallback($matches)
- {
- return sprintf('%%%02X', ord($matches[1]));
- }
+ /**
+ * Callback function to replace extended characters (\x80-xFF) with their
+ * ASCII values (RFC2231)
+ *
+ * @param array $matches Preg_replace's matches array
+ *
+ * @return string Encoded character string
+ * @access private
+ */
+ function _encodeReplaceCallback($matches)
+ {
+ return sprintf('%%%02X', ord($matches[1]));
+ }
} // End of class
diff --git a/import/modify.php b/import/modify.php
index 36b6e20..a05d01c 100755
--- a/import/modify.php
+++ b/import/modify.php
@@ -4,18 +4,17 @@ require_once 'Mail/Mbox.php';
//This function just lists all subjects
function listSubjects($mbox) {
- echo 'Mbox has ' . $mbox->size() . ' messages.' . "\n";
+ echo 'Mbox has ' . $mbox->size() . ' messages.' . "\n";
- for ($n = 0; $n < $mbox->size(); $n++) {
- $message = $mbox->get($n);
- preg_match('/Subject: (.*)$/m', $message, $matches);
- $subject = $matches[1];
- echo 'Mail #' . $n . ': ' . $subject . "\n";
- }
- echo "\n";
+ for ($n = 0; $n < $mbox->size(); $n++) {
+ $message = $mbox->get($n);
+ preg_match('/Subject: (.*)$/m', $message, $matches);
+ $subject = $matches[1];
+ echo 'Mail #' . $n . ': ' . $subject . "\n";
+ }
+ echo "\n";
}
-
//make a copy of the demo file
$original = dirname(__FILE__) . '/demobox';
$file = tempnam('/tmp', 'mbox-copy-');
@@ -26,31 +25,26 @@ $mbox = new Mail_Mbox($file);
$mbox->open();
listSubjects($mbox);
-
echo 'append a message to the end of the box' . "\n";
$message = $mbox->get(0) . "\n" . 'This is a copy of the mail';
$mbox->insert($message);
listSubjects($mbox);
-
echo 'insert a message before the second message' . "\n";
$message = $mbox->get(0) . "\n" . 'This is another copy of the mail';
$mbox->insert($message, 1);
listSubjects($mbox);
-
echo 'remove the last message' . "\n";
$mbox->remove(
- $mbox->size() - 1
+ $mbox->size() - 1,
);
listSubjects($mbox);
-
echo 'remove the first two messages' . "\n";
-$mbox->remove(array(0, 1));
+$mbox->remove([0, 1]);
listSubjects($mbox);
-
$mbox->close();
//remove the tmp file
diff --git a/import/phail.php b/import/phail.php
index 2148289..21a2b8e 100755
--- a/import/phail.php
+++ b/import/phail.php
@@ -11,28 +11,28 @@ require_once 'Console/Getopt.php';
$argv = Console_Getopt::readPHPArgv();
$opts = Console_Getopt::getOpt($argv, 'f:c:s:t:a:b:');
if (PEAR::isError($opts)) {
- usage($opts->getMessage());
+ usage($opts->getMessage());
}
PEAR::setErrorHandling(PEAR_ERROR_DIE);
$mime = new Mail_Mime;
foreach ($opts[0] as $opt) {
- $param = $opt[1];
- switch ($opt[0]) {
- case 'f':
- $headers['From'] = $param; break;
- case 'c':
- $headers['Cc'] = $param; break;
- case 's':
- $headers['Subject'] = $param; break;
- case 't':
- $to = $param; break;
- case 'a':
- $mime->addAttachment($param); break;
- case 'b':
- $isfile = @is_file($param) ? true : false;
- $mime->setTXTBody($param, $isfile); break;
- }
+ $param = $opt[1];
+ switch ($opt[0]) {
+ case 'f':
+ $headers['From'] = $param; break;
+ case 'c':
+ $headers['Cc'] = $param; break;
+ case 's':
+ $headers['Subject'] = $param; break;
+ case 't':
+ $to = $param; break;
+ case 'a':
+ $mime->addAttachment($param); break;
+ case 'b':
+ $isfile = @is_file($param) ? true : false;
+ $mime->setTXTBody($param, $isfile); break;
+ }
}
$mbody = $mime->get();
@@ -42,6 +42,6 @@ $mail->send($to, $headers, $mbody);
function usage($error)
{
- die($error);
+ die($error);
}
?> \ No newline at end of file
diff --git a/import/read.php b/import/read.php
index 9d573b1..37dd197 100755
--- a/import/read.php
+++ b/import/read.php
@@ -12,19 +12,19 @@ $mbox = new Mail_Mbox($file);
$mbox->open();
for ($n = 0; $n < $mbox->size(); $n++) {
- $message = $mbox->get($n);
+ $message = $mbox->get($n);
- preg_match('/Subject: (.*)$/m', $message, $matches);
- $subject = $matches[1];
- echo 'Mail #' . $n . ': ' . $subject . "\n\n\n\n";
- $Decoder = new Mail_mimeDecode( $message );
- $params = array(
- 'include_bodies' => TRUE,
- 'decode_bodies' => TRUE,
- 'decode_headers' => TRUE
- );
- $Decoded = $Decoder->decode($params);
- print_r($Decoded);
+ preg_match('/Subject: (.*)$/m', $message, $matches);
+ $subject = $matches[1];
+ echo 'Mail #' . $n . ': ' . $subject . "\n\n\n\n";
+ $Decoder = new Mail_mimeDecode( $message );
+ $params = [
+ 'include_bodies' => TRUE,
+ 'decode_bodies' => TRUE,
+ 'decode_headers' => TRUE,
+ ];
+ $Decoded = $Decoder->decode($params);
+ print_r($Decoded);
}
$mbox->close();
diff --git a/import/schema_import_inc.php b/import/schema_import_inc.php
index fc898c1..5b411df 100755
--- a/import/schema_import_inc.php
+++ b/import/schema_import_inc.php
@@ -1,5 +1,5 @@
<?php
-$tables = array(
+$tables = [
'contact_phx' => "
content_id I8 PRIMARY,
@@ -101,7 +101,7 @@ $tables = array(
last_change T DEFAULT CURRENT_TIMESTAMP
",
-);
+];
global $gBitInstaller;
diff --git a/includes/bit_setup_inc.php b/includes/bit_setup_inc.php
index f7aa0fe..45f7742 100755
--- a/includes/bit_setup_inc.php
+++ b/includes/bit_setup_inc.php
@@ -14,7 +14,7 @@ $pRegisterHash = [
define( 'CONTACT_PKG_NAME', $pRegisterHash['package_name'] );
define( 'CONTACT_PKG_URL', BIT_ROOT_URL . basename( $pRegisterHash['package_path'] ) . '/' );
define( 'CONTACT_PKG_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/' );
-define( 'CONTACT_PKG_INCLUDE_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/');
+define( 'CONTACT_PKG_INCLUDE_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/');
$gBitSystem->registerPackage( $pRegisterHash );
if( $gBitSystem->isPackageActive( 'contact' ) ) {
diff --git a/includes/classes/Contact.php b/includes/classes/Contact.php
index 2401d9f..91a5973 100755
--- a/includes/classes/Contact.php
+++ b/includes/classes/Contact.php
@@ -13,6 +13,7 @@
* required setup
*/
namespace Bitweaver\Contact;
+
use Bitweaver\BitBase;
use Bitweaver\BitDate;
use Bitweaver\Liberty\LibertyContent; // Contact base class
@@ -37,14 +38,14 @@ class Contact extends LibertyContent {
*/
public function __construct( $pContactId = NULL, $pContentId = NULL ) {
parent::__construct();
- $this->registerContentType( CONTACT_CONTENT_TYPE_GUID, array(
+ $this->registerContentType( CONTACT_CONTENT_TYPE_GUID, [
'content_type_guid' => CONTACT_CONTENT_TYPE_GUID,
'content_name' => 'Contact Entry',
'handler_class' => 'Contact',
'handler_package' => 'contact',
'handler_file' => 'Contact.php',
- 'maintainer_url' => 'http://lsces.co.uk'
- ) );
+ 'maintainer_url' => 'http://lsces.co.uk',
+ ] );
$this->mContentId = (int)$pContentId;
$this->mContentTypeGuid = CONTACT_CONTENT_TYPE_GUID;
@@ -71,7 +72,7 @@ class Contact extends LibertyContent {
public function load( $pContentId = NULL, $pPluginParams = NULL ) {
if ( $pContentId ) $this->mContentId = (int)$pContentId;
if( $this->verifyId( $this->mContentId ) ) {
- $query = "select con.*, lc.*,
+ $query = "select con.*, lc.*,
ap.*, xhA.`xkey_ext` AS house,
img.`xkey` AS client_gallery,
x00.`xkey_ext` as name, lc.`title` as organisation,
@@ -88,7 +89,7 @@ class Contact extends LibertyContent {
LEFT JOIN `".BIT_DB_PREFIX."contact_xref` xhL ON xhL.`content_id` = con.`content_id` AND xhL.`source` = '#L' AND ( xhL.`end_date` IS NULL OR xhL.`end_date` > CURRENT_TIMESTAMP )
LEFT JOIN `".BIT_DB_PREFIX."address_postcode` ap ON ap.`postcode` = xhA.`xkey`
WHERE con.`content_id`=?";
- $result = $this->mDb->query( $query, array( $this->mContentId ) );
+ $result = $this->mDb->query( $query, [ $this->mContentId ] );
// LEFT JOIN `".BIT_DB_PREFIX."contact` ci ON ci.contact_id = pro.owner_id
// LEFT JOIN `".BIT_DB_PREFIX."contact_address` a ON a.contact_id = pro.address_id
// LEFT JOIN `".BIT_DB_PREFIX."postcode` p ON p.`postcode` = a.`postcode`
@@ -129,7 +130,7 @@ class Contact extends LibertyContent {
}
}
LibertyContent::load();
- return;
+
}
/**
@@ -190,7 +191,7 @@ class Contact extends LibertyContent {
// mContentId will not be set until the secondary data has commited
if( !empty( $pParamHash['contact_store']['content_id'] ) ) {
- $result = $this->mDb->associateUpdate( $table, $pParamHash['contact_store'], array( "content_id" => $this->mContentId ) );
+ $result = $this->mDb->associateUpdate( $table, $pParamHash['contact_store'], [ "content_id" => $this->mContentId ] );
} else {
$pParamHash['contact_store']['content_id'] = $pParamHash['content_id'];
$pParamHash['contact_store']['parent_id'] = $pParamHash['content_id'];
@@ -206,17 +207,17 @@ class Contact extends LibertyContent {
}
if( !empty( $pParamHash['contact_types'] ) ) {
$query = "DELETE FROM `".BIT_DB_PREFIX."contact_xref` WHERE `content_id` = ? AND `source` LIKE '$%'";
- $result = $this->mDb->query($query, array($this->mContentId ) );
+ $result = $this->mDb->query($query, [$this->mContentId ] );
foreach ( $pParamHash['contact_types'] as $key => $source ) {
if ( $source == '$00' ) {
$query = "INSERT INTO `".BIT_DB_PREFIX."contact_xref` (`content_id`, `source`, `xkey_ext`, `last_update_date`) VALUES ( ?, ?, ?, NULL )";
- $result = $this->mDb->query($query, array( $this->mContentId, $source, $pParamHash['name'] ) );
+ $result = $this->mDb->query($query, [ $this->mContentId, $source, $pParamHash['name'] ] );
} else if ( $source == '$01' ) {
$query = "INSERT INTO `".BIT_DB_PREFIX."contact_xref` (`content_id`, `source`, `xkey_ext`, `last_update_date`) VALUES ( ?, ?, ?, NULL )";
- $result = $this->mDb->query($query, array( $this->mContentId, $source, $pParamHash['organisation'] ) );
+ $result = $this->mDb->query($query, [ $this->mContentId, $source, $pParamHash['organisation'] ] );
} else {
$query = "INSERT INTO `".BIT_DB_PREFIX."contact_xref` (`content_id`, `source`, `last_update_date`) VALUES ( ?, ?, NULL )";
- $result = $this->mDb->query($query, array( $this->mContentId, $source ) );
+ $result = $this->mDb->query($query, [ $this->mContentId, $source ] );
}
}
}
@@ -240,7 +241,7 @@ class Contact extends LibertyContent {
if ($this->isValid() ) {
$this->mDb->StartTrans();
$query = "DELETE FROM `".BIT_DB_PREFIX."contact_xref` WHERE `content_id` = ?";
- $result = $this->mDb->query($query, array($this->mContentId ) );
+ $result = $this->mDb->query($query, [$this->mContentId ] );
if (LibertyContent::expunge() ) {
$ret = TRUE;
$this->mDb->CompleteTrans();
@@ -285,8 +286,8 @@ class Contact extends LibertyContent {
public function getDisplayLink( $pLinkText=NULL, $pMixed=NULL, $pAnchor=NULL ) {
if ( $this->mContentId != $pMixed['content_id'] ) $this->load($pMixed['content_id']);
- $ret = ( empty( $this->mInfo['content_id'] ) )
- ? '<a href="' . $this->getDisplayUrl( $pMixed['content_id'] ) . '">' . $pMixed['title'] . '</a>'
+ $ret = ( empty( $this->mInfo['content_id'] ) )
+ ? '<a href="' . $this->getDisplayUrl( $pMixed['content_id'] ) . '">' . $pMixed['title'] . '</a>'
: '<a href="' . $this->getDisplayUrl( $pMixed['content_id'] ) . '">' . "Contact - " . $this->mInfo['title'] . '</a>';
return $ret;
}
@@ -331,10 +332,10 @@ class Contact extends LibertyContent {
$selectSql = '';
$joinSql = '';
$whereSql = '';
- $bindVars = array();
+ $bindVars = [];
if ( isset( $pParamHash['role_id'] ) ) {
- array_push( $bindVars, $this->mContentTypeGuid );
+ array_push( $bindVars, $this->mContentTypeGuid );
if ( $pParamHash['role_id'] > 0 ) {
$whereSql .= " AND con.`role_id` = ? ";
$bindVars[] = $pParamHash['role_id'];
@@ -355,10 +356,10 @@ class Contact extends LibertyContent {
}
if ( !isset( $pParamHash['role_id'] ) ) {
- array_push( $bindVars, $this->mContentTypeGuid );
+ array_push( $bindVars, $this->mContentTypeGuid );
}
- $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pParamHash );
+ $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pParamHash );
// $pParamHash["listInfo"]["ihash"]['contact_type_guid'] = $contact_type_guid;
@@ -391,10 +392,10 @@ class Contact extends LibertyContent {
}
/* if( isset( $find_name ) and is_string( $find_name ) and $find_name <> '' ) {
- $split = preg_split('|[,. ]|', $find_name, 2);
+ $split = preg_split('|[,. ]|', $find_name, 2);
$whereSql .= " AND UPPER( ci.`surname` ) STARTING ? ";
$bindVars[] = strtoupper( $split[0] );
- if ( array_key_exists( 1, $split ) ) {
+ if ( array_key_exists( 1, $split ) ) {
$split[1] = trim( $split[1] );
$whereSql .= " AND UPPER( ci.`forename` ) STARTING ? ";
$bindVars[] = strtoupper( $split[1] );
@@ -441,7 +442,7 @@ class Contact extends LibertyContent {
$joinSql WHERE lc.`content_type_guid` = ? $whereSql ";
$result = $this->mDb->query( $query, $bindVars, $max_records, $offset );
- $ret = array();
+ $ret = [];
while( $res = $result->fetchRow() ) {
if (!empty($parse_split)) {
$res = array_merge($this->parseSplit($res), $res);
@@ -464,15 +465,15 @@ class Contact extends LibertyContent {
global $gBitUser, $gBitSmarty;
$roles = array_keys($gBitUser->mRoles);
- $bindVars = array();
- $bindVars = array_merge( $bindVars, $roles, array( $gBitUser->mUserId ) );
+ $bindVars = [];
+ $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] );
$query = "SELECT g.* FROM `".BIT_DB_PREFIX."contact_xref_type` g
LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` purm ON ( purm.`user_id`=".$gBitUser->mUserId." ) AND ( purm.`role_id`=g.`role_id` )
WHERE g.`xref_type` > 0 AND (g.`role_id` IN(". implode(',', array_fill(0, count($roles), '?')) ." ) OR purm.`user_id`=?)
ORDER BY g.`xref_type`";
$result = $this->mDb->query( $query, $bindVars );
- $ret = array();
+ $ret = [];
while ($res = $result->fetchRow()) {
$ret[] = $res;
}
@@ -489,7 +490,7 @@ class Contact extends LibertyContent {
$roles = array_keys($gBitUser->mRoles);
$bindVars = [];
- $bindVars = array_merge( $bindVars, $roles, array( $gBitUser->mUserId ) );
+ $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] );
$query = "SELECT g.`cross_ref_title` AS `type_name`, g.`source` FROM `".BIT_DB_PREFIX."contact_xref_source` g
LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` purm ON ( purm.`user_id`=".$gBitUser->mUserId." ) AND ( purm.`role_id`=g.`role_id` )
@@ -515,21 +516,21 @@ class Contact extends LibertyContent {
$query = "SELECT s.`cross_ref_title` AS `type_name`, s.`source`, s.`template` FROM `".BIT_DB_PREFIX."contact_xref_source` s
WHERE s.`template` = '$xrefTemplate'
ORDER BY s.`cross_ref_title`";
- $result = $this->mDb->query($query, array( $this->mContentId, $xrefGroup ) );
+ $result = $this->mDb->query($query, [ $this->mContentId, $xrefGroup ] );
} elseif ( $xrefGroup > -1 ) {
$query = "SELECT s.`cross_ref_title` AS `type_name`, s.`source`, s.`template` FROM `".BIT_DB_PREFIX."contact_xref_source` s
LEFT JOIN `".BIT_DB_PREFIX."contact_xref` x ON x.`source` = s.`source` AND x.`content_id` = ? AND ( x.`end_date` IS NULL OR x.`end_date` > CURRENT_TIMESTAMP )
WHERE s.`xref_type` = ? AND ( x.`xref_id` IS NULL OR x.`xorder` > 0 )
ORDER BY s.`cross_ref_title`";
- $result = $this->mDb->query($query, array( $this->mContentId, $xrefGroup ) );
+ $result = $this->mDb->query($query, [ $this->mContentId, $xrefGroup ] );
} else {
$query = "SELECT s.`cross_ref_title` AS `type_name`, s.`source`, s.`template` FROM `".BIT_DB_PREFIX."contact_xref_source` s
LEFT JOIN `".BIT_DB_PREFIX."contact_xref` x ON x.`source` = s.`source` AND x.`content_id` = ? AND ( x.`end_date` IS NULL OR x.`end_date` > CURRENT_TIMESTAMP )
WHERE s.`xref_type` > 0 AND ( x.`xref_id` IS NULL OR x.`xorder` > 0 )
ORDER BY s.`cross_ref_title`";
- $result = $this->mDb->query($query, array( $this->mContentId ) );
+ $result = $this->mDb->query($query, [ $this->mContentId ] );
}
- $ret = array();
+ $ret = [];
while ($res = $result->fetchRow()) {
$ret['list'][$res["source"]] = trim($res["type_name"]);
@@ -547,15 +548,15 @@ class Contact extends LibertyContent {
global $gBitUser, $gBitSmarty;
$roles = array_keys($gBitUser->mRoles);
- $bindVars = array();
- $bindVars = array_merge( $bindVars, $roles, array( $gBitUser->mUserId ) );
+ $bindVars = [];
+ $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] );
$query = "SELECT DISTINCT g.`template` FROM `".BIT_DB_PREFIX."contact_xref_source` g
LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` purm ON ( purm.`user_id`=".$gBitUser->mUserId." ) AND ( purm.`role_id`=g.`role_id` )
WHERE (g.`role_id` IN(". implode(',', array_fill(0, count($roles), '?')) ." ) OR purm.`user_id`=?)
ORDER BY g.`template`";
$result = $this->mDb->query( $query, $bindVars );
- $ret = array();
+ $ret = [];
$cnt = 0;
while ($res = $result->fetchRow()) {
$ret[] = trim($res["template"]) <> '' ? trim($res["template"]) : 'generic';
@@ -579,9 +580,9 @@ class Contact extends LibertyContent {
LEFT JOIN `".BIT_DB_PREFIX."address_postcode` ap ON ap.`postcode` = xhA.`xkey`
WHERE r.`source` = 'KEY_S' AND r.`xref` = ? AND ( r.`end_date` IS NULL OR r.`end_date` > CURRENT_TIMESTAMP )
ORDER BY r.`xref`, XORDERBY";
- $result = $this->mDb->query($query, array( $contract ) );
+ $result = $this->mDb->query($query, [ $contract ] );
- $ret = array();
+ $ret = [];
while ($res = $result->fetchRow()) {
$ret[] = $res;
}
@@ -605,9 +606,9 @@ class Contact extends LibertyContent {
global $gBitUser;
$roles = array_keys($gBitUser->mRoles);
- $bindVars = array();
+ $bindVars = [];
array_push( $bindVars, $this->mContentId );
- $bindVars = array_merge( $bindVars, $roles, array( $gBitUser->mUserId ) );
+ $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] );
$sql = "SELECT r.`source`, r.`cross_ref_title`, d.`content_id`
FROM `".BIT_DB_PREFIX."contact_xref_source` r
@@ -633,10 +634,10 @@ class Contact extends LibertyContent {
global $gBitUser;
$roles = array_keys($gBitUser->mRoles);
- $bindVars = array();
+ $bindVars = [];
array_push( $bindVars, $this->mDb->NOW() );
array_push( $bindVars, $this->mContentId );
- $bindVars = array_merge( $bindVars, $roles, array( $gBitUser->mUserId ) );
+ $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] );
$sql = "SELECT s.xref_type, x.`xref_id`, x.`last_update_date`, x.`source`, t.`title` AS type_title,
CASE
@@ -688,7 +689,7 @@ class Contact extends LibertyContent {
* store or update xref records for this contact record
*/
public function storeXref( &$pParamHash ) {
- $xref = new ContactXref( isset($pParamHash['xref_id']) ? $pParamHash['xref_id'] : NULL );
+ $xref = new ContactXref( $pParamHash['xref_id'] ?? NULL );
if ( $xref->store( $pParamHash ) ) {
$this->mInfo['xref_title'] = $xref->mContentId;
$this->mInfo['xref_store'] = $xref->mInfo;
@@ -696,7 +697,7 @@ class Contact extends LibertyContent {
$this->load();
return true;
- } else return false;
+ } return false;
}
/**
@@ -711,7 +712,7 @@ class Contact extends LibertyContent {
$this->load();
return true;
- } else return false;
+ } return false;
}
/**
@@ -724,7 +725,7 @@ class Contact extends LibertyContent {
global $gBitUser;
$roles = array_keys($gBitUser->mRoles);
- $bindVars = array();
+ $bindVars = [];
array_push( $bindVars, $this->mDb->NOW() );
array_push( $bindVars, $this->mContentId );
// $bindVars = array_merge( $bindVars, $roles, array( $gBitUser->mUserId ) );
@@ -759,10 +760,10 @@ class Contact extends LibertyContent {
global $gBitUser;
$roles = array_keys($gBitUser->mRoles);
- $bindVars = array();
+ $bindVars = [];
array_push( $bindVars, $this->mDb->NOW() );
array_push( $bindVars, $this->mContentId );
- $bindVars = array_merge( $bindVars, $roles, array( $gBitUser->mUserId ) );
+ $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] );
$sql = "SELECT s.xref_type, x.`xref_id`, x.`last_update_date`, x.`source`, t.`title` AS type_title,
CASE
diff --git a/includes/classes/ContactType.php b/includes/classes/ContactType.php
index 88a0823..479c855 100755
--- a/includes/classes/ContactType.php
+++ b/includes/classes/ContactType.php
@@ -12,6 +12,7 @@
* Required setup
*/
namespace Bitweaver\Contact;
+
use Bitweaver\BitBase;
/**
@@ -33,7 +34,7 @@ class ContactType extends BitBase {
$roles = array_keys($gBitUser->mRoles);
$bindVars = [];
- $bindVars = array_merge( $bindVars, $roles, array( $gBitUser->mUserId ) );
+ $bindVars = array_merge( $bindVars, $roles, [ $gBitUser->mUserId ] );
$sql = "SELECT r.`source`, r.`cross_ref_title`
FROM `".BIT_DB_PREFIX."contact_xref_source` r
@@ -91,14 +92,14 @@ class ContactType extends BitBase {
$result = $gBitSystem->mDb->query( $query, $bindVars );
- $ret = [];
+ $ret = [];
- while( $res = $result->fetchRow() ) {
- $res["num_types"] = $gBitSystem->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."contact_xref_source` WHERE `xref_type`= ?", array( $res["xref_type"] ) );
+ while( $res = $result->fetchRow() ) {
+ $res["num_types"] = $gBitSystem->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."contact_xref_source` WHERE `xref_type`= ?", [ $res["xref_type"] ] );
- $ret[] = $res;
- }
+ $ret[] = $res;
+ }
- return $ret;
- }
+ return $ret;
+ }
}
diff --git a/includes/classes/ContactXref.php b/includes/classes/ContactXref.php
index 6a4184b..598c356 100755
--- a/includes/classes/ContactXref.php
+++ b/includes/classes/ContactXref.php
@@ -12,6 +12,7 @@
* Required setup
*/
namespace Bitweaver\Contact;
+
use Bitweaver\BitBase;
use Bitweaver\BitDate;
@@ -55,7 +56,7 @@ class ContactXref extends BitBase {
JOIN `".BIT_DB_PREFIX."contact_xref_source` s ON s.`source` = x.`source`
WHERE x.`xref_id` = ?
ORDER BY x.`xorder`";
- $result = $this->mDb->getRow( $sql, array( $pXref_id ) );
+ $result = $this->mDb->getRow( $sql, [ $pXref_id ] );
if( $result['content_id'] ) {
$this->mXrefId = $pXref_id;
$this->mContentId = $result['content_id'];
@@ -76,26 +77,26 @@ class ContactXref extends BitBase {
if ( isset( $pParamHash['content_id'] )) {
$pParamHash['xref_store']['content_id'] = $pParamHash['content_id'];
- }
+ }
if ( isset( $pParamHash['source'] )) {
$pParamHash['xref_store']['source'] = $pParamHash['source'];
- }
-
+ }
+
$pParamHash['xref_store']['xorder'] = 0;
if ( isset ( $pParamHash['fAddXref'] ) ) {
$pParamHash['xref_store']['source'] = isset( $pParamHash['Array_xref_type_list'] ) ? $pParamHash['Array_xref_type_list']['Array.source'] : $pParamHash['source'];
$pParamHash['xref_store']['content_id'] = $pParamHash['content_id'];
- $sql = "SELECT x.`multi` FROM `".BIT_DB_PREFIX."contact_xref_source` x WHERE x.`source` = ?";
- $next = $this->mDb->getOne( $sql, array( $pParamHash['xref_store']['source'] ) );
+ $sql = "SELECT x.`multi` FROM `".BIT_DB_PREFIX."contact_xref_source` x WHERE x.`source` = ?";
+ $next = $this->mDb->getOne( $sql, [ $pParamHash['xref_store']['source'] ] );
if ( $next > 0 ) {
$sql = "SELECT COALESCE( MAX(x.`xorder`) + 1, 1 ) FROM `".BIT_DB_PREFIX."contact_xref` x
WHERE x.`content_id` = ? AND x.`source` = ?";
- $next = $this->mDb->getOne( $sql, array( $pParamHash['xref_store']['content_id'], $pParamHash['xref_store']['source'] ) );
+ $next = $this->mDb->getOne( $sql, [ $pParamHash['xref_store']['content_id'], $pParamHash['xref_store']['source'] ] );
}
$pParamHash['xref_store']['xorder'] = $next;
- }
+ }
if ( isset ( $pParamHash['fStepXref'] ) ) {
$pParamHash['xref_store']['source'] = $this->mSource;
@@ -108,19 +109,19 @@ class ContactXref extends BitBase {
$pParamHash['xref_store']['xkey_ext'] = '';
$pParamHash['xref_store']['data'] = '';
}
-
+
if ( isset( $pParamHash['xref'] )) {
$pParamHash['xref_store']['xref'] = $pParamHash['xref'];
- }
+ }
if ( isset( $pParamHash['xkey'] )) {
$pParamHash['xref_store']['xkey'] = $pParamHash['xkey'];
- }
+ }
if ( isset( $pParamHash['xkey_ext'] )) {
$pParamHash['xref_store']['xkey_ext'] = $pParamHash['xkey_ext'];
- }
+ }
if ( isset( $pParamHash['edit'] )) {
$pParamHash['xref_store']['data'] = $pParamHash['edit'];
- }
+ }
$pParamHash['xref_store']['last_update_date'] = $this->mDb->NOW();
// If start and/or end dates are supplied these are updated as well
@@ -128,12 +129,12 @@ class ContactXref extends BitBase {
$dateString = $this->mDate->gmmktime(
$pParamHash['start_Hour'],
$pParamHash['start_Minute'],
- isset($pParamHash['start_Second']) ? $pParamHash['start_Second'] : 0,
+ $pParamHash['start_Second'] ?? 0,
$pParamHash['start_Month'],
$pParamHash['start_Day'],
- $pParamHash['start_Year']
+ $pParamHash['start_Year'],
);
-
+
$timestamp = $this->mDate->getUTCFromDisplayDate( $dateString );
if( $timestamp !== -1 ) {
$pParamHash['start_date'] = $timestamp;
@@ -145,17 +146,17 @@ class ContactXref extends BitBase {
if( isset ($pParamHash['ignore_start_date']) && $pParamHash['ignore_start_date'] == 'on' ) {
$pParamHash['xref_store']['start_date'] = '';
}
-
+
if( !empty( $pParamHash['end_Month'] ) ) {
$dateString = $this->mDate->gmmktime(
$pParamHash['end_Hour'],
$pParamHash['end_Minute'],
- isset($pParamHash['end_Second']) ? $pParamHash['end_Second'] : 0,
+ $pParamHash['end_Second'] ?? 0,
$pParamHash['end_Month'],
$pParamHash['end_Day'],
- $pParamHash['end_Year']
+ $pParamHash['end_Year'],
);
-
+
$timestamp = $this->mDate->getUTCFromDisplayDate( $dateString );
if( $timestamp !== -1 ) {
$pParamHash['end_date'] = $timestamp;
@@ -177,7 +178,7 @@ class ContactXref extends BitBase {
$this->mDb->StartTrans();
if( isset( $pParamHash['xref_id'] ) ) {
- $result = $this->mDb->associateUpdate( $table, $pParamHash['xref_store'], array( "xref_id" => $pParamHash['xref_id'] ) );
+ $result = $this->mDb->associateUpdate( $table, $pParamHash['xref_store'], [ "xref_id" => $pParamHash['xref_id'] ] );
} else {
$this->mXrefId = $this->mDb->GenID( 'contact_xref_seq' );
$pParamHash['xref_id'] = $this->mXrefId;
@@ -188,9 +189,9 @@ class ContactXref extends BitBase {
$this->load( $this->mXrefId );
$this->mDb->CompleteTrans();
return true;
- } else {
- return false;
}
+ return false;
+
}
public function stepXref( &$pParamHash = NULL ) {
@@ -213,5 +214,5 @@ class ContactXref extends BitBase {
$this->store( $pParamHash );
return true;
}
-
+
} \ No newline at end of file
diff --git a/includes/classes/ContactXrefType.php b/includes/classes/ContactXrefType.php
index b87bfe9..17af008 100755
--- a/includes/classes/ContactXrefType.php
+++ b/includes/classes/ContactXrefType.php
@@ -12,6 +12,7 @@
* Required setup
*/
namespace Bitweaver\Contact;
+
use Bitweaver\BitBase;
/**
@@ -28,7 +29,7 @@ class ContactXrefType extends BitBase {
global $gBitSystem;
$where = '';
- $bindVars = array();
+ $bindVars = [];
if( !empty( $pOptionHash['active_role'] ) ) {
$where = " WHERE cxs.`role_id` = ? ";
$bindVars[] = $pOptionHash['active_role'];
@@ -44,14 +45,14 @@ class ContactXrefType extends BitBase {
$result = $gBitSystem->mDb->query( $query, $bindVars );
- $ret = [];
+ $ret = [];
- while( $res = $result->fetchRow() ) {
- $res["num_entries"] = $gBitSystem->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."contact_xref` WHERE `source`= ?", array( $res["source"] ) );
+ while( $res = $result->fetchRow() ) {
+ $res["num_entries"] = $gBitSystem->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."contact_xref` WHERE `source`= ?", [ $res["source"] ] );
- $ret[] = $res;
- }
+ $ret[] = $res;
+ }
- return $ret;
- }
+ return $ret;
+ }
} \ No newline at end of file
diff --git a/includes/lookup_contact_inc.php b/includes/lookup_contact_inc.php
index b159407..1c77c99 100755
--- a/includes/lookup_contact_inc.php
+++ b/includes/lookup_contact_inc.php
@@ -20,7 +20,7 @@ use Bitweaver\Contact\Contact;
} else {
$gContent = new Contact();
}
-
+
$gBitSmarty->clearAssign( 'gContent' );
$gBitSmarty->assign( 'gContent', $gContent );
}
diff --git a/includes/lookup_contact_xref_type_inc.php b/includes/lookup_contact_xref_type_inc.php
index 27db728..ec39dce 100755
--- a/includes/lookup_contact_xref_type_inc.php
+++ b/includes/lookup_contact_xref_type_inc.php
@@ -11,7 +11,7 @@
global $gContent;
use Bitweaver\Contact\Contact;
use Bitweaver\Contact\ContactXref;
-
+
// if we already have a gContent, we assume someone else created it for us, and has properly loaded everything up.
if( empty( $gContent ) || !is_object( $gContent ) ) {
if (!empty($_REQUEST['xref_id']) && is_numeric($_REQUEST['xref_id'])) {
diff --git a/index.php b/index.php
index aa59937..ceb7082 100755
--- a/index.php
+++ b/index.php
@@ -36,4 +36,4 @@ if ($gContent->isCommentable()) {
$gContent->mInfo['type'] = $gContent->getContactGroupList();
$gBitSystem->setBrowserTitle("Contact List Item");
- $gBitSystem->display( 'bitpackage:contact/show_contact.tpl', NULL, array( 'display_mode' => 'display' ));
+ $gBitSystem->display( 'bitpackage:contact/show_contact.tpl', NULL, [ 'display_mode' => 'display' ]);
diff --git a/lib/phpcoord-2.3.php b/lib/phpcoord-2.3.php
index ae5b4d6..b158963 100755
--- a/lib/phpcoord-2.3.php
+++ b/lib/phpcoord-2.3.php
@@ -26,7 +26,6 @@
// - Initial version
//--------------------------------------------------------------------------
-
// ================================================================== LatLng
class LatLng {
@@ -34,7 +33,6 @@ class LatLng {
public $lat;
public $lng;
-
/**
* Create a new LatLng object from the given latitude and longitude
*
@@ -46,7 +44,6 @@ class LatLng {
$this->lng = $lng;
}
-
/**
* Return a string representation of this LatLng object
*
@@ -56,7 +53,6 @@ class LatLng {
return "({$this->lat}, {$this->lng})";
}
-
/**
* Calculate the surface distance between this LatLng object and the one
* passed in as a parameter.
@@ -81,11 +77,10 @@ class LatLng {
$z2 = $er * cos($latTo);
$d = acos(sin($latFrom)*sin($latTo) + cos($latFrom)*cos($latTo)*cos($lngTo-$lngFrom)) * $er;
-
+
return $d;
}
-
/**
* Convert this LatLng object from OSGB36 datum to WGS84 datum.
*/
@@ -129,12 +124,11 @@ class LatLng {
}
$phiB = rad2deg($phiN);
-
+
$this->lat = $phiB;
$this->lng = $lambdaB;
}
-
/**
* Convert this LatLng object from WGS84 datum to OSGB36 datum.
*/
@@ -178,7 +172,7 @@ class LatLng {
}
$phiB = rad2deg($phiN);
-
+
$this->lat = $phiB;
$this->lng = $lambdaB;
}
@@ -261,7 +255,6 @@ class LatLng {
return $osref->toString();
}
-
/**
* Convert a latitude and longitude to an UTM reference
*
@@ -360,7 +353,6 @@ class LatLng {
}
}
-
// =================================================================== OSRef
// References given with OSRef are accurate to 1m.
@@ -369,7 +361,6 @@ class OSRef {
public $easting;
public $northing;
-
/**
* Create a new OSRef object representing an OSGB grid reference. Note
* that the parameters for this constructor require eastings and
@@ -391,7 +382,6 @@ class OSRef {
$this->northing = $northing;
}
-
/**
* Convert this grid reference into a string showing the exact values
* of the easting and northing.
@@ -402,7 +392,6 @@ class OSRef {
return "({$this->easting}, {$this->northing})";
}
-
/**
* Convert this grid reference into a string using a standard six-figure
* grid reference including the two-character designation for the 100km
@@ -414,8 +403,8 @@ class OSRef {
$hundredkmE = floor($this->easting / 100000);
$hundredkmN = floor($this->northing / 100000);
$firstLetter = "";
- $firstLetter = $hundredkmN < 5
- ? ( $hundredkmE < 5 ? "S" : "T" )
+ $firstLetter = $hundredkmN < 5
+ ? ( $hundredkmE < 5 ? "S" : "T" )
: ( $hundredkmN < 10 ? ( $hundredkmE < 5 ? "N" : "O" ) : "H" );
$secondLetter = "";
@@ -430,7 +419,6 @@ class OSRef {
return sprintf("%s%s%03d%03d", $firstLetter, $secondLetter, $e, $n);
}
-
/**
* Convert this grid reference into a latitude and longitude
*
@@ -522,7 +510,6 @@ class OSRef {
}
}
-
// ================================================================== UTMRef
class UTMRef {
@@ -532,7 +519,6 @@ class UTMRef {
public $latZone;
public $lngZone;
-
/**
* Create a new object representing a UTM reference.
*
@@ -548,7 +534,6 @@ class UTMRef {
$this->lngZone = $lngZone;
}
-
/**
* Return a string representation of this UTM reference
*
@@ -558,7 +543,6 @@ class UTMRef {
return "{$this->lngZone}{$this->latZone} {$this->easting} {$this->northing}";
}
-
/**
* Convert this UTM reference to a latitude and longitude
*
@@ -611,7 +595,7 @@ class UTMRef {
* (1.0 - $eSquared)
/ pow(
1.0 - $eSquared * sin($phi1Rad) * sin($phi1Rad),
- 1.5);
+ 1.5, );
$d = $x / ($n * $UTM_F0);
$latitude = (
@@ -649,10 +633,9 @@ class UTMRef {
$latlog = new LatLng($latitude, $longitude);
return $latlog->toString();
- }
+ }
}
-
// ================================================================== RefEll
class RefEll {
@@ -661,7 +644,6 @@ class UTMRef {
public $min;
public $ecc;
-
/**
* Create a new RefEll object to represent a reference ellipsoid
*
@@ -675,7 +657,6 @@ class UTMRef {
}
}
-
// ================================================== Mathematical Functions
function sinSquared($x) {
@@ -694,7 +675,6 @@ function sec($x) {
return 1.0 / cos($x);
}
-
/**
* Take a string formatted as a six-figure OS grid reference (e.g.
* "TG514131") and return a reference to an OSRef object that represents
@@ -734,7 +714,6 @@ function getOSRefFromSixFigureReference($ref) {
return $osref->toString();
}
-
/**
* Work out the UTM latitude zone from the latitude
*
diff --git a/lib/test-2.3.php b/lib/test-2.3.php
index c9edc8b..87f6ac9 100755
--- a/lib/test-2.3.php
+++ b/lib/test-2.3.php
@@ -17,7 +17,6 @@
// - Added OSGB36/WGS84 data conversions
// 1.0 - 11 Aug 2005 // - Initial version //--------------------------------------------------------------------------
-
require_once("phpcoord-2.3.php");
?>
@@ -46,13 +45,13 @@ $d = $lld1->distance($lld2);
echo "Surface Distance between New York and London: " . $d . "km";</pre>
<?php
- $lld1 = new LatLng(40.718119, -73.995667); // New York
- echo "New York Lat/Long: " . $lld1->toString() . "<br />";
- $lld2 = new LatLng(51.499981, -0.125313); // London
- echo "London Lat/Long: " . $lld2->toString() . "<br />";
- $d = $lld1->distance($lld2);
- echo "Surface Distance between New York and London: " . $d . "km";
- ?>
+ $lld1 = new LatLng(40.718119, -73.995667); // New York
+ echo "New York Lat/Long: " . $lld1->toString() . "<br />";
+ $lld2 = new LatLng(51.499981, -0.125313); // London
+ echo "London Lat/Long: " . $lld2->toString() . "<br />";
+ $d = $lld1->distance($lld2);
+ echo "Surface Distance between New York and London: " . $d . "km";
+ ?>
</p>
<h2>Convert OS Grid Reference to Latitude/Longitude</h2>
@@ -72,11 +71,11 @@ $ll1 = $os1->toLatLng();
echo "Converted to Lat/Long: " . $ll1->toString();</pre>
<?php
- $os1 = new OSRef(651409.903, 313177.270);
- echo "OS Grid Reference: " . $os1->toString() . " - " . $os1->toSixFigureString() . "<br />";
- $ll1 = $os1->toLatLng();
- echo "Converted to Lat/Long: " . $ll1->toString();
- ?>
+ $os1 = new OSRef(651409.903, 313177.270);
+ echo "OS Grid Reference: " . $os1->toString() . " - " . $os1->toSixFigureString() . "<br />";
+ $ll1 = $os1->toLatLng();
+ echo "Converted to Lat/Long: " . $ll1->toString();
+ ?>
</p>
<p>
@@ -89,12 +88,12 @@ $l1w->OSGB36ToWGS84();
echo "Converted to Lat/Long: " . $ll1w->toString();</pre>
<?php
- $os1w = new OSRef(651409.903, 313177.270);
- echo "OS Grid Reference: " . $os1w->toString() . " - " . $os1w->toSixFigureString() . "<br />";
- $ll1w = $os1w->toLatLng();
- $ll1w->OSGB36ToWGS84();
- echo "Converted to Lat/Long: " . $ll1w->toString();
- ?>
+ $os1w = new OSRef(651409.903, 313177.270);
+ echo "OS Grid Reference: " . $os1w->toString() . " - " . $os1w->toSixFigureString() . "<br />";
+ $ll1w = $os1w->toLatLng();
+ $ll1w->OSGB36ToWGS84();
+ echo "Converted to Lat/Long: " . $ll1w->toString();
+ ?>
</p>
<h2>Convert Latitude/Longitude to OS Grid Reference</h2>
@@ -114,11 +113,11 @@ $os2 = $ll2->toOSRef();
echo "Converted to OS Grid Ref: " . $os2->toString() . " - " . $os2->toSixFigureString();</pre>
<?php
- $ll2 = new LatLng(52.657570301933, 1.7179215806451);
- echo "Latitude/Longitude: " . $ll2->toString() . "<br />";
- $os2 = $ll2->toOSRef();
- echo "Converted to OS Grid Ref: " . $os2->toString() . " - " . $os2->toSixFigureString();
- ?>
+ $ll2 = new LatLng(52.657570301933, 1.7179215806451);
+ echo "Latitude/Longitude: " . $ll2->toString() . "<br />";
+ $os2 = $ll2->toOSRef();
+ echo "Converted to OS Grid Ref: " . $os2->toString() . " - " . $os2->toSixFigureString();
+ ?>
</p>
<p>
@@ -131,12 +130,12 @@ $os2w = $ll2w->toOSRef();
echo "Converted to OS Grid Ref: " . $os2w->toString() . " - " . $os2w->toSixFigureString();</pre>
<?php
- $ll2w = new LatLng(52.657570301933, 1.7179215806451);
- echo "Latitude/Longitude: " . $ll2->toString() . "<br />";
- $ll2w->WGS84ToOSGB36();
- $os2w = $ll2w->toOSRef();
- echo "Converted to OS Grid Ref: " . $os2w->toString() . " - " . $os2w->toSixFigureString();
- ?>
+ $ll2w = new LatLng(52.657570301933, 1.7179215806451);
+ echo "Latitude/Longitude: " . $ll2->toString() . "<br />";
+ $ll2w->WGS84ToOSGB36();
+ $os2w = $ll2w->toOSRef();
+ echo "Converted to OS Grid Ref: " . $os2w->toString() . " - " . $os2w->toSixFigureString();
+ ?>
</p>
<h2>Convert Six-Figure OS Grid Reference String to an OSRef Object</h2>
@@ -150,11 +149,11 @@ $os6x = getOSRefFromSixFigureReference($os6);
echo "Converted to OS Grid Ref: " . $os6x->toString() . " - " . $os6x->toSixFigureString();</pre>
<?php
- $os6 = "TG514131";
- echo "Six figure string: " . $os6 . "<br />";
- $os6x = getOSRefFromSixFigureReference($os6);
- echo "Converted to OS Grid Ref: " . $os6x->toString() . " - " . $os6x->toSixFigureString();
- ?>
+ $os6 = "TG514131";
+ echo "Six figure string: " . $os6 . "<br />";
+ $os6x = getOSRefFromSixFigureReference($os6);
+ echo "Converted to OS Grid Ref: " . $os6x->toString() . " - " . $os6x->toSixFigureString();
+ ?>
</p>
<h2>Convert UTM Reference to Latitude/Longitude</h2>
@@ -166,11 +165,11 @@ $ll3 = $utm1->toLatLng();
echo "Converted to Lat/Long: " . $ll3->toString();</pre>
<?php
- $utm1 = new UTMRef(456463.99, 3335334.05, "E", 12);
- echo "UTM Reference: " . $utm1->toString() . "<br />";
- $ll3 = $utm1->toLatLng();
- echo "Converted to Lat/Long: " . $ll3->toString();
- ?>
+ $utm1 = new UTMRef(456463.99, 3335334.05, "E", 12);
+ echo "UTM Reference: " . $utm1->toString() . "<br />";
+ $ll3 = $utm1->toLatLng();
+ echo "Converted to Lat/Long: " . $ll3->toString();
+ ?>
</p>
<h2>Convert Latitude/Longitude to UTM Reference</h2>
@@ -182,11 +181,11 @@ $utm2 = $ll4->toUTMRef();
echo "Converted to UTM Ref: " . $utm2->toString() ;</pre>
<?php
- $ll4 = new LatLng(-60.1167, -111.7833);
- echo "Latitude/Longitude: " . $ll4->toString() . "<br />";
- $utm2 = $ll4->toUTMRef();
- echo "Converted to UTM Ref: " . $utm2->toString() ;
- ?>
+ $ll4 = new LatLng(-60.1167, -111.7833);
+ echo "Latitude/Longitude: " . $ll4->toString() . "<br />";
+ $utm2 = $ll4->toUTMRef();
+ echo "Converted to UTM Ref: " . $utm2->toString() ;
+ ?>
</p>
<p>
diff --git a/list.php b/list.php
index 3a4f2e9..16b0955 100755
--- a/list.php
+++ b/list.php
@@ -52,4 +52,4 @@ $gBitSmarty->assign( 'listInfo', $listHash['listInfo'] );
$gBitSystem->setBrowserTitle("View Contacts List");
// Display the template
-$gBitSystem->display( 'bitpackage:contact/list.tpl', NULL, array( 'display_mode' => 'list' ));
+$gBitSystem->display( 'bitpackage:contact/list.tpl', NULL, [ 'display_mode' => 'list' ]);
diff --git a/list1.php b/list1.php
index 3df951b..dea1aaa 100755
--- a/list1.php
+++ b/list1.php
@@ -51,5 +51,5 @@ $gBitSmarty->assign( 'listInfo', $listHash['listInfo'] );
$gBitSystem->setBrowserTitle("View Contacts List");
// Display the template
-$gBitSystem->display( 'bitpackage:contact/list1.tpl', NULL, array( 'display_mode' => 'list' ));
+$gBitSystem->display( 'bitpackage:contact/list1.tpl', NULL, [ 'display_mode' => 'list' ]);
diff --git a/list2.php b/list2.php
index 3e661af..991b3ed 100755
--- a/list2.php
+++ b/list2.php
@@ -51,5 +51,5 @@ $gBitSmarty->assign( 'listInfo', $listHash['listInfo'] );
$gBitSystem->setBrowserTitle("View Contacts List");
// Display the template
-$gBitSystem->display( 'bitpackage:contact/list2.tpl', NULL, array( 'display_mode' => 'list' ));
+$gBitSystem->display( 'bitpackage:contact/list2.tpl', NULL, [ 'display_mode' => 'list' ]);
diff --git a/list_contacts.php b/list_contacts.php
index 39485f4..833638b 100755
--- a/list_contacts.php
+++ b/list_contacts.php
@@ -27,12 +27,11 @@ if ( empty( $_REQUEST["sort_mode"] ) ) {
$sort_mode = 'organisation_asc';
}
-// Get a list of Contacts
+// Get a list of Contacts
$contacts->getList( $_REQUEST );
$smarty->assign('listInfo', $_REQUEST['listInfo']);
$smarty->assign('list', $contacts);
-
// Display the template
-$gBitSystem->display( 'bitpackage:contact/list_contacts.tpl', NULL, array( 'display_mode' => 'list' ));
+$gBitSystem->display( 'bitpackage:contact/list_contacts.tpl', NULL, [ 'display_mode' => 'list' ]);
diff --git a/list_contracts.php b/list_contracts.php
index d3eef46..cf0d2b4 100755
--- a/list_contracts.php
+++ b/list_contracts.php
@@ -26,11 +26,11 @@ if ( !isset($_REQUEST['contract'])) {
$_REQUEST['contract'] = 0;
}
-// Get a list of Contracts
+// Get a list of Contracts
$contracts = $contacts->getContractList( $_REQUEST['contract'] );
$gBitSmarty->assign('listInfo', $_REQUEST['listInfo']);
$gBitSmarty->assign('list', $contracts);
// Display the template
-$gBitSystem->display( 'bitpackage:contact/list_contracts.tpl', NULL, array( 'display_mode' => 'list' ));
+$gBitSystem->display( 'bitpackage:contact/list_contracts.tpl', NULL, [ 'display_mode' => 'list' ]);
diff --git a/load_emails.php b/load_emails.php
index a3d8024..8726354 100755
--- a/load_emails.php
+++ b/load_emails.php
@@ -42,17 +42,17 @@ for ( $n = 0; $n < $mbox->size(); $n++ ) {
$message = $mbox->get( $n );
preg_match( '/Subject: (.*)$/m', $message, $matches );
- $subject = isset( $matches[1] ) ? $matches[1] : 'Not Set';$subject = 'Not Set';
+ $subject = $matches[1] ?? 'Not Set';$subject = 'Not Set';
// echo 'Mail #' . $n . ': ' . $subject . "<br>";
$Decoder = new Mail_mimeDecode( $message );
- $params = array(
+ $params = [
'include_bodies' => true,
'decode_bodies' => true,
'decode_headers' => true,
- );
+ ];
$Decoded = $Decoder->decode( $params );
if (strtolower( $Decoded->ctype_primary ) == "multipart") {
- // \Bitweaver\vd($Decoded->parts[0]->ctype_primary);
+ // \Bitweaver\vd($Decoded->parts[0]->ctype_primary);
$ctype_secondary = $Decoded->parts[0]->ctype_secondary;
if (strtolower( $Decoded->parts[0]->ctype_primary ) == "multipart") {
if (!empty( $Decoded->parts[0]->parts[0]->body )) {
@@ -65,7 +65,7 @@ for ( $n = 0; $n < $mbox->size(); $n++ ) {
}
}
else if (strtolower( $Decoded->ctype_primary ) == "text") {
- // \Bitweaver\vd($Decoded->ctype_primary);
+ // \Bitweaver\vd($Decoded->ctype_primary);
$ctype_secondary = $Decoded->ctype_secondary;
if (!empty( $Decoded->body )) {
$body = $Decoded->body;
@@ -135,7 +135,7 @@ for ( $n = 0; $n < $mbox->size(); $n++ ) {
$pattern = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
// preg match all in the string
preg_match_all( $pattern, $Decoded->headers['from'], $emails );
- if ( !empty($emails[0]) ) {
+ if ( !empty($emails[0]) ) {
if ( $emails[0][0] == 'lester@lsces.co.uk' ) {
preg_match_all( $pattern, $Decoded->headers['to'], $to_emails );
}
@@ -155,8 +155,8 @@ for ( $n = 0; $n < $mbox->size(); $n++ ) {
$table = BIT_DB_PREFIX . "contact_email";
$email['email_store']['end_date'] = strtotime( $dateTime->format( DATE_ATOM ) );
- $result = $storeComment->mDb->associateUpdate( $table, $email['email_store'], array( "email" => $from_emails[0] ) );
- } else {
+ $result = $storeComment->mDb->associateUpdate( $table, $email['email_store'], [ "email" => $from_emails[0] ] );
+ } else {
$table = BIT_DB_PREFIX . "contact_email";
$email['email_store']['email'] = $from_emails[0];
$email['email_store']['start_date'] = strtotime( $dateTime->format( DATE_ATOM ) );
@@ -179,7 +179,7 @@ $mbox->close();
if ($gContent->isCommentable()) {
$commentsParentId = $gContent->mContentId;
- $comments_vars = array( 'contact' );
+ $comments_vars = [ 'contact' ];
$comments_prefix_var = 'contact:';
$comments_object_var = 'contact';
$comments_return_url = $_SERVER['PHP_SELF'] . "?content_id=" . $gContent->mContentId;
diff --git a/load_sage_contacts.php b/load_sage_contacts.php
index b904adc..85ea294 100755
--- a/load_sage_contacts.php
+++ b/load_sage_contacts.php
@@ -28,8 +28,8 @@ if ( $handle == FALSE) {
$row = -999;
} else {
while (($data = fgetcsv($handle, 800, ",")) !== FALSE) {
- if ( $row ) $contact->SageRecordLoad( $data, 1 );
- $row++;
+ if ( $row ) $contact->SageRecordLoad( $data, 1 );
+ $row++;
}
fclose($handle);
}
@@ -42,8 +42,8 @@ if ( $handle == FALSE) {
$row = -999;
} else {
while (($data = fgetcsv($handle, 800, ",")) !== FALSE) {
- if ( $row ) $contact->SageRecordLoad( $data, 2 );
- $row++;
+ if ( $row ) $contact->SageRecordLoad( $data, 2 );
+ $row++;
}
fclose($handle);
}
diff --git a/modules/index.php b/modules/index.php
index 3e305fe..c0437d0 100755
--- a/modules/index.php
+++ b/modules/index.php
@@ -1,4 +1,4 @@
-<?php
+<?php
// This is not a package.
header ("location: ../index.php");
diff --git a/process.php b/process.php
index b8271f7..7e00d6b 100755
--- a/process.php
+++ b/process.php
@@ -47,11 +47,11 @@ if (isset($_REQUEST["fCancel"])) {
$formInfo = $_REQUEST;
$formInfo['data'] = &$_REQUEST['edit'];
}
-}
+}
// formInfo might be set due to a error on submit
if( empty( $formInfo ) ) {
// $formInfo = &$gContent->mInfo;
}
-$gBitSystem->display( 'bitpackage:contact/employment.tpl', 'Edit: ' , array( 'display_mode' => 'edit' ));
+$gBitSystem->display( 'bitpackage:contact/employment.tpl', 'Edit: ' , [ 'display_mode' => 'edit' ]);
diff --git a/templates/index.php b/templates/index.php
index 3e305fe..c0437d0 100755
--- a/templates/index.php
+++ b/templates/index.php
@@ -1,4 +1,4 @@
-<?php
+<?php
// This is not a package.
header ("location: ../index.php");
diff --git a/view_xref.php b/view_xref.php
index 964cdbd..4393cf9 100755
--- a/view_xref.php
+++ b/view_xref.php
@@ -35,11 +35,11 @@ if (isset($_REQUEST["fCancel"])) {
if( $gContent->storeXref( $_REQUEST ) ) {
header("Location: ".$gContent->getDisplayUrl() );
die;
- } else {
+ }
$xrefInfo = $_REQUEST;
$xrefInfo['data'] = &$_REQUEST['edit'];
- }
-}
+
+}
// formInfo might be set due to a error on submit
if( empty( $xrefInfo ) ) {
@@ -52,7 +52,7 @@ $gBitSmarty->assign( 'xref_title', $gContent->mInfo['xref_title'] );
$gBitSmarty->assign( 'errors', $gContent->mErrors );
if( isset($xrefInfo['template']) ) {
- $gBitSystem->display( 'bitpackage:contact/view_xref_'.$xrefInfo['template'].'.tpl', 'View: ' , array( 'display_mode' => 'view' ));
+ $gBitSystem->display( 'bitpackage:contact/view_xref_'.$xrefInfo['template'].'.tpl', 'View: ' , [ 'display_mode' => 'view' ]);
} else {
- $gBitSystem->display( 'bitpackage:contact/view_xref.tpl', 'View: ' , array( 'display_mode' => 'view' ));
+ $gBitSystem->display( 'bitpackage:contact/view_xref.tpl', 'View: ' , [ 'display_mode' => 'view' ]);
}