Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-WAV从电子邮件下载_Php_Email_Imap_Php Imap - Fatal编程技术网

PHP-WAV从电子邮件下载

PHP-WAV从电子邮件下载,php,email,imap,php-imap,Php,Email,Imap,Php Imap,我们目前有一个PHP脚本,它可以访问我们的电子邮件,并提取.wav文件以用于语音邮件目的 但是新的语音邮件系统发送的.wav是这样的:01359272577 03-14-16 20h14.wav,而旧系统是这样做的:msg100.wav 脚本在没有空格时下载wav文件。我无法理解当文件名中有空格时为什么它不这样做 已编辑请参见下面不带SQL的新脚本。它做了它应该做的一切,但如果原始文件名有空格,它将不会提取文件 编辑玩得更多。如果你再次发送电子邮件。但首先将文件拖到桌面,然后再拖回电子邮件。它会

我们目前有一个PHP脚本,它可以访问我们的电子邮件,并提取
.wav
文件以用于语音邮件目的

但是新的语音邮件系统发送的
.wav
是这样的:
01359272577 03-14-16 20h14.wav
,而旧系统是这样做的:
msg100.wav

脚本在没有空格时下载wav文件。我无法理解当文件名中有空格时为什么它不这样做

已编辑请参见下面不带SQL的新脚本。它做了它应该做的一切,但如果原始文件名有空格,它将不会提取文件

编辑玩得更多。如果你再次发送电子邮件。但首先将文件拖到桌面,然后再拖回电子邮件。它会降低1kb,然后将文件放入文件夹并100%工作

有人能帮我弄清楚吗

下面可以看到关于该文件的一些调试

未提取的文件。

 Extracting D:/Voicemail/Messages/test/01359272577 2016-03-14 19-47-30.wav... 
