0

Gmailアカウントにログインし、SPAMフォルダからすべてのメールを取得するスクリプトを作成しようとしています。これは私がこれまでに持っているものです:

<?php
// Ensure Zend folder is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    'C:\xampp\htdocs\zend\library',
     get_include_path(),
)));

// require the ZF autoloader file if you have it in your include path
require_once 'Zend/Loader/Autoloader.php';
// if ZF is not in your path you can specify the full path
// otherwise if it's in a subdir (most likely if you're on a web hosting)
// you can do something like this
//require_once dirname(__FILE__) . '/Zend/Loader/AutoLoader.php';

// laod the autoloader so you don't need to require any ZF file
Zend_Loader_Autoloader::getInstance();

// connecting with Imap to gmail
$mail = new Zend_Mail_Storage_Imap(
    array(
        'host'     => 'imap.gmail.com',
        'port'     => '993',
        'ssl'      => true,
        'user'     => 'myemail@gmail.com',
        'password' => 'password',
    )
);

/*
// get the message object
$message = $mail->getMessage(1);
// output subject of message
echo $message->subject . "\n";
// dump message headers
Zend_Debug::dump($message->getHeaders());

echo $mail->countMessages() . " messages found<br/>";
foreach ($mail as $message) 
{
    echo "Mail from '{$message->from}': {$message->subject}<br/>";
}
*/

/*
var_dump($mail->getCurrentFolder());
echo "<hr>";
*/

echo "<pre>";

foreach($mail->getFolders() as $mailfolder)
{
    foreach($mailfolder as $mailfolder2)
    {
        echo "<b>Folder ".$mailfolder2." ... fetching ... </b><br>";

            var_dump($mailfolder2);



    }

}

die;
var_dump($mail->getFolders());
var_dump($mail->selectFolder("Gmail/Drafts"));

/*
// mbox with folders
$mail = new Zend_Mail_Storage_Folder_Mbox(array('dirname' =>
                                                    '/'));

$folders = new RecursiveIteratorIterator($this->mail->getFolders(),
                                         RecursiveIteratorIterator::SELF_FIRST);
echo '<select name="folder">';
foreach ($folders as $localName => $folder) {
    $localName = str_pad('', $folders->getDepth(), '-', STR_PAD_LEFT) .
                 $localName;
    echo '<option';
    if (!$folder->isSelectable()) {
        echo ' disabled="disabled"';
    }
    echo ' value="' . htmlspecialchars($folder) . '">'
        . htmlspecialchars($localName) . '</option>';
}
echo '</select>';
*/

?>

そして、私は各フォルダを(Zend_Mail_Storage_Folderオブジェクトとして)フェッチすることができましたが、そこから件名/メッセージを取得する方法を理解できません...

受信トレイからすべての電子メールをフェッチする基本的なスクリプトは次のようになります。

    // get the message object
$message = $mail->getMessage(1);
// output subject of message
echo $message->subject . "\n";
// dump message headers
Zend_Debug::dump($message->getHeaders());

echo $mail->countMessages() . " messages found<br/>";
foreach ($mail as $message) 
{
    echo "Mail from '{$message->from}': {$message->subject}<br/>";
}

これは基本的にOOPの問題です。何か助けはありますか?

これは私が得ている出力です

http://s17.postimage.org/er2v6yjcf/ceva.jpg

4

1 に答える 1

0

これを試して:

<?php
header("Content-Type: text/plain; charset=UTF-8");
mb_internal_encoding("UTF-8");
function __autoload($sClassName) {
    $sLibFilePath = __DIR__.'/'.str_replace('_', '/', $sClassName) . '.php';
    if (is_file($sLibFilePath)) {
        include_once($sLibFilePath);
    } else {
        return;
    }
}
$oImap = new Zend_Mail_Storage_Imap(
    array(
        'host'     => 'imap.gmail.com',
        'port'     => '993',
        'ssl'      => true,
        'user'     => 'myemail@gmail.com',
        'password' => '***',
    )
);
$oImap->selectFolder('[Gmail]/Spam');
echo $oImap->countMessages() . " messages found\n";
foreach ($oImap as $iTempId => $oMessage) {
  $iUniqueId = $oImap->getUniqueId($iTempId);
  echo "[{$iTempId}/{$iUniqueId}] Mail from ".mb_decode_mimeheader($oMessage->from).": ".mb_decode_mimeheader($oMessage->subject)."\n";
  if (rand(0,5) == 0) break; //for testing
}
于 2013-01-26T13:01:52.983 に答える