0

I'm trying to use you impx.dll via PowerShell and am have difficulties trying to parse out the html.
Are there any examples anyon can help me with or point me in the right direction.

I am new to powershell and need any help I can get. - Thanks in advance!

I am using the following:

Start-Transcript -path C:\log.txt -append
$path = "C:\scripts"

[Reflection.Assembly]::LoadFile(“$path\imapx.dll”)

$Username = "user"
$Password = "pass"

# Initialize the IMAP client
$client = New-Object ImapX.ImapClient

###set the fetching mode to retrieve the part of message you want to retrieve, 
###the less the better
$client.Behavior.MessageFetchMode = "Full"
$client.Host = "webmailserverblabla"
$client.Port = 993
$client.UseSsl = $true
$client.Connect()
$client.Login($Username, $Password)

$messages = $client.Folders.Inbox.Search("ALL", $client.Behavior.MessageFetchMode, 100)

# Counts the number of emails in the inbox
write-host "Count found: $($messages.count)"

# loops through inbox for all subjects and writes them
foreach($m in $messages){

    $m.From.Address
    $m.Subject
    $m.UId
    $m.body.Text
    $m.DownloadRawMessage()
}


Output to parse:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
</style>
</head>
<body lang="EN-US" link="#xxxxxx" vlink="#xxxxxx" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Test<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal"><span style="color:#63666A">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:#005CB9">James</span></b><span style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:#005CB9"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body>
</html>
  • 1
    What do you mean by parse? Do you want the `...` text from the raw html? You will probably have to just regex out what you want. – Cpt.Whale May 03 '21 at 18:01
  • Yes, I want the ... text from the raw html? Not sure how to regex... – DigitalStimulants May 03 '21 at 18:40
  • 2
    You might also want to look at a library like the HtmlAgilityPack (https://html-agility-pack.net/) to process the html. If you use a regex you'll potentially end up with an unmaintainable regex-soup before you get very far... – mclayton May 03 '21 at 21:24
  • I would highly recommend the use of something like HtmlAgilityPack as well. – jstedfast May 19 '21 at 19:11

0 Answers0