- Timestamp:
- 2007/10/29 12:06:29 (16 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 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 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 162 163 164 165 166 167 168 169 170 171 172 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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 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.