Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. $username = "email@domain.com"
  5. $password = "password"
  6.  
  7. #Connect to gmail using webclient, using https://mail.google.com/mail/feed/atom
  8. function get-emails($a, $b){
  9.  
  10.     $webclient = new-object System.Net.WebClient
  11.     $webclient.Credentials = new-object System.Net.NetworkCredential ("$a","$b")
  12.     [xml]$xml= $webclient.DownloadString("https://mail.google.com/mail/feed/atom")
  13.     $xml
  14.  
  15. }
  16.  
  17.  
  18. #Check age of latest email by comparing time with now
  19. function check-latestticket {
  20.  
  21.     [datetime]$1stTime = $xml.feed.entry[0].modified
  22.  
  23.     if($1stTime -gt (Get-Date).AddMinutes("-5")){
  24.         $true
  25.     }else{
  26.         $false
  27.     }
  28.  
  29.  
  30. }
  31.  
  32. #Retrieve emails, has to go before xml filtering at the moment
  33. $xml = get-emails $username $password
  34.  
  35.  
  36.  
  37. #Filter xml for required data - this part needs improving
  38. $ticket1 = $xml.feed.entry[0]
  39. $ticket1title = $ticket1.title
  40. $len = $ticket1.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
  41. if ($len -lt 80) { $ticket1summary = $ticket1.summary}else{$ticket1summary = $ticket1.summary.Substring(0,80) + "..."}
  42. $ticket1author = $ticket1.author.name
  43.  
  44.  
  45. $ticket2 = $xml.feed.entry[1]
  46. $ticket2title = $ticket2.title
  47. $len = $ticket2.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
  48. if ($len -lt 80) { $ticket2summary = $ticket2.summary}else{$ticket2summary = $ticket2.summary.Substring(0,80) + "..."}
  49. $ticket2author = $ticket2.author.name
  50.  
  51. $ticket3 = $xml.feed.entry[2]
  52. $ticket3title = $ticket3.title
  53. $len = $ticket3.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
  54. if ($len -lt 80) { $ticket3summary = $ticket3.summary}else{$ticket3summary = $ticket3.summary.Substring(0,80) + "..."}
  55. $ticket3author = $ticket3.author.name
  56.  
  57. $ticket4 = $xml.feed.entry[3]
  58. $ticket4title = $ticket4.title
  59. $len = $ticket4.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
  60. if ($len -lt 80) { $ticket4summary = $ticket4.summary}else{$ticket4summary = $ticket4.summary.Substring(0,80) + "..."}
  61. $ticket4author = $ticket4.author.name
  62.  
  63. $ticket5 = $xml.feed.entry[4]
  64. $ticket5title = $ticket5.title
  65. $len = $ticket5.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
  66. if ($len -lt 80) { $ticket5summary = $ticket5.summary}else{$ticket5summary = $ticket5.summary.Substring(0,80) + "..."}
  67. $ticket5author = $ticket5.author.name
  68.  
  69.  
  70.  
  71. #Outputs an html table with added variables from section above
  72. function html-display {
  73.  
  74.     #Put a flashing alert if latest email less than 5minutes old
  75.     if (check-latestticket -eq $true){
  76.  
  77.          "<section class=`"contact-info`">
  78.            <span class=`"blink`" style=`"color:red`">New Ticket: $ticket1title </span>
  79.         </section>"
  80.  
  81.  
  82.     }else{
  83.     '<section class="contact-info">
  84.            <span class="blink"></span>
  85.         </section>'
  86.  
  87.  
  88.     }
  89.  
  90.  
  91.     "<table border=1 frame=void rules=rows >
  92.    <colgroup><col/><col/><col/><col/><col/><col/></colgroup>
  93.    <tr><th>Title</th><th>Summary</th><th>From</th></tr>
  94.    <tr><td>$Ticket1title</td><td>$ticket1summary</td><td>$ticket1author</td></tr>
  95.    <tr><td>$Ticket2title</td><td>$ticket2summary</td><td>$ticket2author</td>
  96.    <tr><td>$Ticket3title</td><td>$ticket3summary</td><td>$ticket3author</td>
  97.    <tr><td>$Ticket4title</td><td>$ticket4summary</td><td>$ticket4author</td>
  98.    <tr><td>$Ticket5title</td><td>$ticket5summary</td><td>$ticket5author</td>
  99.    </table>"
  100.  
  101.  
  102. }
  103.  
  104.  
  105. #Output html
  106. html-display
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement