OSDN Git Service

bug fix
[immt/program.git] / imode.php
1 <?php
2 //=========================================================
3 //
4 // imodeメール転送 ver.1
5 // https://sourceforge.jp/projects/immt/
6 // 作者:Shohei Yokoyama (http://shohei.yokoyama.ac/)
7 // ライセンス:GPL v3
8 // ご利用はat own your riskで。
9 // 
10 //
11 //=========================================================
12
13 //--- ご自身のデータを入れてください
14 //imode.netのユーザ名(多分携帯電話番号)
15 $UID = "09000000000";
16 //imode.netのパスワード
17 $PWD = "xxxxxxxx";
18 //転送先メールアドレス
19 $TO  = "foo@gmail.com";
20
21
22 //--- ご自身の環境に応じて書き換えてください
23 /* HTML保存ファイル:書き込み可能なファイル */
24 $outHtml    = "/home/foo/imode.html";
25 /* COOKIE保存ファイル:書き込み可能なファイル */
26 $outCookie  = "/home/foo/imode.txt";
27 /* 絵文字保存フォルダ:書き込み可能なフォルダ(Webに公開されている場所) */
28 $emojiPath  = "/home/foo/public_html/imode/";
29 /* 絵文字保存URL:上記のフォルダをWebから見た時のURL */
30 $emojiUrl   = "http://hogehoge.jp/~foo/imode/";
31
32
33 //--- 必要に応じて変更してください
34 //転送メールのタイトルの前に挿入する文字
35 $prefixSubject="[imode] ";
36 //転送メールの本文の冒頭に挿入する文字
37 $prefixMail = "========================<br>
38  ※ このメールはimodeメールの転送です ※<br>
39       <a href=\"https://imode.net/cmn/m/\">https://imode.net/cmn/m/</a><br>
40 ========================<br>
41 ";
42
43
44 /* コマンド:特に変更する必要は無いです */
45 $cmdEmoji = "wget --load-cookies=".$outCookie." ";
46 $cmdListWithLogin = "wget --quiet --save-cookies ".$outCookie." --keep-session-cookies -O ".$outHtml." --post-data 'HIDEURL=%3FWM_AK%3Dhttps%253a%252f%252fimode.net%252fsmfag%26path%3D%252fimail%252fm%252fsmarttop%26query%3D&LOGIN=WM_LOGIN&WM_KEY=0&MDCM_UID=".$UID."&MDCM_PWD=".$PWD."' https://imode.net/smf/dfw";
47 $cmdListWithoutLogin = "wget --quiet --load-cookies ".$outCookie." -O ".$outHtml." --post-data 'func_id_PWS301_F04=%e6%9c%80%e6%96%b0%e6%83%85%e5%a0%b1%e3%81%b8%e6%9b%b4%e6%96%b0&fid=0&pno=1&startdate=".date("YmdHis")."&chkdate=".date("YmdHis")."&bdid=0' https://imode.net/imail/m/e6uao/acgi/smart";
48
49 function getNewMail(){
50         global $outHtml,$cmdListWithLogin,$cmdListWithoutLogin;
51         exec($cmdListWithOutLogin);
52         if(strpos(file_get_contents($outHtml),'input name="MDCM_UID"')!==FALSE){
53                 exec($cmdListWithLogin);
54         }
55 }
56
57 $cmdMail = "wget --quiet -O imode.html --load-cookies ".$outCookie." ";
58 $cmdMailUrl = "https://imode.net/imail/m/e6uao/acgi/";
59
60 getNewMail();
61
62 $list = file($outHtml);
63 $c = 0;
64 foreach($list as $line){
65         if(strpos($line,'<span class="unread">')!==FALSE){
66                 if($c++ % 3 == 2){
67                         $a = strpos($line,'<a href="')+11;
68                         $z = strpos($line,'"',$a);
69                         $cmd = $cmdMail.escapeshellarg($cmdMailUrl.html_entity_decode(substr($line,$a,$z-$a)));
70                         exec($cmd);
71                         $mail = file($outHtml);
72                         $hit = false;$cc=0;$date="";$from="";$subject="";$text="";
73                         foreach($mail as $row){
74                                 if($cc <= 3 and $hit){
75                                         $hit = false;
76                                         if($cc == 1){
77                                                 list($gomi,$date) = explode(":",html_entity_decode(strip_tags($row)),2);
78                                         }else if($cc == 2){
79                                                 if($from==""){
80                                                         $hit = true;
81                                                         $from = $row;
82                                                 }else{
83                                                         list($gomi,$from) = explode(":",html_entity_decode(strip_tags($from.$row)),2);
84                                                 }
85                                         }else if($cc == 3){
86                                                 list($gomi,$subject) = explode(":",html_entity_decode(strip_tags($row)),2);
87                                         }
88                                 }
89                                 if($cc >= 3){
90                                         if(strpos($row,'<td colspan="2">')!==FALSE){
91                                                 if($cc == 5){
92                                                         $text = html_entity_decode(substr($row,16,strlen($row)-23));
93                                                         $text = "<html><head><base href=\"".$cmdMailUrl."\"></head><body>".$text."</body></html>";
94                                                         $headers  = 'MIME-Version: 1.0' . "\r\n";
95                                                         $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";;
96                                                         $headers .= 'From: '.$from."\r\n";
97                                                         //echo "==========-\n";
98                                                         //echo $date."\n";
99                                                         //echo $from."\n";
100                                                         //echo $subject."\n";
101                                                         //echo "-----------\n".html_entity_decode($text)."\n-------------\n";
102                                                         //--emoji
103                                                         preg_match_all(
104                                                                 '|<img src="(\\.\\./[^"]*)"|U',
105                                                                 $text, $out, PREG_SET_ORDER
106                                                         );
107                                                         $emojis = array();
108                                                         foreach($out as $emoji){
109                                                                 //echo $emoji[1];
110                                                                 $filename = uniqid().".gif";
111                                                                 $emojis[html_entity_decode($emoji[1])] = $emojiUrl.$filename;
112                                                                 exec($cmdEmoji."-O ".$emojiPath.$filename." '".$cmdMailUrl.html_entity_decode($emoji[1])."'");
113                                                                 $text = str_replace($emoji[1],$emojis[html_entity_decode($emoji[1])],$text);
114                                                                 echo "\n\n\n".$text."\n\n\n";
115                                                         }
116                                                         mail($TO,$prefixSubject.$subject,$prefixMail.$text,$headers);
117                                                         break;
118                                                 }
119                                                 $cc++;
120                                         }
121                                 }
122                                 if(strpos($row,'<tr class="mailinfo">')!==FALSE){
123                                         $hit = true;
124                                         $cc++;
125                                 }
126                         }
127                 }
128         }
129 }
130 ?>