source: temp/branches/mobile/data/class/GC_MobileKaraMail.php @ 11406

Revision 11406, 4.2 KB checked in by rebelt, 17 years ago (diff)

以下のモバイルサイト用ページ・機能を作成いたしました。

  • ログイン
  • パスワードを忘れた方
  • ご利用ガイド
  • お問い合せ
  • 空メール機能
  • Property svn:eol-style set to native
Line 
1<?php
2
3/**
4 * ¶õ¥á¡¼¥ë¼õ¤±ÉÕ¤±¥¢¥É¥ì¥¹¤Î¥³¥Þ¥ó¥É̾¤È¥È¡¼¥¯¥ó¤Î´Ö¤Î¶èÀÚ¤êʸ»ú
5 */
6define('MOBILE_KARA_MAIL_EXTENSION_DELIMITER', '_');
7
8/**
9 * ¥â¥Ð¥¤¥ë¥µ¥¤¥È¤Î¶õ¥á¡¼¥ë¤ò°·¤¦¥¯¥é¥¹
10 */
11class GC_MobileKaraMail {
12    /**
13     * ´Ä¶­ÊÑ¿ô¤«¤é MTA ¤òȽÊ̤·¡¢Âбþ¤¹¤ë GC_MobileKaraMail ¤Þ¤¿¤Ï¤½¤Î¥µ¥Ö¥¯¥é¥¹
14     * ¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òºîÀ®¤¹¤ë¡£
15     *
16     * @return object GC_MobileKaraMail ¤Þ¤¿¤Ï¤½¤Î¥µ¥Ö¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òÊÖ¤¹¡£
17     */
18    function &factory() {
19        if (isset($_ENV['EXTENSION'])) {
20            $objInstance = new GC_MobileKaraMail_Postfix;
21        } elseif (isset($_ENV['DEFAULT'])) {
22            $objInstance = new GC_MobileKaraMail_Qmail;
23        } else {
24            $objInstance = new GC_MobileKaraMail;
25        }
26
27        return $objInstance;
28    }
29
30    /**
31     * ɸ½àÆþÎϤ«¤é¥á¡¼¥ë¤òÆɤ߹þ¤ß¡¢É¬ÍפʾðÊó¤ò¼èÆÀ¤¹¤ë¡£
32     *
33     * @return void
34     */
35    function parse() {
36        if (@$this->parsed) {
37            return;
38        }
39
40        require_once DATA_PATH . '/module/Mail/mimeDecode.php';
41
42        $fp = fopen('php://stdin', 'r');
43
44        // From ¹Ô¤ò²òÀϤ¹¤ë¡£
45        $from_line = rtrim(fgets($fp));
46        if (preg_match('/^From\\s+"?([^\\s"@]+)"?@([^\\s@]+)/', $from_line, $matches)) {
47            $this->sender = $matches[1] . '@' . $matches[2];
48        } else {
49            trigger_error("Invalid from line: $from_line");
50            $this->sender = null;
51        }
52
53        // »Ä¤ê¤Î¥Ø¥Ã¥À¡¼¤ò²òÀϤ¹¤ë¡£
54        $data = '';
55        while (!feof($fp)) {
56            $data .= fgets($fp);
57            if (rtrim($data, "\r\n") == '') {
58                break;
59            }
60        }
61        $structure = Mail_mimeDecode::decode(array('input' => $data));
62        $this->recipient = @$structure->headers['to'];
63
64        // °¸À襢¥É¥ì¥¹¤«¤é³ÈÄ¥Éôʬ¤ò¼èÆÀ¤¹¤ë¡£
65        $pos = strpos($this->recipient, MOBILE_KARA_MAIL_ADDRESS_DELIMITER);
66        if ($pos !== false) {
67            $extension_and_domain = substr($this->recipient, $pos + 1);
68            $pos = strpos($extension_and_domain, '@');
69            if ($pos !== false) {
70                $this->extension = substr($extension_and_domain, 0, $pos);
71            } else {
72                $this->extension = $extension_and_domain;
73            }
74        } else {
75            trigger_error("Invalid recipient: {$this->recipient}");
76            $this->extension = null;
77        }
78
79        $this->parsed = true;
80    }
81
82    /**
83     * ÇÛ¿®¤¬´°Î»¤·¤¿¤³¤È¤ò¼¨¤¹½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤Ç¥×¥í¥°¥é¥à¤ò½ªÎ»¤¹¤ë¡£
84     *
85     * @return void
86     */
87    function success() {
88        exit(0);
89    }
90
91    /**
92     * °ì»þŪ¤Ê¥¨¥é¡¼¤ò¼¨¤¹½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤Ç¥×¥í¥°¥é¥à¤ò½ªÎ»¤¹¤ë¡£
93     *
94     * @return void
95     */
96    function temporaryFailure() {
97        exit(75);
98    }
99
100    /**
101     * Á÷¿®¼Ô¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤ò¼èÆÀ¤¹¤ë¡£
102     *
103     * parse() ¼Â¹Ô¸å¤Ë»ÈÍѤ¹¤ë¤³¤È¡£
104     *
105     * @return string|false Á÷¿®¼Ô¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤òÊÖ¤¹¡£¼èÆÀ¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï false ¤òÊÖ¤¹¡£
106     */
107    function getSender() {
108        return isset($this->sender) ? $this->sender : false;
109    }
110
111    /**
112     * °¸Àè¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤Î³ÈÄ¥Éôʬ¤«¤é¥³¥Þ¥ó¥É̾¤ò¼èÆÀ¤¹¤ë¡£
113     *
114     * parse() ¼Â¹Ô¸å¤Ë»ÈÍѤ¹¤ë¤³¤È¡£
115     *
116     * @return string|false ¥³¥Þ¥ó¥É̾¤òÊÖ¤¹¡£¼èÆÀ¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï false ¤òÊÖ¤¹¡£
117     */
118    function getCommand() {
119        if (!isset($this->extension)) {
120            return false;
121        }
122
123        $pos = strpos($this->extension, MOBILE_KARA_MAIL_EXTENSION_DELIMITER);
124        if ($pos === false) {
125            return false;
126        }
127
128        return substr($this->extension, 0, $pos);
129    }
130
131    /**
132     * °¸Àè¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤Î³ÈÄ¥Éôʬ¤«¤é¥È¡¼¥¯¥ó¤ò¼èÆÀ¤¹¤ë¡£
133     *
134     * parse() ¼Â¹Ô¸å¤Ë»ÈÍѤ¹¤ë¤³¤È¡£
135     *
136     * @return string|false ¥È¡¼¥¯¥ó¤òÊÖ¤¹¡£¼èÆÀ¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï false ¤òÊÖ¤¹¡£
137     */
138    function getToken() {
139        if (!isset($this->extension)) {
140            return false;
141        }
142
143        $pos = strpos($this->extension, MOBILE_KARA_MAIL_EXTENSION_DELIMITER);
144        if ($pos === false) {
145            return false;
146        }
147
148        return substr($this->extension, $pos + 1);
149    }
150}
151
152/**
153 * ¥â¥Ð¥¤¥ë¥µ¥¤¥È¤Î¶õ¥á¡¼¥ë¤ò°·¤¦¥¯¥é¥¹ (PostfixÍÑ)
154 */
155class GC_MobileKaraMail_Postfix extends GC_MobileKaraMail {
156    /**
157     * @see GC_MobileKaraMail::parse()
158     */
159    function parse() {
160        if (@$this->parsed) {
161            return;
162        }
163
164        $this->sender = $_ENV['SENDER'];
165        $this->recipient = $_ENV['RECIPIENT'];
166        $this->extension = $_ENV['EXTENSION'];
167
168        $this->parsed = true;
169    }
170}
171
172/**
173 * ¥â¥Ð¥¤¥ë¥µ¥¤¥È¤Î¶õ¥á¡¼¥ë¤ò°·¤¦¥¯¥é¥¹ (qmailÍÑ)
174 */
175class GC_MobileKaraMail_Qmail extends GC_MobileKaraMail {
176    /**
177     * @see GC_MobileKaraMail::parse()
178     */
179    function parse() {
180        if (@$this->parsed) {
181            return;
182        }
183
184        $this->sender = $_ENV['SENDER'];
185        $this->recipient = $_ENV['RECIPIENT'];
186        $this->extension = $_ENV['DEFAULT'];
187
188        $this->parsed = true;
189    }
190
191    /**
192     * °ì»þŪ¤Ê¥¨¥é¡¼¤ò¼¨¤¹½ªÎ»¥¹¥Æ¡¼¥¿¥¹¤Ç¥×¥í¥°¥é¥à¤ò½ªÎ»¤¹¤ë¡£
193     *
194     * @return void
195     */
196    function temporaryFailure() {
197        exit(111);
198    }
199}
200?>
Note: See TracBrowser for help on using the repository browser.