PoshCode Archive  Artifact [8d624b1de8]

Artifact 8d624b1de8290f9d95c91d56e3b81f37fa7a12dd15a70efb6e7fd5d6e0be8df6:

  • File mari07031986.ps1 — part of check-in [179626520b] at 2018-06-10 14:20:03 on branch trunk — Not for regular use, this is just a demo with using COM object to check new letters on gmail. (user: greg zakharov size: 1150)

# encoding: ascii
# api: powershell
# title: mari07031986
# description: Not for regular use, this is just a demo with using COM object to check new letters on gmail.
# version: 3.0
# type: function
# author: greg zakharov
# license: CC0
# function: Check-NewGmail
# x-poshcode-id: 6725
# x-archived: 2017-02-10T21:31:33
# x-published: 2017-02-07T15:28:00
#
#
function Check-NewGmail {
  param(
    [String]$Email = (Read-Host "Enter your email"),    
    [Security.SecureString]$Password = (Read-Host "Enter email password" -as)
  )
  
  function str([Security.SecureString]$s) {
    return [Runtime.InteropServices.Marshal]::PtrToStringAuto(
      [Runtime.InteropServices.Marshal]::SecureStringToBSTR($s)
    )
  }
  $com = New-Object -com MSXML2.XMLHTTP.3.0
  $com.open('GET', $('https://' + $Email + ':' + `
             (str $Password) + '@mail.google.com/mail/feed/atom'), $false)
  $com.setRequestHeader('Content-Type', 'application/x-www-from-urlcoded')
  $com.send()
  
  $com.responseText -match 'fullcount>\d+' | Out-Null; $res = ($matches[0] -split '>')[1]
  Write-Host You have $res new letter`(s`).
}