Gmail feed: getting the body from the last letter. Powershell

I want to get the body of the latest gmail using my feed. Here is the code I have.

I also include results

$xml.feed.entry | Select *

What is:

title           : 
summary         : Test body
link            : link
modified        : 2018-02-10T21:06:18Z
issued          : 2018-02-10T21:06:18Z
id              : tag:gmail.google.com,2004:1592049563135473902
author          : author
Name            : entry
LocalName       : entry
NamespaceURI    : http://purl.org/atom/ns#
Prefix          : 
NodeType        : Element
ParentNode      : feed
OwnerDocument   : #document
IsEmpty         : False
Attributes      : {}
HasAttributes   : False
SchemaInfo      : System.Xml.XmlName
InnerXml        : <OMITTED>
InnerText       : <OMITTED>
NextSibling     : 
PreviousSibling : modified
Value           : 
ChildNodes      : {title, summary, link, modified...}
FirstChild      : title
LastChild       : author
HasChildNodes   : True
IsReadOnly      : False
OuterXml        : <OMITTED>
BaseURI         : 
PreviousText    :

`

I am using a function from dmitrysotnikov.wordpress.com to measure the last datetime value (it works). I just can't say to select the message body with the most recent date.

function Measure-Latest {
    begin { $latest = $null }
    process {
            if (($_ -ne $null) -and (($latest -eq $null) -or ($_ -gt 
$latest))) {
                $latest = $_ 
            }
    }
    end { $latest }
}

$webclient = new-object System.Net.WebClient

$webclient.Credentials = new-object System.Net.NetworkCredential 
("TEST123@gmail.com", "PASSWORD")

[xml]$xml= 
$webclient.DownloadString("https://mail.google.com/mail/feed/atom")

$latestmail = $xml.feed.entry.issued | Measure-Latest
+4
source share
1 answer

You are almost there! The final step is to indicate that you want an email message that has a timestamp $latestmailas a property issued, and that you want to use the property summaryfor this email message:

($xml.feed.entry | Where-Object {$_.issued -eq $latestmail}).summary
+2
source

Source: https://habr.com/ru/post/1693472/


All Articles