stdClass Object ( [type] => 1 [encoding] => 0 [ifsubtype] => 1 [subtype] => MIXED [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => boundary [value] => multipart-mixed-boundary ) ) [parts] => Array ( [0] => stdClass Object ( [type] => 0 [encoding] => 0 [ifsubtype] => 1 [subtype] => HTML [ifdescription] => 0 [ifid] => 0 [lines] => 1 [bytes] => 247 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 0 [parameters] => stdClass Object ( ) ) [1] => stdClass Object ( [type] => 3 [encoding] => 3 [ifsubtype] => 1 [subtype] => OCTET-STREAM [ifdescription] => 0 [ifid] => 0 [bytes] => 48250 [ifdisposition] => 1 [disposition] => attachment [ifdparameters] => 1 [dparameters] => Array ( [0] => stdClass Object ( [attribute] => filename [value] => 01359272577 03-14-16 19h47.wav ) ) [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => name [value] => 01359272577 03-14-16 19h47.wav
Extracting D:/Voicemail/Messages/test/01359272577 2016-03-15 16-15-11.wav... 
stdClass Object ( [type] => 1 [encoding] => 0 [ifsubtype] => 1 [subtype] => MIXED [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => boundary [value] => _004_6774455887777E4C8AEAC737C2F28B0D95E27FISERVER2infusions_ ) ) [parts] => Array ( [0] => stdClass Object ( [type] => 1 [encoding] => 0 [ifsubtype] => 1 [subtype] => ALTERNATIVE [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => boundary [value] => _000_6774455887777E4C8AEAC737C2F28B0D95E27FISERVER2infusions_ ) ) [parts] => Array ( [0] => stdClass Object ( [type] => 0 [encoding] => 4 [ifsubtype] => 1 [subtype] => PLAIN [ifdescription] => 0 [ifid] => 0 [lines] => 6 [bytes] => 152 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => charset [value] => us-ascii ) ) ) [1] => stdClass Object ( [type] => 0 [encoding] => 4 [ifsubtype] => 1 [subtype] => HTML [ifdescription] => 0 [ifid] => 0 [lines] => 70 [bytes] => 2137 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => charset [value] => us-ascii ) ) ) ) ) [1] => stdClass Object ( [type] => 4 [encoding] => 3 [ifsubtype] => 1 [subtype] => WAV [ifdescription] => 1 [description] => 01359272577 03-15-16 16h05.wav [ifid] => 0 [bytes] => 87660 [ifdisposition] => 1 [disposition] => attachment [ifdparameters] => 1 [dparameters] => Array ( [0] => stdClass Object ( [attribute] => filename [value] => 01359272577 03-15-16 16h05.wav ) [1] => stdClass Object ( [attribute] => size [value] => 67660 ) [2] => stdClass Object ( [attribute] => creation-date [value] => Tue, 15 Mar 2016 16:14:54 GMT ) [3] => stdClass Object ( [attribute] => modification-date [value] => Tue, 15 Mar 2016 16:14:54 GMT ) ) [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => name [value] => 01359272577 03-15-16 16h05.wav
文件中的内容。

 Extracting D:/Voicemail/Messages/test/01359272577 2016-03-14 19-47-30.wav... 
stdClass Object ( [type] => 1 [encoding] => 0 [ifsubtype] => 1 [subtype] => MIXED [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => boundary [value] => multipart-mixed-boundary ) ) [parts] => Array ( [0] => stdClass Object ( [type] => 0 [encoding] => 0 [ifsubtype] => 1 [subtype] => HTML [ifdescription] => 0 [ifid] => 0 [lines] => 1 [bytes] => 247 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 0 [parameters] => stdClass Object ( ) ) [1] => stdClass Object ( [type] => 3 [encoding] => 3 [ifsubtype] => 1 [subtype] => OCTET-STREAM [ifdescription] => 0 [ifid] => 0 [bytes] => 48250 [ifdisposition] => 1 [disposition] => attachment [ifdparameters] => 1 [dparameters] => Array ( [0] => stdClass Object ( [attribute] => filename [value] => 01359272577 03-14-16 19h47.wav ) ) [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => name [value] => 01359272577 03-14-16 19h47.wav
Extracting D:/Voicemail/Messages/test/01359272577 2016-03-15 16-15-11.wav... 
stdClass Object ( [type] => 1 [encoding] => 0 [ifsubtype] => 1 [subtype] => MIXED [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => boundary [value] => _004_6774455887777E4C8AEAC737C2F28B0D95E27FISERVER2infusions_ ) ) [parts] => Array ( [0] => stdClass Object ( [type] => 1 [encoding] => 0 [ifsubtype] => 1 [subtype] => ALTERNATIVE [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => boundary [value] => _000_6774455887777E4C8AEAC737C2F28B0D95E27FISERVER2infusions_ ) ) [parts] => Array ( [0] => stdClass Object ( [type] => 0 [encoding] => 4 [ifsubtype] => 1 [subtype] => PLAIN [ifdescription] => 0 [ifid] => 0 [lines] => 6 [bytes] => 152 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => charset [value] => us-ascii ) ) ) [1] => stdClass Object ( [type] => 0 [encoding] => 4 [ifsubtype] => 1 [subtype] => HTML [ifdescription] => 0 [ifid] => 0 [lines] => 70 [bytes] => 2137 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => charset [value] => us-ascii ) ) ) ) ) [1] => stdClass Object ( [type] => 4 [encoding] => 3 [ifsubtype] => 1 [subtype] => WAV [ifdescription] => 1 [description] => 01359272577 03-15-16 16h05.wav [ifid] => 0 [bytes] => 87660 [ifdisposition] => 1 [disposition] => attachment [ifdparameters] => 1 [dparameters] => Array ( [0] => stdClass Object ( [attribute] => filename [value] => 01359272577 03-15-16 16h05.wav ) [1] => stdClass Object ( [attribute] => size [value] => 67660 ) [2] => stdClass Object ( [attribute] => creation-date [value] => Tue, 15 Mar 2016 16:14:54 GMT ) [3] => stdClass Object ( [attribute] => modification-date [value] => Tue, 15 Mar 2016 16:14:54 GMT ) ) [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => name [value] => 01359272577 03-15-16 16h05.wav
这是我的代码:

<?php

$MSG_DIR = "D:/Voicemail/Messages";
$USER = "XX";
$PASS = "XX";

// connect to server
echo "Opening mailbox...\n<br/>";
$host = "{localhost:143/imap4/novalidate-cert}Inbox";
$mbox=imap_open($host,$USER,$PASS, NULL, 1, array('DISABLE_AUTHENTICATOR' => 'GSSAPI')) or die("Can't connect: " . imap_last_error());

// iterate over mailbox
echo "Finding emails...\n<br/>";
$MC = imap_check($mbox) or die("Can't check for messages");

$overview = imap_fetch_overview( $mbox, "1:".$MC->Nmsgs, 0 ) or die( "Can't get headers");
$countThis = 0;
foreach ( $overview as $email )
{       
    $subject = $email->subject;
    $udate = $email->udate;
    if( preg_match('/Voice Message from ([0-9]+)/', $subject, $groups) )
    {
        $filename = $MSG_DIR."/".$groups[1].date(" Y-m-d H-i-s", $udate).".wav";

        if( file_exists( $filename ) )
        {
            echo "Skipping $filename...\n<br/>";
        }
        else
        {
            echo "Extracting $filename...\n<br/>";
             $structure = imap_fetchstructure($mbox,$email->uid, FT_UID) or die( "could not fetch structure");
             foreach ( $structure->parts as $part )
             {
                if( $part->subtype == "X-WAV" || $part->subtype=="WAV")
                {
                    // found it!
                    $body = imap_base64( imap_fetchbody( $mbox, $email->uid, 2, FT_UID ) ) or die( "Could not fetch part");
                    file_put_contents( $filename, $body );
                }
                else
                {
                }
             }
        }
        $countThis++;
    }
}
echo "Found $countThis voicemails\r\n";

imap_close($mbox);  ?>
添加了以下内容

$part->subtype=="OCTET-STREAM"
到年底

 if( $part->subtype == "X-WAV" || $part->subtype=="WAV")

NEC SV8100语音邮件文件子类型数组似乎不是WAV,而是八位字节流。

我猜这个regexp可能是:
/Caller:[\s\t]+\“*”[\s\t]+/
和/或之后的那个?我不认为这里有人会调试156行代码,他们甚至不能为你运行/测试,除非你开始付钱给别人。抱歉:-(您需要通过创建一个来隔离问题。另请参阅。感谢您的回复。抱歉。可能就是这种情况,我必须付费给他人进行调整。
$filename=$MSG_DIR./“$username.date”($Y-m-d H-I-s),$udate)。“.wav”
“新的语音邮件系统发送的.wav如下所示:013592725777 03-14-16 20h14.wav”对我来说,这些看起来一点都不一样。