1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
<?php
/**
* Generic e-mail based SMS driver
*
* Copyright 2005-2007 WebSprockets, LLC
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* This driver interfaces with the email-to-sms gateways provided by many
* carriers, particularly those based in the U.S.
*
* $Horde: framework/Net_SMS/SMS/generic_smtp.php,v 1.8.2.9 2008/05/14 21:39:40 jan Exp $
*
* @category Networking
* @package Net_SMS
* @author Ian Eure <ieure@php.net>
* @since Horde 3.1
* @since Net_SMS 0.0.2
*/
class Net_SMS_generic_smtp extends Net_SMS {
/**
* Capabilities of this driver.
*
* @var array
*/
var $capabilities = array(
'auth' => false,
'batch' => false,
'multi' => false,
'receive' => false,
'credit' => false,
'addressbook' => false,
'lists' => false
);
/**
* Driver parameters.
*
* @var array
*
* @access private
*/
var $_params = array(
'carrier' => null,
'mailBackend' => 'mail',
'mailParams' => array(),
'mailHeaders' => array()
);
/**
* Carrier email map.
*
* @var array
*
* @access private
*/
var $_carriers = array(
/* U.S. carriers. */
'att' => '%s@mmode.com',
'cingular' => '%s@mmode.com',
'verizon' => '%s@vtext.com',
'boost' => '%s@myboostmobile.com',
'cellularone' => '%s@mycellone.net',
'cincybell' => '%s@gocbw.com',
'sprint' => '%s@messaging.sprintpcs.com',
'tmobile_us' => '%s@tmomail.com',
'suncom' => '%s@tms.suncom.com',
'aircel' => '%s@airsms.com',
'airtel' => '%s@airtelmail.com',
'bplmobile' => '%s@bplmobile.com',
'bellmobility' => '%s@txt.bellmobility.ca',
'bluegrass' => '%s@sms.bluecell.com',
'cellforce' => '%s@celforce.com',
'cellularone' => '%s@mycellone.net',
/* German carriers. */
'eplus' => '%s@smsmail.eplus.de',
'tmobile_de' => '%s@t-mobile-sms.de',
'vodafone_de' => '%s@vodafone-sms.de',
);
/**
* Identifies this driver.
*
* @return array Driver info.
*/
function getInfo()
{
return array(
'name' => _("Email-to-SMS Gateway"),
'desc' => _("This driver allows sending of messages through an email-to-SMS gateway, for carriers which provide this service.")
);
}
/**
* Returns required parameters.
*
* @return array Array of required parameters.
*/
function getParams()
{
return array(
'carrier' => array('label' => _("Carrier"), 'type' => 'text'),
'mailBackend' => array('label' => _("PEAR::Mail backend"), 'type' => 'text')
);
}
/**
* Sends the message.
*
* You may also specify the carrier with the 'carrier' key of the message
* to avoid creating a new instance for each carrier, or fiddling with the
* parameters.
*
* @access private
*
* @param array $message Message to send.
* @param string $to The recipient.
*
* @return array An array with the success status and additional
* information.
*/
function _send($message, $to)
{
require_once 'Mail.php';
$m = &Mail::factory($this->_params['mailBackend'],
$this->_params['mailParams']);
if (isset($message['carrier'])) {
$dest = $this->_getDest($to, $message['carrier']);
} else {
$dest = $this->_getDest($to);
}
$res = $m->send($dest, $this->_params['mailHeaders'], $message['text']);
if (PEAR::isError($res)) {
return array(0, $res->getMessage());
} else {
return array(1, null);
}
}
/**
* Returns destination e-mail address.
*
* @param string $phone Phone number to send to.
*
* @return string Destination address.
*/
function _getDest($phone, $carrier = null)
{
$carrier = is_null($carrier) ? $this->_params['carrier'] : $carrier;
return sprintf($this->_carriers[$carrier],
preg_replace('/[^0-9]/', '', $phone));
}
/**
* Returns the address template for a carrier.
*
* @param string $carrier Carrier name.
*
* @return mixed Address template or false.
*/
function getAddressTemplate($carrier)
{
if (!isset($this->_carriers[$carrier])) {
return false;
}
return $this->_carriers[$carrier];
}
/**
* Adds a carrier to the list.
*
* Address templates need to be in the form of an email address, with a
* '%s' representing the place where the destination phone number goes.
*
* @param string $name Carrier name.
* @param string $addr Address template.
*/
function addCarrier($name, $addr)
{
$this->_carriers[$name] = $addr;
}
/**
* Returns a list of parameters specific for this driver.
*
* @return array Default sending parameters.
*/
function getDefaultSendParams()
{
return array();
}
}
|