2016-03-15 46 views
3

我們目前有一個PHP腳本,訪問我們的電子郵件,並拉動.wav文件被訪問的語音郵件的目的。PHP - 從電子郵件WAV下載

但是,新的語音信箱系統發送.wav,如下所示:01359272577 03-14-16 20h14.wav,其中舊系統是這樣做的:msg100.wav

腳本在沒有空格時下載wav文件。當文件名稱中有空格時,我無法解決它爲什麼不能執行此操作。

EDITED請參閱下面的不帶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 

這是我的代碼:

<?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); ?> 
+1

我猜這個正則表達式可能是:'/Caller:[\s\t]+\".*\"[\s\t]+ <([0-9]+)> /'和/或之後的那個?我不認爲這裏有人會調試156行代碼,他們甚至無法爲你運行/測試,除非你開始付錢給別人。對不起:-(你需要通過創建一個[Minimal,Complete,and Verifiable example](http://stackoverflow.com/help/mcve)來自己隔離問題,另請參閱[我如何提出一個好問題? ](http://stackoverflow.com/help/how-to-ask)。 – Carpetsmoker

+0

感謝您的回覆。 對不起。可能是這種情況,我將不得不支付某人來調整它。 – Law

+0

'$ filename = $ MSG_DIR。「/」。$ username.date(「Ymd His」,$ udate)。「.wav」;'_「新語音郵件系統發送如下所示的.wav:01359272577 03-14-16 20h14.wav 「對我來說,這些看起來沒有任何相同之處。 –

回答

0

添加以下

$part->subtype=="OCTET-STREAM" 

上的

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

它將年代末eem NEC SV8100語音郵件文件子類型陣列不是WAV它是OCTET-STREAM。