. */ /** * Alle E-Mails auf eine E-Plus Handy-Mail Account löschen * * Dieses PHP-Script löscht alle E-Mails eines E-Plus * Handy-Mail Account. * * Es wird am besten mittels PHP CLI ausgeführt, dass Handy-Mail * unglaublich lahm beim löschen von E-Mails ist. * * $ php eplus-handy-mail-posteingang-leeren.php * * Vorher müssen natürlich die Variablen * - $user * - $password * weiter unten befüllt werden. * * Dieses Script erfordert PHP >= 5.0.0 mit den Extensions curl und pcre * * @author Markus Tacker * @link http://m.tacker.org/blog/1179.e-plus-handy-mail-alle-e-mails-auf-einmal-loschen.html * @version 2008-07-10.1 */ class EPlus_HandyMail { /** * @var string Handy-Nummer */ public static $user = ''; /** * @var string Passwort */ public static $pass = ''; private $sessionid; private $host = 'https://email.eplus.de'; private $curl; private $accountid; private function __construct() { $this->curl = curl_init(); curl_setopt( $this->curl, CURLOPT_COOKIESESSION, true ); } /** * Bei Handy-Mail einloggen */ private function login() { // Get Login curl_setopt( $this->curl, CURLOPT_URL, $this->host . '/login' ); curl_setopt( $this->curl, CURLOPT_POST, false ); curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, true ); $loginform = curl_exec( $this->curl ); if ( !preg_match( '#jsessionid=([^\?]+)#i', $loginform, $match ) ) throw new Exception( 'Konnte Session-ID nicht finden.' ); $this->sessionid = $match[1]; // Login $url = $this->host . '/messaging_as/xhtml%3Bjsessionid=' . $this->sessionid . '?site=e-plus'; curl_setopt( $this->curl, CURLOPT_URL, $url ); curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $this->curl, CURLOPT_HEADER, true ); curl_setopt( $this->curl, CURLOPT_COOKIE, 'JSESSIONID=' . $this->sessionid ); curl_setopt( $this->curl, CURLOPT_POST, true ); $this->setPost( array( 'user' => self::$user, 'pass' => self::$pass, 'view' => 'login', 'red' => '', 'site' => 'e-plus', 'op_login' => 'Einloggen' ) ); $message = curl_exec( $this->curl ); if ( !preg_match( '/accountid=([0-9]+)/', $message, $match ) ) throw new Exception( 'Konnte Account-ID nicht finden.' ); $this->accountid = $match[ 1 ]; } private function deleteAllMessages() { $this->login(); do { $messages = $this->fetchMessages(); foreach( $messages as $id ) $this->deleteMessage( $id ); } while( !empty( $messages ) ); echo 'Fertig. Keine Nachrichten (mehr) vorhanden.'; } /** * Message-IDs aus dem Posteingang abrufen * * @return array */ private function fetchMessages() { $url = $this->host . '/messaging_as/xhtml%3Bjsessionid=' . $this->sessionid . '?view=folder&accountid=' . $this->accountid . '&frag=1&counter=0&site=e-plus'; curl_setopt( $this->curl, CURLOPT_URL, $url ); curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $this->curl, CURLOPT_POST, false ); $inbox = curl_exec( $this->curl ); preg_match_all( '#/messaging_as/xhtml%3Bjsessionid=' . $this->sessionid . '\?view=msg&oid=([^&]+)&frag=[0-9]+&accountid=' . $this->accountid . '&pagenum=[0-9]+&counter=[0-9]+&foldertype=&site=e-plus#i', $inbox, $matches ); $return = array(); foreach ( $matches[1] as $match ) $return[] = $match; return $return; } /** * Nachricht löschen * * @param string ID */ private function deleteMessage( $message_id ) { echo 'Deleting Message ' . $message_id . "\n"; $url = $this->host . '/messaging_as/xhtml%3Bjsessionid=' . $this->sessionid . '?site=e-plus'; curl_setopt( $this->curl, CURLOPT_URL, $url ); curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $this->curl, CURLOPT_COOKIE, 'JSESSIONID=' . $this->sessionid ); curl_setopt( $this->curl, CURLOPT_POST, true ); $this->setPost( array( 'folderFrag' => '1', 'folderFragAfterDeletion' => '1', 'op_delete' => 'Löschen', 'source' => '', 'view' => 'delete', 'accountid' => '', 'foldertype' => '', 'oid' => urldecode( $message_id ) ) ); $message = curl_exec( $this->curl ); } /** * Post-Daten setzen */ private function setPost( array $data ) { $postvars = ''; foreach( $data as $k => $v ) $postvars .= ( empty( $postvars ) ? '' : '&' ) . urlencode( $k ) . '=' . urlencode( $v ); curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $postvars ); } /** * Einstiegspunkt der Anwendung */ public static function main() { error_reporting( E_ALL|E_STRICT ); ini_set( 'display_errors', 1 ); ini_set( 'html_errors', 0 ); $EPlus_HandyMail = new EPlus_HandyMail; $EPlus_HandyMail->deleteAllMessages(); } } EPlus_HandyMail::main();