Gmail teavitused töölauale & rss & php

29074 vaatamist
  1. Brunn

    2014-02-08 Administrator Estonia
    #!/bin/bash
    
    check_emails(){
    count=0;
    
    #FIRST ACCOUNT
    gmail_login="FISRT_ACCOUNT_HERE@gmail.com"
    gmail_password="FIRST_PASSWORD_HERE" 
    count=$(wget -q -O - https://mail.google.com/a/gmail.com/feed/atom --http-user=${gmail_login} --http-password=${gmail_password} --no-check-certificate | grep fullcount | sed 's/<[^0-9]*>//g')
    
    if [ $count -gt 0 ]; then
       notify-send "GMAIL" "$gmail_login - $count new emails"
    fi
    
    #SECOND ACCOUNT
    gmail_login="SECOND_ACCOUNT_HERE@gmail.com"
    gmail_password="SECOND_PASSWORD_HERE" 
    count=$(wget -q -O - https://mail.google.com/a/gmail.com/feed/atom --http-user=${gmail_login} --http-password=${gmail_password} --no-check-certificate | grep fullcount | sed 's/<[^0-9]*>//g')
    
    if [ $count -gt 0 ]; then
       notify-send "GMAIL" "$gmail_login - $count new emails"
    fi
    }
    
    #PROGRAM STARTS HERE
    #timeout in case you have selected starting the script in startup
    sleep 5 #set your own timeout if you want
    while true; do
       check_emails #run the function
       sleep 15m #timeout to wait between each check
    done
  2. Brunn

    2014-02-27 Administrator Estonia

    Mitte, et seda eriliselt heaks kiidan, kuid võimalus kui selline eksisteerib...

    $rss = new DOMDocument();
    $rss->load('https://kasutajatunnus:parool@gmail.google.com/gmail/feed/atom');
    $feed = array();
    json_decode(print_r($rss));
    
    foreach ($rss->getElementsByTagName('item') as $node) {
    	$item = array ( 
    		'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
    		'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
    		'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
    		'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
    		);
    	array_push($feed, $item);
    }
    $limit = 50;
    for($x=0;$x<$limit;$x++) {
    	$title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    	$link = $feed[$x]['link'];
    	$description = $feed[$x]['desc'];
    	$date = date('l F d, Y', strtotime($feed[$x]['date']));
    	echo '<p><strong><a href="'.$link.'">'.$title.'</a></strong><br />';
    	echo '<small><em>Posted on '.$date.'</em></small></p>';
    	echo '<p>'.$description.'</p>';
    }
  3. Brunn

    2014-02-27 Administrator Estonia

    Phps mailide lugemist, kui Zone serverist pärida:

    <?PHP
    $login = 'gmaili.aadress@gmail.com';
    $password = 'gmailiparool';
    $jk=new readattachment(); 
    $jk->getdata("{imap.gmail.com:993/imap/ssl}INBOX",$login,$password,"","","");
     
    	class readattachment
    	{
    		function getdecodevalue($message,$coding)
    		{
    			if ($coding == 0)
    			{
    			//$message = imap_8bit($message);//teatud juhtudel on vaja
    			$message = imap_qprint($message);//konverdib prinditavaks stringiks..ka xml'i
    			}
    			elseif ($coding == 1)
    			{
    			$message = imap_8bit($message);
    			}
    			elseif ($coding == 2)
    			{
    			$message = imap_binary($message);
    			}
    			elseif ($coding == 3)
    			{
    			$message=imap_base64($message);
    			}
    			elseif ($coding == 4)
    			{
    			$message = imap_qprint($message);//konverdib prinditavaks stringiks
    			}
    			elseif ($coding == 5)
    			{
    			$message = imap_base64($message);
    			}
    		return $message;
    		}
     
    		function getdata($host,$login,$password,$filepath,$album,$folder)
    		{
    $filepath="./";
    		 $mbox = imap_open ($host,  $login, $password) or die("can't connect: " . imap_last_error());
    		 $message = array();
    		 $message["attachment"]["type"][0] = "text";
    		 $message["attachment"]["type"][1] = "multipart";
    		 $message["attachment"]["type"][2] = "message";
    		 //$message["attachment"]["type"][3] = "application";
    		 $message["attachment"]["type"][4] = "audio";
    		 $message["attachment"]["type"][5] = "image";
    		 $message["attachment"]["type"][6] = "video";
    		 $message["attachment"]["type"][7] = "other";
    			for ($jk = 1; $jk <= imap_num_msg($mbox); $jk++)
    			{
    			 $structure = imap_fetchstructure($mbox, $jk);#  FT_UID OLI KOLMAS ARGUMENT
    			 $obj_andmed = imap_headerinfo($mbox, $jk);//minu lisatud päise info lugemine
    			 $parts = $structure->parts;
    			 $fpos=2;
    				for($i = 1; $i < count($parts); $i++)
    				{
    				$message["pid"][$i] = ($i);
    				$part = $parts[$i];
    					if($part->disposition == "ATTACHMENT")
    					{
    					$message["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype);
    					$message["subtype"][$i] = strtolower($part->subtype);
    					$ext=$part->subtype;
    					$params = $part->dparameters;
    					$filename=$part->dparameters[0]->value;
    					$mege="";
    					$data="";
    					$mege = imap_fetchbody($mbox,$jk,$fpos);
    					$fp=fopen($filepath . $filename,w);
    					$data=$this->getdecodevalue($mege,$part->type);
    					fputs($fp,$data);
    					fclose($fp);
    					// add_picture($album, $folder, $filename);
    echo $filename;
    					$fpos+=1;
    					}
    				}
    			 echo 'Mail on saabunud kuupäeval:'.date("Y-m-d", $obj_andmed->udate).'<br>';
    			 echo ''.date("H:i:s", $obj_andmed->udate);
    			 imap_delete($mbox,$jk);#ei kustuta vaid märgistab loetud lippudega
    			}
    			#imap_expunge($mbox);#märgistab kirjad loetuks
    			imap_close($mbox);
    		}
    	}
     
    ?>