<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>No Znx! &#187; exchange</title>
	<atom:link href="http://znx.no/tag/exchange/feed/" rel="self" type="application/rss+xml" />
	<link>http://znx.no</link>
	<description>the pigeons!!!!</description>
	<lastBuildDate>Tue, 20 Dec 2011 22:42:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Better E-Mail Checking!</title>
		<link>http://znx.no/2008/12/better-e-mail-checking/</link>
		<comments>http://znx.no/2008/12/better-e-mail-checking/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 23:12:18 +0000</pubDate>
		<dc:creator>znx</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[exchange]]></category>
		<category><![CDATA[ms]]></category>

		<guid isPermaLink="false">http://znx.no/?p=60</guid>
		<description><![CDATA[A mate of mine was reading this and made some great comments about it! First up there is a Bash version of expect (THANK GOD!). Secondly fetchmail maybe a better solution to grabbing the mail to see if it was received, another good comment! Unfortunately for me I was working on a system with the [...]]]></description>
			<content:encoded><![CDATA[<p>A <a title="Dustybin" href="http://www.thinkdebian.org/">mate of mine</a> was reading this and made some great comments about it! First up there is a Bash version of <a title="BASH Version of Expect" href="http://empty.sourceforge.net">expect</a> (THANK GOD!). Secondly fetchmail maybe a better solution to grabbing the mail to see if it was received, another good comment! Unfortunately for me I was working on a system with the tools that were available to me, that means no fetchmail and no empty installed.</p>
<p>Interestingly it didn&#8217;t initially work 100% of the time, after a little bit of testing it looked like Microsoft were temporarily throwing away some of the test e-mails. Interesting as it must mean that they look for repetitious e-mails in a bid to fight SPAM. We of course simply contacted MS and got it sorted and now the e-mails come in every hour.</p>
<p>What this does show us though, is that under UNIX/Linux there is a lot of different solutions that can be made, but sometimes you have to work with the tools that are there.</p>
]]></content:encoded>
			<wfw:commentRss>http://znx.no/2008/12/better-e-mail-checking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>E-Mail Checking</title>
		<link>http://znx.no/2008/12/e-mail-checking/</link>
		<comments>http://znx.no/2008/12/e-mail-checking/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 22:11:31 +0000</pubDate>
		<dc:creator>znx</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[exchange]]></category>
		<category><![CDATA[ms]]></category>

		<guid isPermaLink="false">http://znx.no/?p=55</guid>
		<description><![CDATA[At my work we have two domains and recently one of those domains was blacklisted, thanks to some phishing e-mails hitting their marks. So I was tasked today to setup an automated e-mail send and check. To ensure that we can send between our domains. First up I checked to see that I was able [...]]]></description>
			<content:encoded><![CDATA[<p>At my work we have two domains and recently one of those domains was blacklisted, thanks to some phishing e-mails hitting their marks. So I was tasked today to setup an automated e-mail send and check. To ensure that we can send between our domains.</p>
<p>First up I checked to see that I was able to get a POP3 connection to the other domain, as it is hosted by Microsoft for us. Whilst I was able to connect via POP3 I was unable to login. A quick check revealed that only POP3S was being accepted. This meant that I was going to need to utilize the simple s_client tool available with OpenSSL.</p>
<p>So to testing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl s_client <span style="color: #660033;">-connect</span> SERVER:<span style="color: #000000;">995</span>
.... blah blah ....
+OK The POP3 Service is ready.
USER test.user<span style="color: #000000; font-weight: bold;">@</span>example.com
^C
$</pre></div></div>

<p>Hrmm, what&#8217;s going on here, the server isn&#8217;t responding to my USER. A quick brain check and I spotted my issue, line endings!</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl s_client <span style="color: #660033;">-connect</span> SERVER:<span style="color: #000000;">995</span> <span style="color: #660033;">-crlf</span>
.... blah blah ....
+OK The POP3 Service is ready.
USER test.user<span style="color: #000000; font-weight: bold;">@</span>example.com
+OK
PASS mypassword
+OK User successfully logged in.
STAT
+OK <span style="color: #000000;">49</span> <span style="color: #000000;">2758446</span>
QUIT
DONE</pre></div></div>

<p>That&#8217;s more like it. Now I know that I can connect, logged and run arbitrary commands. It may be perfectly OK to manually check like this but that isn&#8217;t the reason we started this, we want an automated solution.</p>
<p>The most obvious solution here is <strong>expect</strong>, ugh TCL! With the above information it is easy to write a simple expect script:</p>

<div class="wp_syntax"><div class="code"><pre class="tcl" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env expect</span>
spawn openssl s_client -connect SERVER:<span style="color: #ff4500;">995</span> -crlf
expect <span style="color: #483d8b;">&quot;+OK The POP3 service is ready.&quot;</span>
send <span style="color: #483d8b;">&quot;USER test.user@example.com<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK&quot;</span>
send <span style="color: #483d8b;">&quot;PASS mypassword<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK User successfully logged on.&quot;</span>
send <span style="color: #483d8b;">&quot;QUIT<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;DONE&quot;</span>
expect <span style="color: #008000;">eof</span></pre></div></div>

<p>Simple enough, send a command and expect a response. Obviously it helps if you understand the protocol that you are dealing with. Running that script happily logs in and then quits. Sweet, we are halfway there already!</p>
<p>So to recap, I plan on sending an e-mail from the first domain to my test account on the second domain and then check that the e-mail actually arrived. Thus proving that the e-mail was getting through without issue. So when I do this I will wish to get the newest e-mail in my INBOX, which may not the be the first. So the script needs some modifying.</p>

<div class="wp_syntax"><div class="code"><pre class="tcl" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env expect</span>
spawn openssl s_client -connect SERVER:<span style="color: #ff4500;">995</span> -crlf
expect <span style="color: #483d8b;">&quot;+OK The POP3 service is ready.&quot;</span>
send <span style="color: #483d8b;">&quot;USER test.user@example.com<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK&quot;</span>
send <span style="color: #483d8b;">&quot;PASS mypassword<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK User successfully logged on.&quot;</span>
send <span style="color: #483d8b;">&quot;STAT<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect -re <span style="color: #483d8b;">&quot;OK (.*) .*&quot;</span> <span style="color: black;">&#123;</span>
  <span style="color: #ff7700;font-weight:bold;">set</span> number <span style="color: #ff3333;">$expect_out</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #008000;">string</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#125;</span>
send <span style="color: #483d8b;">&quot;TOP $number 1<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK&quot;</span>
send <span style="color: #483d8b;">&quot;QUIT<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;DONE&quot;</span>
expect <span style="color: #008000;">eof</span></pre></div></div>

<p>Now expect will grab the number of e-mails in the INBOX and request the headers of the newest one. So the final step is integrating this with a simple check. Lets just use a shell script to check with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">TS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Subject: TESTING <span style="color: #007800;">$TS</span>
&nbsp;
Hi,
&nbsp;
This is a test please do not delete me!
&nbsp;
Thanks&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> mail test.user<span style="color: #000000; font-weight: bold;">@</span>example.com
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">60</span>
expect collect.exp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$TS</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> \
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Success The E-Mail Arrived!&quot;</span> <span style="color: #000000; font-weight: bold;">||</span>\
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Failure The E-Mail Was Not Found!&quot;</span></pre></div></div>

<p>That works, a test and we have a success! We find the TS in the subject line of the e-mail. There is a minor problem here, what happens if I e-mail the test and in-between I receive some other e-mails, hrmm! OK so why don&#8217;t we dump the headers of the first few e-mails, we certainly don&#8217;t expect a rush of e-mails on a test account within a minute. Let&#8217;s change the expect script just a bit more:</p>

<div class="wp_syntax"><div class="code"><pre class="tcl" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env expect</span>
&nbsp;
spawn openssl s_client -connect SERVER:<span style="color: #ff4500;">995</span> -crlf
expect <span style="color: #483d8b;">&quot;+OK The POP3 service is ready.&quot;</span>
send <span style="color: #483d8b;">&quot;USER test.user@example.com<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK&quot;</span>
send <span style="color: #483d8b;">&quot;PASS mypassword<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK User successfully logged on.&quot;</span>
send <span style="color: #483d8b;">&quot;STAT<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect -re <span style="color: #483d8b;">&quot;OK (.*) .*&quot;</span> <span style="color: black;">&#123;</span>
  <span style="color: #ff7700;font-weight:bold;">set</span> number <span style="color: #ff3333;">$expect_out</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #008000;">string</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#125;</span>
send <span style="color: #483d8b;">&quot;TOP $number 1<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK&quot;</span>
<span style="color: #ff7700;font-weight:bold;">set</span> number <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$number</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
send <span style="color: #483d8b;">&quot;TOP $number 1<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK&quot;</span>
<span style="color: #ff7700;font-weight:bold;">set</span> number <span style="color: black;">&#91;</span><span style="color: #ff7700;font-weight:bold;">expr</span> <span style="color: #ff3333;">$number</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
send <span style="color: #483d8b;">&quot;TOP $number 1<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;+OK&quot;</span>
send <span style="color: #483d8b;">&quot;QUIT<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
expect <span style="color: #483d8b;">&quot;DONE&quot;</span>
expect <span style="color: #008000;">eof</span></pre></div></div>

<p>Placing the shell script into a crontab and we are done. Yet another example of how simple scripting can achieve anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://znx.no/2008/12/e-mail-checking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exchange Restores</title>
		<link>http://znx.no/2008/09/exchange-restores/</link>
		<comments>http://znx.no/2008/09/exchange-restores/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 15:16:44 +0000</pubDate>
		<dc:creator>znx</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[exchange]]></category>
		<category><![CDATA[ms]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://znx.no/?p=7</guid>
		<description><![CDATA[Exchange is a massive enterprise tool and as such you&#8217;d expect it to provide a simple method for restoring mail folders. No such luck! Instead a restore on exchange is quite a long process. First up you need to discover the storage group that your mailbox is in. This requires a quick search on an [...]]]></description>
			<content:encoded><![CDATA[<p>Exchange is a massive enterprise tool and as such you&#8217;d expect it to provide a simple method for restoring mail folders. No such luck! Instead a restore on exchange is quite a long process.</p>
<p>First up you need to discover the storage group that your mailbox is in. This requires a quick search on an active directory server. Once you have that you can go on to create a &#8216;recovery storage group&#8217; linking it to the correct storage group.</p>
<p>Then you start up your TSM restore and recover the storage group (we use TSM as our backup). On our setup that means that you are restoring approximately 20Gb of data. Once thats done (it can take a while), we can then mount the recovery group. At this point we are left with one of two options: copy all the mail and folders into your existing mail account effectively doubling your mail, or you can merge the contents back into your mail so only copying what is missing.</p>
<p>My issue is that neither of these options are really what a use wants. If we copy the mail back, then we effectively double the amount of mail that a user has. If we merge the data back, it can merge e-mails back into folders that maybe the user will not look at, thus leaving behind stray meant-to-be-deleted e-mails. Nine times out of ten all the user has lost is a single folder or a single mail.</p>
<p>The solution to this is to add another step into the process, extract the mailbox from the recovery group into a PST file, then merge the folder out of the PST file back into the mailbox in the main storage group. But even here there is a problem, if you don&#8217;t know the exact folder name you can&#8217;t find out what it is and therefore cannot restore it.</p>
<p>In reality what is needed here is a solution that allows the administrators the ability to extract individual folders within a mailbox. It is obvious that the exchange restores are built with the intent of only being used in a situation of disaster, total loss of a storage group or something similar. However almost all the restores undertaken will be for single users.</p>
<p>Looking back to the old method we used with exim makes this look even more silly. As there we could simply find the file representing the mail folder and restore it. Done!</p>
]]></content:encoded>
			<wfw:commentRss>http://znx.no/2008/09/exchange-restores/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

