質問編集履歴
3
honbunの取得位置と、届いたメールの本体を追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -184,6 +184,12 @@
|
|
184
184
|
|
185
185
|
|
186
186
|
|
187
|
+
//bodyからhtmlタグを取り除く(改行のみ残す)
|
188
|
+
|
189
|
+
$honbun = strip_tags($body,'<br>');
|
190
|
+
|
191
|
+
|
192
|
+
|
187
193
|
$osirase = "*******************************************************\n";
|
188
194
|
|
189
195
|
$osirase .= " お知らせ\n";
|
@@ -290,6 +296,138 @@
|
|
290
296
|
|
291
297
|
```
|
292
298
|
|
299
|
+
上記メールの本体です
|
300
|
+
|
301
|
+
```
|
302
|
+
|
303
|
+
Return-Path: <user_1@exempl_1.com>
|
304
|
+
|
305
|
+
X-Original-To: user_2@exempl_2.com
|
306
|
+
|
307
|
+
Delivered-To: user_2@exempl_2.com
|
308
|
+
|
309
|
+
Received: from exempl_3.com (mailsv03.exempl_3.com [10.130.201.17])
|
310
|
+
|
311
|
+
by exempl_2.com (Postfix) with ESMTP id 9A17055C20
|
312
|
+
|
313
|
+
for <user_2@exempl_2.com>; Wed, 12 Apr 2017 01:20:02 +0900 (JST)
|
314
|
+
|
315
|
+
Received: from exempl_3.com (localhost [127.0.0.1])
|
316
|
+
|
317
|
+
by exempl_3.com (Proxmox) with ESMTP id D64BC10FC520
|
318
|
+
|
319
|
+
for <user_2@exempl_2.com>; Wed, 12 Apr 2017 01:20:12 +0900 (JST)
|
320
|
+
|
321
|
+
Received: from outd2.commnd.jp (outd2.commnd.jp [219.117.35.72])
|
322
|
+
|
323
|
+
by exempl_3.com (Proxmox) with ESMTP id 5921D10FCE54
|
324
|
+
|
325
|
+
for <user_2@exempl_2.com>; Wed, 12 Apr 2017 01:20:05 +0900 (JST)
|
326
|
+
|
327
|
+
Received: from TEVAAV12.commnd.jp (TEVAAV12.sv.commnd.jp [192.168.41.152])
|
328
|
+
|
329
|
+
by TEVAOUTD02.sv.commnd.jp (Postfix) with ESMTP id 633464003B
|
330
|
+
|
331
|
+
for <user_2@exempl_2.com>; Wed, 12 Apr 2017 01:20:05 +0900 (JST)
|
332
|
+
|
333
|
+
Received: from pps.filterd (TEVAAV12.commnd.jp [127.0.0.1])
|
334
|
+
|
335
|
+
by TEVAAV12.commnd.jp (8.16.0.17/8.16.0.17) with SMTP id v3BFQKOI026949
|
336
|
+
|
337
|
+
for <user_2@exempl_2.com>; Wed, 12 Apr 2017 01:20:05 +0900
|
338
|
+
|
339
|
+
Received: from tevain03.sv.commnd.jp (TEVAIN03.sv.commnd.jp [192.168.40.23])
|
340
|
+
|
341
|
+
by TEVAAV12.commnd.jp with ESMTP id 29pf4hsw8f-1
|
342
|
+
|
343
|
+
for <user_2@exempl_2.com>; Wed, 12 Apr 2017 01:20:05 +0900
|
344
|
+
|
345
|
+
Received: from exempl_1.com (14-133-71-20.dz.commnd.jp [14.133.71.20])
|
346
|
+
|
347
|
+
by TEVAIN03.sv.commnd.jp (Postfix) with ESMTPA id 3F6524003C
|
348
|
+
|
349
|
+
for <user_2@exempl_2.com>; Wed, 12 Apr 2017 01:20:05 +0900 (JST)
|
350
|
+
|
351
|
+
Received: from [10.130.200.224] (p199075.mirai.ne.jp [210.172.199.75])
|
352
|
+
|
353
|
+
by exempl_1.com (Postfix) with ESMTPSA id 9AE6B83A8802
|
354
|
+
|
355
|
+
for <user_2@exempl_2.com>; Wed, 12 Apr 2017 01:20:04 +0900 (JST)
|
356
|
+
|
357
|
+
To: user_2@exempl_2.com
|
358
|
+
|
359
|
+
From: user_1 <user_1@exempl_1.com>
|
360
|
+
|
361
|
+
Subject: =?UTF-8?B?MeODhuOCueODiOODoeODvOODqw==?=
|
362
|
+
|
363
|
+
Message-ID: <83f0e40a-ad17-90ed-4301-683bf404578e@detox.dip.jp>
|
364
|
+
|
365
|
+
Date: Wed, 12 Apr 2017 01:19:54 +0900
|
366
|
+
|
367
|
+
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101
|
368
|
+
|
369
|
+
Thunderbird/52.0
|
370
|
+
|
371
|
+
MIME-Version: 1.0
|
372
|
+
|
373
|
+
Content-Type: multipart/mixed;
|
374
|
+
|
375
|
+
boundary="------------B1E5A46C90073A442978500A"
|
376
|
+
|
377
|
+
Content-Language: en-US
|
378
|
+
|
379
|
+
X-Proofpoint-Virus-Version: vendor=nai engine=5800 definitions=8495 signatures=668451
|
380
|
+
|
381
|
+
X-SPAM-LEVEL: Spam detection results: 0
|
382
|
+
|
383
|
+
RCVD_IN_DNSWL_NONE -0.0001 Sender listed at http://yahoo.co.jp/, no trust
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
This is a multi-part message in MIME format.
|
388
|
+
|
389
|
+
--------------B1E5A46C90073A442978500A
|
390
|
+
|
391
|
+
Content-Type: text/plain; charset=utf-8; format=flowed
|
392
|
+
|
393
|
+
Content-Transfer-Encoding: 8bit
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
テストメール
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
--------------B1E5A46C90073A442978500A
|
404
|
+
|
405
|
+
Content-Type: text/plain; charset=UTF-8;
|
406
|
+
|
407
|
+
name="copy.bat"
|
408
|
+
|
409
|
+
Content-Transfer-Encoding: base64
|
410
|
+
|
411
|
+
Content-Disposition: attachment;
|
412
|
+
|
413
|
+
filename="copy.bat"
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
IHBhdXNlDQogcGF1c2UNCiBjZCBjOlxhYWENCiBtb3ZlIC95IGM6XGFhYVxjYXJ0aWVyNC5o
|
418
|
+
|
419
|
+
dG0gYzpcYmJiDQogbW92ZSAveSBjOlxhYWFcb21lZ2E0Lmh0bSBjOlxiYmINCiBtb3ZlIC95
|
420
|
+
|
421
|
+
IGM6XGFhYVxjb3J1bTQuaHRtIGM6XGJiYg0KIG1vdmUgL3kgYzpcYWFhXHR1ZG9yNC5odG0g
|
422
|
+
|
423
|
+
YzpcYmJiDQogbW92ZSAveSBjOlxhYWFcYmxlaXRsaW5nNC5odG0gYzpcYmJiDQogcGF1c2Ug
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
--------------B1E5A46C90073A442978500A--
|
428
|
+
|
429
|
+
```
|
430
|
+
|
293
431
|
エクセルファイルとbatファイルの2つを添付してもbatファイルの内容が本文に入ってしまいます。
|
294
432
|
|
295
433
|
何か解決方法があったら教えてください。
|
2
ユーザー名を匿名にしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -160,7 +160,7 @@
|
|
160
160
|
|
161
161
|
};
|
162
162
|
|
163
|
-
$cpname = "/home/s
|
163
|
+
$cpname = "/home/userdir/".$cpname;
|
164
164
|
|
165
165
|
//ファイルをコピーする
|
166
166
|
|
1
使用スクリプトを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,6 +2,244 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
使用しているPHPスクリプト
|
6
|
+
|
7
|
+
```
|
8
|
+
|
9
|
+
#!/usr/bin/php
|
10
|
+
|
11
|
+
<?php
|
12
|
+
|
13
|
+
$stdin = fopen("php://stdin", "r");
|
14
|
+
|
15
|
+
$header = "";
|
16
|
+
|
17
|
+
$_header_write = true;
|
18
|
+
|
19
|
+
$raw_mail = "";
|
20
|
+
|
21
|
+
$ketasuu = array();
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
do {
|
26
|
+
|
27
|
+
$line = fread($stdin, 4096);
|
28
|
+
|
29
|
+
if (strlen($line) == 0) break;
|
30
|
+
|
31
|
+
if ( $n = strpos($line, "\n\n")){ //空行を見つけた
|
32
|
+
|
33
|
+
$header .= substr($line, 0, $n);
|
34
|
+
|
35
|
+
$_header_write = false;
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
if ($_header_write) $header .= $line;
|
40
|
+
|
41
|
+
$raw_mail .= $line ;//. PHP_EOL;
|
42
|
+
|
43
|
+
} while(true);
|
44
|
+
|
45
|
+
fclose($stdin);
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
require_once('/usr/local/bin/ReceiptMailDecoder.class.php');
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
$decoder =& new ReceiptMailDecoder($raw_mail);
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
//X-Original-Toを取得する
|
58
|
+
|
59
|
+
$deliveredto = $decoder->getDeliveredTo( 'x-original-to' );
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
//$deliveredtoからアカウントを取得
|
64
|
+
|
65
|
+
$deliveredaccount = strstr($deliveredto, "@", true);
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
//$deliveredtoからドメインを取得
|
70
|
+
|
71
|
+
$mydomain = strstr($deliveredto,"@");
|
72
|
+
|
73
|
+
$mydomain = str_replace('@', "", $mydomain);
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
//fromを取り出す
|
78
|
+
|
79
|
+
$subfrom = $decoder->getFromAddr('from');
|
80
|
+
|
81
|
+
$fromtxt = $subfrom;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
//件名を取得する
|
86
|
+
|
87
|
+
$subject = $decoder->getDecodedHeader( 'subject' );
|
88
|
+
|
89
|
+
$subject = mb_convert_encoding($subject,"UTF-8",mb_detect_encoding($subject, "ASCII,JIS,UTF-8,CP51932,SJIS-win,iso-2022-jp", true));
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
$body = "";
|
94
|
+
|
95
|
+
//本文を取得する
|
96
|
+
|
97
|
+
//text/planなメール本文を取得する
|
98
|
+
|
99
|
+
$body = mb_convert_encoding($decoder->body['text'],'UTF-8','auto');
|
100
|
+
|
101
|
+
if (empty($body)){
|
102
|
+
|
103
|
+
//text/htmlなメール本文を取得する
|
104
|
+
|
105
|
+
$body = mb_convert_encoding($decoder->body['html'],'UTF-8','auto');
|
106
|
+
|
107
|
+
$body = mb_convert_encoding($body,'UTF-8',mb_detect_encoding($body, 'ASCII,JIS,UTF-8,CP51932,SJIS-win,iso-2022-jp','auto'));
|
108
|
+
|
109
|
+
};
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
//マルチパートのデータを取得する
|
114
|
+
|
115
|
+
if ( $decoder->isMultipart() ) {
|
116
|
+
|
117
|
+
$tempFiles = array();
|
118
|
+
|
119
|
+
$num_of_attaches = $decoder->getNumOfAttach();
|
120
|
+
|
121
|
+
for ( $i=0 ; $i < $num_of_attaches ; ++$i ) {
|
122
|
+
|
123
|
+
/*
|
124
|
+
|
125
|
+
* ファイルを一時ディレクトリ _TEMP_ATTACH_FILE_DIR_ に保存する
|
126
|
+
|
127
|
+
* 一時ファイルには tempnam()を使用する
|
128
|
+
|
129
|
+
*/
|
130
|
+
|
131
|
+
$fpath = tempnam( _TEMP_ATTACH_FILE_DIR_, "todoattach_" );
|
132
|
+
|
133
|
+
print "fpath=$fpath <br>\n";
|
134
|
+
|
135
|
+
if ( $decoder->saveAttachFile( $i, $fpath )) {
|
136
|
+
|
137
|
+
$tempFiles["$fpath"] = $decoder->attachments[$i]['mime_type'];
|
138
|
+
|
139
|
+
//取り込んだ添付ファイルの名前を取得
|
140
|
+
|
141
|
+
foreach (glob($fpath."*") as $filename) {
|
142
|
+
|
143
|
+
if (filesize($filename) >0){
|
144
|
+
|
145
|
+
//指定した文字数以降の文字列を取得
|
146
|
+
|
147
|
+
$cpname = $deliveredaccount."_".substr($filename, strlen($fpath));
|
148
|
+
|
149
|
+
$cpname = mb_convert_encoding($cpname,'UTF-8',mb_detect_encoding($cpname, 'ASCII,JIS,UTF-8,CP51932,SJIS-win,iso-2022-jp','auto'));
|
150
|
+
|
151
|
+
//サイズが0(ゼロ)より大きいとき
|
152
|
+
|
153
|
+
if ($tmpchk == "") {
|
154
|
+
|
155
|
+
$tmpchk = $cpname;
|
156
|
+
|
157
|
+
} else {
|
158
|
+
|
159
|
+
$tmpchk .= ', '.$cpname;
|
160
|
+
|
161
|
+
};
|
162
|
+
|
163
|
+
$cpname = "/home/sanitizer/".$cpname;
|
164
|
+
|
165
|
+
//ファイルをコピーする
|
166
|
+
|
167
|
+
var_dump(copy( $filename, $cpname ));
|
168
|
+
|
169
|
+
//ファイルを削除する
|
170
|
+
|
171
|
+
var_dump( unlink($filename) );
|
172
|
+
|
173
|
+
var_dump( unlink($fpath) );
|
174
|
+
|
175
|
+
};
|
176
|
+
|
177
|
+
};
|
178
|
+
|
179
|
+
};
|
180
|
+
|
181
|
+
};
|
182
|
+
|
183
|
+
};
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
$osirase = "*******************************************************\n";
|
188
|
+
|
189
|
+
$osirase .= " お知らせ\n";
|
190
|
+
|
191
|
+
$osirase .= " ".$subfrom."\n";
|
192
|
+
|
193
|
+
if (empty($tmpchk)) {
|
194
|
+
|
195
|
+
$osirase .= "\n";
|
196
|
+
|
197
|
+
} else {
|
198
|
+
|
199
|
+
$osirase .= " 添付ファイル:".$tmpchk."\n";
|
200
|
+
|
201
|
+
};
|
202
|
+
|
203
|
+
$osirase .= "*******************************************************\n\n";
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
$subto='<'.$deliveredaccount.'@xxxxxxx.com>';
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
//言語設定、内部エンコーディングを指定する
|
212
|
+
|
213
|
+
mb_language("japanese");
|
214
|
+
|
215
|
+
mb_internal_encoding("UTF-8");
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
//日本語メール送信
|
220
|
+
|
221
|
+
$atesaki = $subto;
|
222
|
+
|
223
|
+
$kenmei = $subject;
|
224
|
+
|
225
|
+
$naiyou = $osirase.$honbun;
|
226
|
+
|
227
|
+
$from = $fromtxt;
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
//送信
|
232
|
+
|
233
|
+
echo mb_send_mail($atesaki,$kenmei,$naiyou,'From:'.$from);
|
234
|
+
|
235
|
+
?>
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
```
|
242
|
+
|
5
243
|
エクセルファイルを添付したとき
|
6
244
|
|
7
245
|
```
|