- Timestamp:
- 2007/10/29 12:06:29 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/SC_MobileKaraMail.php
r16329 r16582 1 1 <?php 2 /** 3 * 2 /* 3 * This file is part of EC-CUBE 4 * 4 5 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. 5 6 * 6 7 * http://www.lockon.co.jp/ 7 * 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * as published by the Free Software Foundation; either version 2 12 * of the License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * 8 23 * 空メール受け付けアドレスのコマンド名とトークンの間の区切り文字 9 24 */ … … 14 29 */ 15 30 class SC_MobileKaraMail { 16 /**17 * 環境変数から MTA を判別し、対応する SC_MobileKaraMail またはそのサブクラス18 * のインスタンスを作成する。19 *20 * @return object SC_MobileKaraMail またはそのサブクラスのインスタンスを返す。21 */22 function &factory() {23 if (isset($_ENV['EXTENSION'])) {24 $objInstance = new SC_MobileKaraMail_Postfix;25 } elseif (isset($_ENV['DEFAULT'])) {26 $objInstance = new SC_MobileKaraMail_Qmail;27 } else {28 $objInstance = new SC_MobileKaraMail;29 }30 31 return $objInstance;32 }33 34 /**35 * 標準入力からメールを読み込み、必要な情報を取得する。36 *37 * @return void38 */39 function parse() {40 if (@$this->parsed) {41 return;42 }43 44 require_once DATA_PATH . '/module/Mail/mimeDecode.php';45 46 $fp = fopen('php://stdin', 'r');47 48 // From 行を解析する。49 $from_line = rtrim(fgets($fp));50 if (preg_match('/^From\\s+"?([^\\s"@]+)"?@([^\\s@]+)/', $from_line, $matches)) {51 $this->sender = $matches[1] . '@' . $matches[2];52 } else {53 trigger_error("Invalid from line: $from_line");54 $this->sender = null;55 }56 57 // 残りのヘッダーを解析する。58 $data = '';59 while (!feof($fp)) {60 $data .= fgets($fp);61 if (rtrim($data, "\r\n") == '') {62 break;63 }64 }65 $structure = Mail_mimeDecode::decode(array('input' => $data));66 $this->recipient = @$structure->headers['to'];67 68 // 宛先アドレスから拡張部分を取得する。69 $pos = strpos($this->recipient, MOBILE_KARA_MAIL_ADDRESS_DELIMITER);70 if ($pos !== false) {71 $extension_and_domain = substr($this->recipient, $pos + 1);72 $pos = strpos($extension_and_domain, '@');73 if ($pos !== false) {74 $this->extension = substr($extension_and_domain, 0, $pos);75 } else {76 $this->extension = $extension_and_domain;77 }78 } else {79 trigger_error("Invalid recipient: {$this->recipient}");80 $this->extension = null;81 }82 83 $this->parsed = true;84 }85 86 /**87 * 配信が完了したことを示す終了ステータスでプログラムを終了する。88 *89 * @return void90 */91 function success() {92 exit(0);93 }94 95 /**96 * 一時的なエラーを示す終了ステータスでプログラムを終了する。97 *98 * @return void99 */100 function temporaryFailure() {101 exit(75);102 }103 104 /**105 * 送信者のメールアドレスを取得する。106 *107 * parse() 実行後に使用すること。108 *109 * @return string|false 送信者のメールアドレスを返す。取得できなかった場合は false を返す。110 */111 function getSender() {112 return isset($this->sender) ? $this->sender : false;113 }114 115 /**116 * 宛先のメールアドレスの拡張部分からコマンド名を取得する。117 *118 * parse() 実行後に使用すること。119 *120 * @return string|false コマンド名を返す。取得できなかった場合は false を返す。121 */122 function getCommand() {123 if (!isset($this->extension)) {124 return false;125 }126 127 $pos = strpos($this->extension, MOBILE_KARA_MAIL_EXTENSION_DELIMITER);128 if ($pos === false) {129 return false;130 }131 132 return substr($this->extension, 0, $pos);133 }134 135 /**136 * 宛先のメールアドレスの拡張部分からトークンを取得する。137 *138 * parse() 実行後に使用すること。139 *140 * @return string|false トークンを返す。取得できなかった場合は false を返す。141 */142 function getToken() {143 if (!isset($this->extension)) {144 return false;145 }146 147 $pos = strpos($this->extension, MOBILE_KARA_MAIL_EXTENSION_DELIMITER);148 if ($pos === false) {149 return false;150 }151 152 return substr($this->extension, $pos + 1);153 }31 /** 32 * 環境変数から MTA を判別し、対応する SC_MobileKaraMail またはそのサブクラス 33 * のインスタンスを作成する。 34 * 35 * @return object SC_MobileKaraMail またはそのサブクラスのインスタンスを返す。 36 */ 37 function &factory() { 38 if (isset($_ENV['EXTENSION'])) { 39 $objInstance = new SC_MobileKaraMail_Postfix; 40 } elseif (isset($_ENV['DEFAULT'])) { 41 $objInstance = new SC_MobileKaraMail_Qmail; 42 } else { 43 $objInstance = new SC_MobileKaraMail; 44 } 45 46 return $objInstance; 47 } 48 49 /** 50 * 標準入力からメールを読み込み、必要な情報を取得する。 51 * 52 * @return void 53 */ 54 function parse() { 55 if (@$this->parsed) { 56 return; 57 } 58 59 require_once DATA_PATH . '/module/Mail/mimeDecode.php'; 60 61 $fp = fopen('php://stdin', 'r'); 62 63 // From 行を解析する。 64 $from_line = rtrim(fgets($fp)); 65 if (preg_match('/^From\\s+"?([^\\s"@]+)"?@([^\\s@]+)/', $from_line, $matches)) { 66 $this->sender = $matches[1] . '@' . $matches[2]; 67 } else { 68 trigger_error("Invalid from line: $from_line"); 69 $this->sender = null; 70 } 71 72 // 残りのヘッダーを解析する。 73 $data = ''; 74 while (!feof($fp)) { 75 $data .= fgets($fp); 76 if (rtrim($data, "\r\n") == '') { 77 break; 78 } 79 } 80 $structure = Mail_mimeDecode::decode(array('input' => $data)); 81 $this->recipient = @$structure->headers['to']; 82 83 // 宛先アドレスから拡張部分を取得する。 84 $pos = strpos($this->recipient, MOBILE_KARA_MAIL_ADDRESS_DELIMITER); 85 if ($pos !== false) { 86 $extension_and_domain = substr($this->recipient, $pos + 1); 87 $pos = strpos($extension_and_domain, '@'); 88 if ($pos !== false) { 89 $this->extension = substr($extension_and_domain, 0, $pos); 90 } else { 91 $this->extension = $extension_and_domain; 92 } 93 } else { 94 trigger_error("Invalid recipient: {$this->recipient}"); 95 $this->extension = null; 96 } 97 98 $this->parsed = true; 99 } 100 101 /** 102 * 配信が完了したことを示す終了ステータスでプログラムを終了する。 103 * 104 * @return void 105 */ 106 function success() { 107 exit(0); 108 } 109 110 /** 111 * 一時的なエラーを示す終了ステータスでプログラムを終了する。 112 * 113 * @return void 114 */ 115 function temporaryFailure() { 116 exit(75); 117 } 118 119 /** 120 * 送信者のメールアドレスを取得する。 121 * 122 * parse() 実行後に使用すること。 123 * 124 * @return string|false 送信者のメールアドレスを返す。取得できなかった場合は false を返す。 125 */ 126 function getSender() { 127 return isset($this->sender) ? $this->sender : false; 128 } 129 130 /** 131 * 宛先のメールアドレスの拡張部分からコマンド名を取得する。 132 * 133 * parse() 実行後に使用すること。 134 * 135 * @return string|false コマンド名を返す。取得できなかった場合は false を返す。 136 */ 137 function getCommand() { 138 if (!isset($this->extension)) { 139 return false; 140 } 141 142 $pos = strpos($this->extension, MOBILE_KARA_MAIL_EXTENSION_DELIMITER); 143 if ($pos === false) { 144 return false; 145 } 146 147 return substr($this->extension, 0, $pos); 148 } 149 150 /** 151 * 宛先のメールアドレスの拡張部分からトークンを取得する。 152 * 153 * parse() 実行後に使用すること。 154 * 155 * @return string|false トークンを返す。取得できなかった場合は false を返す。 156 */ 157 function getToken() { 158 if (!isset($this->extension)) { 159 return false; 160 } 161 162 $pos = strpos($this->extension, MOBILE_KARA_MAIL_EXTENSION_DELIMITER); 163 if ($pos === false) { 164 return false; 165 } 166 167 return substr($this->extension, $pos + 1); 168 } 154 169 } 155 170 … … 158 173 */ 159 174 class SC_MobileKaraMail_Postfix extends SC_MobileKaraMail { 160 /**161 * @see SC_MobileKaraMail::parse()162 */163 function parse() {164 if (@$this->parsed) {165 return;166 }167 168 $this->sender = $_ENV['SENDER'];169 $this->recipient = $_ENV['RECIPIENT'];170 $this->extension = $_ENV['EXTENSION'];171 172 $this->parsed = true;173 }175 /** 176 * @see SC_MobileKaraMail::parse() 177 */ 178 function parse() { 179 if (@$this->parsed) { 180 return; 181 } 182 183 $this->sender = $_ENV['SENDER']; 184 $this->recipient = $_ENV['RECIPIENT']; 185 $this->extension = $_ENV['EXTENSION']; 186 187 $this->parsed = true; 188 } 174 189 } 175 190 … … 178 193 */ 179 194 class SC_MobileKaraMail_Qmail extends SC_MobileKaraMail { 180 /**181 * @see SC_MobileKaraMail::parse()182 */183 function parse() {184 if (@$this->parsed) {185 return;186 }187 188 $this->sender = $_ENV['SENDER'];189 $this->recipient = $_ENV['RECIPIENT'];190 $this->extension = $_ENV['DEFAULT'];191 192 $this->parsed = true;193 }194 195 /**196 * 一時的なエラーを示す終了ステータスでプログラムを終了する。197 *198 * @return void199 */200 function temporaryFailure() {201 exit(111);202 }195 /** 196 * @see SC_MobileKaraMail::parse() 197 */ 198 function parse() { 199 if (@$this->parsed) { 200 return; 201 } 202 203 $this->sender = $_ENV['SENDER']; 204 $this->recipient = $_ENV['RECIPIENT']; 205 $this->extension = $_ENV['DEFAULT']; 206 207 $this->parsed = true; 208 } 209 210 /** 211 * 一時的なエラーを示す終了ステータスでプログラムを終了する。 212 * 213 * @return void 214 */ 215 function temporaryFailure() { 216 exit(111); 217 } 203 218 } 204 219 ?>
Note: See TracChangeset
for help on using the changeset viewer.
