Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $username = "email@domain.com"
- $password = "password"
- #Connect to gmail using webclient, using https://mail.google.com/mail/feed/atom
- function get-emails($a, $b){
- $webclient = new-object System.Net.WebClient
- $webclient.Credentials = new-object System.Net.NetworkCredential ("$a","$b")
- [xml]$xml= $webclient.DownloadString("https://mail.google.com/mail/feed/atom")
- $xml
- }
- #Check age of latest email by comparing time with now
- function check-latestticket {
- [datetime]$1stTime = $xml.feed.entry[0].modified
- if($1stTime -gt (Get-Date).AddMinutes("-5")){
- $true
- }else{
- $false
- }
- }
- #Retrieve emails, has to go before xml filtering at the moment
- $xml = get-emails $username $password
- #Filter xml for required data - this part needs improving
- $ticket1 = $xml.feed.entry[0]
- $ticket1title = $ticket1.title
- $len = $ticket1.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
- if ($len -lt 80) { $ticket1summary = $ticket1.summary}else{$ticket1summary = $ticket1.summary.Substring(0,80) + "..."}
- $ticket1author = $ticket1.author.name
- $ticket2 = $xml.feed.entry[1]
- $ticket2title = $ticket2.title
- $len = $ticket2.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
- if ($len -lt 80) { $ticket2summary = $ticket2.summary}else{$ticket2summary = $ticket2.summary.Substring(0,80) + "..."}
- $ticket2author = $ticket2.author.name
- $ticket3 = $xml.feed.entry[2]
- $ticket3title = $ticket3.title
- $len = $ticket3.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
- if ($len -lt 80) { $ticket3summary = $ticket3.summary}else{$ticket3summary = $ticket3.summary.Substring(0,80) + "..."}
- $ticket3author = $ticket3.author.name
- $ticket4 = $xml.feed.entry[3]
- $ticket4title = $ticket4.title
- $len = $ticket4.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
- if ($len -lt 80) { $ticket4summary = $ticket4.summary}else{$ticket4summary = $ticket4.summary.Substring(0,80) + "..."}
- $ticket4author = $ticket4.author.name
- $ticket5 = $xml.feed.entry[4]
- $ticket5title = $ticket5.title
- $len = $ticket5.summary| Measure-Object -Character | Select-Object -ExpandProperty Characters
- if ($len -lt 80) { $ticket5summary = $ticket5.summary}else{$ticket5summary = $ticket5.summary.Substring(0,80) + "..."}
- $ticket5author = $ticket5.author.name
- #Outputs an html table with added variables from section above
- function html-display {
- #Put a flashing alert if latest email less than 5minutes old
- if (check-latestticket -eq $true){
- "<section class=`"contact-info`">
- <span class=`"blink`" style=`"color:red`">New Ticket: $ticket1title </span>
- </section>"
- }else{
- '<section class="contact-info">
- <span class="blink"></span>
- </section>'
- }
- "<table border=1 frame=void rules=rows >
- <colgroup><col/><col/><col/><col/><col/><col/></colgroup>
- <tr><th>Title</th><th>Summary</th><th>From</th></tr>
- <tr><td>$Ticket1title</td><td>$ticket1summary</td><td>$ticket1author</td></tr>
- <tr><td>$Ticket2title</td><td>$ticket2summary</td><td>$ticket2author</td>
- <tr><td>$Ticket3title</td><td>$ticket3summary</td><td>$ticket3author</td>
- <tr><td>$Ticket4title</td><td>$ticket4summary</td><td>$ticket4author</td>
- <tr><td>$Ticket5title</td><td>$ticket5summary</td><td>$ticket5author</td>
- </table>"
- }
- #Output html
- html-display
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement