| 1 | <?php
|
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 6 | * |
|---|
| 7 | * http://www.lockon.co.jp/ |
|---|
| 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 | *
|
|---|
| 23 | * 空メール受け付けアドレスのコマンド名とトークンの間の区切り文字
|
|---|
| 24 | */
|
|---|
| 25 | define('MOBILE_KARA_MAIL_EXTENSION_DELIMITER', '_');
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * モバイルサイトの空メールを扱うクラス
|
|---|
| 29 | */
|
|---|
| 30 | class SC_MobileKaraMail {
|
|---|
| 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 | }
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | /**
|
|---|
| 172 | * モバイルサイトの空メールを扱うクラス (Postfix用)
|
|---|
| 173 | */
|
|---|
| 174 | class SC_MobileKaraMail_Postfix extends SC_MobileKaraMail {
|
|---|
| 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 | }
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | /**
|
|---|
| 192 | * モバイルサイトの空メールを扱うクラス (qmail用)
|
|---|
| 193 | */
|
|---|
| 194 | class SC_MobileKaraMail_Qmail extends SC_MobileKaraMail {
|
|---|
| 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 | }
|
|---|
| 218 | }
|
|---|
| 219 | ?>
|
|---|