-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmail-check.ps1
51 lines (37 loc) · 1.45 KB
/
mail-check.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
if (-not (Get-Module Mailozaurr -ListAvailable)) {
Install-Module Mailozaurr -AllowClobber -Force
}
Import-Module -Name Mailozaurr -Force
# Enter PSScriptRoot
cd $PSScriptRoot
# Init
. "$PSScriptRoot\init.ps1"
# Import config
. "$PSScriptRoot\config.ps1"
# IMAP client
if ($SkipCertificateCheck -eq 'true') { [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } }
$Client = Connect-IMAP -Server $Server -Password $Password -UserName $Account -Port 993 -Options Auto
Get-IMAPFolder -FolderAccess ReadWrite -Client $Client -Verbose
$inbox = $Client.data.Inbox.Search("All")
# Moving processed emails to preexisting Junk folder
$MoveToFolder = $Client.data.GetFolder("$MoveMailToFolder")
#loop through email UID-s and retrieve messages
function Get-Headers {
foreach ($id in $inbox.UniqueIds) {
$Client.data.Inbox.GetMessage($id)
$Client.Data.Inbox.GetMessage($id).from.address
$Client.Data.Inbox.GetMessage($id).to.address
$Client.Data.Inbox.MoveTo($id, $MoveToFolder)
}
}
# Import contacts
. "$PSScriptRoot\contacts.ps1"
# Match email to phone numbers and write to file
foreach ($line in $(Get-Headers | Select-String -Pattern [a-zA-Z0-9_.-]+@$domain | foreach { $_.Matches.Value }) | Get-Unique ) {
if ($contacts.ContainsKey($line)) {
$phone = $contacts[$line]
$phone | Out-File -Append $Callfile -Force
}
}
# Disconnect from the IMAP server.
Disconnect-IMAP -Client $Client