source: branches/feature-module-paygent/data/class/GC_MobileKaraMail.php @ 11686

Revision 11686, 4.3 KB checked in by uehara, 17 years ago (diff)
  • Property svn:eol-style set to native
Line 
1<?php
2/**
3 *
4 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
5 *
6 * http://www.lockon.co.jp/
7 *
8 * ¶õ¥á¡¼¥ë¼õ¤±ÉÕ¤±¥¢¥É¥ì¥¹¤Î¥³¥Þ¥ó¥É̾¤È¥È¡¼¥¯¥ó¤Î´Ö¤Î¶èÀÚ¤êʸ»ú
9 */
10define('MOBILE_KARA_MAIL_EXTENSION_DELIMITER', '_');
11
12/**
13 * ¥â¥Ð¥¤¥ë¥µ¥¤¥È¤Î¶õ¥á¡¼¥ë¤ò°·¤¦¥¯¥é¥¹
14 */
15class GC_MobileKaraMail {
16    /**
17     * ´Ä¶­ÊÑ¿ô¤«¤é MTA ¤òȽÊ̤·¡¢Âбþ¤¹¤ë GC_MobileKaraMail ¤Þ¤¿¤Ï¤½¤Î¥µ¥Ö¥¯¥é¥¹
18     * ¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òºîÀ®¤¹¤ë¡£
19     *
20     * @return object GC_MobileKaraMail ¤Þ¤¿¤Ï¤½¤Î¥µ¥Ö¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òÊÖ¤¹¡£
21     */
22    function &factory() {
23        if (isset($_ENV['EXTENSION'])) {
24            $objInstance = new GC_MobileKaraMail_Postfix;
25        } elseif (isset($_ENV['DEFAULT'])) {
26            $objInstance = new GC_MobileKaraMail_Qmail;
27        } else {
28            $objInstance = new GC_MobileKaraMail;
29        }
30
31        return $objInstance;
32    }
33
34    /**
35     * ɸ½àÆþÎϤ«¤é¥á¡¼¥ë¤òÆɤ߹þ¤ß¡¢É¬ÍפʾðÊó¤ò¼èÆÀ¤¹¤ë¡£
36     *
37     * @return void
38     */
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 void
90     */
91    function success() {
92        exit(0);
93    }
94
95    /**
96     * °ì»þŪ¤Ê¥¨¥é¡¼¤ò¼¨¤¹½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤Ç¥×¥í¥°¥é¥à¤ò½ªÎ»¤¹¤ë¡£
97     *
98     * @return void
99     */
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    }
154}
155
156/**
157 * ¥â¥Ð¥¤¥ë¥µ¥¤¥È¤Î¶õ¥á¡¼¥ë¤ò°·¤¦¥¯¥é¥¹ (PostfixÍÑ)
158 */
159class GC_MobileKaraMail_Postfix extends GC_MobileKaraMail {
160    /**
161     * @see GC_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    }
174}
175
176/**
177 * ¥â¥Ð¥¤¥ë¥µ¥¤¥È¤Î¶õ¥á¡¼¥ë¤ò°·¤¦¥¯¥é¥¹ (qmailÍÑ)
178 */
179class GC_MobileKaraMail_Qmail extends GC_MobileKaraMail {
180    /**
181     * @see GC_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 void
199     */
200    function temporaryFailure() {
201        exit(111);
202    }
203}
204?>
Note: See TracBrowser for help on using the repository browser.