Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Outlook Pasto Sistema</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
- <style>
- *{
- margin:0;
- padding:0;
- }
- html{
- height: 100%;
- width: 100%;
- }
- body{
- height: 100%;
- width: 100%
- }
- table{
- table-layout: fixed;
- width: 100%;
- }
- td{
- border : 1px solid black;
- text-align: center;
- width: 10%;
- word-wrap:break-word
- }
- th {
- border: 1px solid black;
- word-wrap:break-word
- }
- </style>
- </head>
- <body>
- <?php
- header('Content-Type: text/html; charset=UTF-8');
- //Prijungiam duomenu baze
- include ('config/DbConnect.php');
- //Prisijungimai i el.pasta
- $user = 'tautvydas.ulevicius@vilnius.lt';
- $password = 'Taul320k';
- //Prisijungimo funkcija...Nustatom tls ir pridedam , kad be sertifikato...
- function pop3_login($host,$port,$user,$pass,$folder="INBOX",$tls=false)
- {
- $tls = ($tls==false) ? '/novalidate-cert' : '';
- return (imap_open('{'.$host.':'.$port.'/pop3/tls}'.$folder,$user,$pass));
- }
- //Isgaunam prisijungimo statusa....
- function pop3_stat($imap){
- $check = imap_mailboxmsginfo($imap);
- return ((array)$check);
- }
- //Informacija, prie kur jungtis
- $inbox = pop3_login("mail.vilnius.lt","110",$user,$password,$folder="INBOX",$tls=true);
- $emails = imap_search($inbox,'UNSEEN');
- //Paziurim el-pasto statusa...
- $check = imap_mailboxmsginfo($inbox);
- if ($check) {
- echo '<table><tr>';
- echo "<th>"."Date: "."</th>"."<th>"."Driver: "."</th>"."<th>"."Mailbox: "."<th>"."Messages: "."<th>"."Recent: "."<th>"."Unread: "."<th>"."Deleted: "."<th>"."Size: "."</tr>";
- echo "<tr>"."<td>".$check->Date."</td>"."<td>".$check->Driver."</td>"."<td>".$check->Mailbox."</td>"."<td>".$check->Nmsgs."</td>"."<td>".$check->Recent."</td>"."<td>".$check->Unread."</td>"."<td>".$check->Deleted."</td>"."<td>".$check->Size."</td>"."</tr>";
- } else {
- echo "imap_mailboxmsginfo() failed: " . imap_last_error() . "<br />\n";
- }?>
- <!--Pradedam lentele kurioje bus dedama informacija laisku-->
- <table width="100%" border="0" cellspacing="0" cellpadding="0">
- <br>
- <tr>
- <td><h1>ID</h1></td>
- <td><h1>Siuntėjas</h1></td>
- <td><h1>Gavimo laikas</h1></td>
- <td><h1>Tema</h1></td>
- <td><h1>Turinys</h1></td>
- <td><h1>Pridetas failas</h1></td>
- </tr>
- <?php
- if($emails) {
- //apsirasom kintamuosius, kurie bus reikalingi, kad i duomenu baze irasyt info
- $siuntejas = '';
- $data='';
- $tema='';
- $turinys='';
- $output='';
- /* Kiekvienam laiskui... */
- foreach($emails as $email_number) {
- /* Laisko informacijos gavimas */
- $overview = imap_fetch_overview($inbox,$email_number,0);
- $message =imap_fetchbody($inbox,$email_number,1);
- /* Gauname informacija */
- $siuntejas= $overview[0]->from;
- $sena_data=$overview[0]->date; // Data blogu formatu
- $tema=$overview[0]->subject;
- $message;
- $convert = strtotime($sena_data)+3600; // Konvertuojam data i normalu formata
- $data =date('Y-m-d G:i:s', $convert);// Isgaunam geresnio formato data
- //Naikinam base64 encodinga...
- //$turinys = imap_fetchstructure($inbox,$email_number);
- //if ($turinys->encoding==3) //3 = BASE64 encoding
- // $message = base64_decode($message);
- $turinys= $message;
- $turinys=strip_tags(html_entity_decode($turinys));//Reikalingas, kad
- //istrintu html,xml is gauto emailo
- $turinys = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $turinys);//reikalingas, kad pasalintu
- //visus tarpus
- echo $turinys;
- $siuntejas = preg_replace("/[^@. \w]+/", "", $siuntejas); //Dabartinis budas
- $siuntejas=str_replace('windows1257Q', '', $siuntejas);//sutvarkyti gaunamu
- $siuntejas=str_replace('UTF8Q', '', $siuntejas);//adresatu vardus
- $siuntejas=str_replace('*lt', '', $siuntejas);
- $data2=date('Y-m-d-H-i-s',$convert);
- //Issaugom kiekviena e-mail'a i folderi , nes po to istrinsim
- $headers = imap_fetchheader($inbox, $email_number, FT_PREFETCHTEXT);
- //$headers = strstr($headers,"From:");
- $headers = preg_replace('/^(?!From:)(?!To:)(?!Subject:)(?!Date:)(?!X-MS-Has-Attach:).*?\n/m','',$headers);
- $body = imap_body($inbox, $email_number);
- file_put_contents('./test/'.($siuntejas.'-'.$data2), $headers . "\n" . $body);
- //Pradedam isgauti pridetus failus
- $structure = imap_fetchstructure($inbox, $email_number);
- $attachments = array();
- /* Jei rastas pridetas failas.. */
- if(isset($structure->parts) && count($structure->parts))
- {
- for($i = 0; $i < count($structure->parts); $i++)
- {
- $attachments[$i] = array(
- 'is_attachment' => false,
- 'filename' => '',
- 'name' => '',
- 'attachment' => ''
- );
- if($structure->parts[$i]->ifdparameters)
- {
- foreach($structure->parts[$i]->dparameters as $object)
- {
- if(strtolower($object->attribute) == 'filename')
- {
- $attachments[$i]['is_attachment'] = true;
- $attachments[$i]['filename'] = $object->value;
- }
- }
- }
- if($structure->parts[$i]->ifparameters)
- {
- foreach($structure->parts[$i]->parameters as $object)
- {
- if(strtolower($object->attribute) == 'name')
- {
- $attachments[$i]['is_attachment'] = true;
- $attachments[$i]['name'] = $object->value;
- }
- }
- }
- if($attachments[$i]['is_attachment'])
- {
- $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1);
- /* 3 = BASE64 encoding */
- if($structure->parts[$i]->encoding == 3)
- {
- $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
- }
- /* 4 = QUOTED-PRINTABLE encoding */
- elseif($structure->parts[$i]->encoding == 4)
- {
- $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
- }
- }
- }
- }else{$attlink='Nera prideto failo';}
- /* Pereinam per kiekviena prideta faila ir ji issaugom */
- foreach($attachments as $attachment)
- {
- if($attachment['is_attachment'] == 1)
- {
- $filename = $attachment['name'];
- if(empty($filename)) $filename = $attachment['filename'];
- if(empty($filename)) $filename = time() . ".dat";
- $folder = "test";
- if(!is_dir($folder))
- {
- mkdir($folder);
- }
- $fp = fopen("./". $folder ."/". $email_number . "-" . $filename, "w+");
- fwrite($fp, $attachment['attachment']);
- fclose($fp);
- $attlink=("./".$folder."/".$email_number."-".$filename);
- }
- }
- //Pradedam irasyneti i duomenu baze
- $sql = "INSERT INTO Laiskai (Siuntejas,Gavimo_laikas,Tema,Turinys,Pridetas_failas)
- VALUES ('$siuntejas','$data','$tema','$turinys','$attlink')";
- if (mysqli_query($conn, $sql)) {
- //echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . mysqli_error($conn);
- }
- imap_delete($inbox, $email_number); //Nustatom , kad istrintu emailus visus
- }
- }else{echo 'Nera nauju laisku';}
- //Traukiam informacija is duomenu bazes
- $sql = "SELECT * FROM Laiskai ORDER BY Gavimo_laikas DESC";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()){
- $url = $row["Pridetas_failas"];
- echo '<tr>'.'<th>'.$row["ID"].'</th>'.'<th>'.$row["Siuntejas"].'</th>'.'<th>'.$row["Gavimo_laikas"].'</th>'.'<th>'.$row["Tema"].'</th>'.'<th>'.$row["Turinys"].'</th>'.'<th>'."<a href='".$url."'>".$url."<a/>".'<a/>'.'</th>'.'</tr>';
- }
- } else {
- echo '<h1>'."Nėra laišku".'</h1>'.'<br/>'; //Jei nera emailu, arba nauju
- }
- /* Uzdarom prisijungimus */
- mysqli_close($conn);
- //imap_expunge($inbox); //Trinam visus emailus
- imap_close($inbox);
- ?>
- </table>
- </body>
- </html>
Add Comment
Please, Sign In to add comment