E-Mail Migration: From IMAP To Exchange
GoDaddy now offers Exchange e-mail hosting. So I decided to try to move from my IMAP e-mail provider to Exchange. Migrating all of my e-mails was difficult. I tried..
- Copying each folder through drag and drop in both Outlook and Thunderbird. Outlook occasionally locked up. And Thunderbird did recursively copy correctly and sometimes when it came across an email it couldn’t handle, it would go into a download message loop.
- Using the IMAPCopy program. It didn’t work for me and had problems with some of my emails and threw errors. Furthermore, if something happened and it got disconnected then I ended up having to find where it left off and continue otherwise it would recopy everything and make duplicates.
- Using imapsync perl script. This was a nightmare for me to try and setup and configure because it doesn’t support the most recent version of the perl IMAPClient class. Furthermore the dates didn’t sync correctly and it threw errors which I didn’t want to have to deal with and I got fed up with it.
The way I got all my emails migrated was..
Forcing Outlook to download the full e-mails from my IMAP server and using the resulting .PST to import my emails into the Exchange server. It was so much simpler and less prone to importation error. It was also a lot quicker than any of the scripts that I tried.
Also I would recommend this other post on changing when a message is marked read.
The Apprentice Returns!!
The Apprentice is like the characters on heroes, they die but their powers keep bringing them back to life. What powers did Donald Trump use to get The Apprentice back on the air? Perhaps his power is in his hair. If the Don hears something he doesn’t like his hair leaps off his head and attaches itself to the head of its prey and starts sucking the brains out of it.
Honestly, I’ve been a fan of the show forever and even I believe it doesn’t deserve to be on television anymore! It’s 2009 people!!! Where’s my flying car?!!! The show is OLD like all the has been celebrities that frequent it. It is time to give it a rest Don. Don’t you love it.. you know a show really sucks when they don’t even bother playing the full length intro anymore. Furthermore the show isn’t even in HD anymore. How can you go on television and say your show is the greatest on cable and it is not even in Hi-def. NBC, don’t bring The Apprentice back for season 9.. resist the whiles of the Don.
Firefox IFRAME Caching
There is a great post on the internet that gives a work around for iframes that are being cached. In my situation however, it did not work. Instead I was able to achieve the same thing, causing the IFRAME to be reloaded using..
frame.contentWindow.location.replace(frame.src);
Nvidia Drivers Break Remote Desktop AGAIN!
These are supposed to be WHQL’ed drivers!! You think they would check to make sure that remote desktop works after installing them. It happed in version 175.16 and now again in 180.48. Nvidia is putting a bad taste in my mouth. They have been known for long time for their great drivers (at least compared to ATI) and now I am not so sure anymore. You break my remote desktop once, shame on you, you break it twice, shame on me.
Bitwise Operations
Here’s a great resource for doing some common bit-wise tasks.
Bit Twiddling Hacks (http://graphics.stanford.edu/~seander/bithacks.html)
C# WPF Singleton Application
There are several tutorials out there for C# that show you how to make an application so that it can only have one instance. However most of the example code out there doesn’t do it properly or it uses the FindWindow function which is not the proper way to identify an application.
The code below basically registers a window message using your application’s GUID. Then it sends that message to all the open processes, seeing if any will respond to it. Processes that do respond to the window message that we registered, are ours, because we have code that also responds to our own window message. Once we identify that a window is ours, we then send a COPYDATA window message to it with the command line parameter that we want to pass to the instance of our application that is visible to the user.
Source Code:
public partial class App : Application
{
private static Mutex SingleMutex;
public static uint MessageId;
private void Application_Startup(object sender, StartupEventArgs e)
{
IntPtr Result;
IntPtr SendOk;
Win32.COPYDATASTRUCT CopyData;
string[] Args;
IntPtr CopyDataMem;
bool AllowMultipleInstances = false;
Args = Environment.GetCommandLineArgs();
// TODO: Replace {00000000-0000-0000-0000-000000000000} with your application's GUID
MessageId = Win32.RegisterWindowMessage("{00000000-0000-0000-0000-000000000000}");
SingleMutex = new Mutex(false, "AppName");
if ((AllowMultipleInstances) || (!AllowMultipleInstances && SingleMutex.WaitOne(1, true)))
{
new Main();
}
else if (Args.Length > 1)
{
foreach (Process Proc in Process.GetProcesses())
{
SendOk = Win32.SendMessageTimeout(Proc.MainWindowHandle, MessageId, IntPtr.Zero, IntPtr.Zero,
Win32.SendMessageTimeoutFlags.SMTO_BLOCK | Win32.SendMessageTimeoutFlags.SMTO_ABORTIFHUNG,
2000, out Result);
if (SendOk == IntPtr.Zero)
continue;
if ((uint)Result != MessageId)
continue;
CopyDataMem = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Win32.COPYDATASTRUCT)));
CopyData.dwData = IntPtr.Zero;
CopyData.cbData = Args[1].Length*2;
CopyData.lpData = Marshal.StringToHGlobalUni(Args[1]);
Marshal.StructureToPtr(CopyData, CopyDataMem, false);
Win32.SendMessageTimeout(Proc.MainWindowHandle, Win32.WM_COPYDATA, IntPtr.Zero, CopyDataMem,
Win32.SendMessageTimeoutFlags.SMTO_BLOCK | Win32.SendMessageTimeoutFlags.SMTO_ABORTIFHUNG,
5000, out Result);
Marshal.FreeHGlobal(CopyData.lpData);
Marshal.FreeHGlobal(CopyDataMem);
}
Shutdown(0);
}
}
}
/***********************************************************************/
public partial class Main : Window
{
private void Window_Loaded(object sender, RoutedEventArgs e)
{
HwndSource Source;
Source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
Source.AddHook(new HwndSourceHook(Window_Proc));
}
private IntPtr Window_Proc(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam, ref bool Handled)
{
Win32.COPYDATASTRUCT CopyData;
string Path;
if (Msg == Win32.WM_COPYDATA)
{
CopyData = (Win32.COPYDATASTRUCT)Marshal.PtrToStructure(lParam, typeof(Win32.COPYDATASTRUCT));
Path = Marshal.PtrToStringUni(CopyData.lpData, CopyData.cbData / 2);
if (WindowState == WindowState.Minimized)
{
// Restore window from tray
}
// Do whatever we want with information
Activate();
Focus();
}
if (Msg == App.MessageId)
{
Handled = true;
return new IntPtr(App.MessageId);
}
return IntPtr.Zero;
}
}
/***********************************************************************/
public class Win32
{
public const uint WM_COPYDATA = 0x004A;
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}
[Flags]
public enum SendMessageTimeoutFlags : uint
{
SMTO_NORMAL = 0x0000,
SMTO_BLOCK = 0x0001,
SMTO_ABORTIFHUNG = 0x0002,
SMTO_NOTIMEOUTIFNOTHUNG = 0x0008
}
[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern uint RegisterWindowMessage(string lpString);
[DllImport("user32.dll")]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam,
SendMessageTimeoutFlags fuFlags, uint uTimeout, out IntPtr lpdwResult);
}
C# String Wildcard Comparsion
Here are some string extensions that I use to compare wildcards. CompareWildcard compares only one wildcard (ie “*.txt”), while CompareWildcards compares multiple wildcards (ig “*.txt;*.zip;”).
Usage Example:
string Path = "c:\readme.txt";
if (Path.CompareWildcards("*.txt;*.zip;", true) == true)
{
// Path matches wildcard
}
Source code:
public static bool CompareWildcards(this string WildString, string Mask, bool IgnoreCase)
{
int i = 0;
if (String.IsNullOrEmpty(Mask))
return false;
if (Mask == "*")
return true;
while (i != Mask.Length)
{
if (CompareWildcard(WildString, Mask.Substring(i), IgnoreCase))
return true;
while (i != Mask.Length && Mask[i] != ';')
i += 1;
if (i != Mask.Length && Mask[i] == ';')
{
i += 1;
while (i != Mask.Length && Mask[i] == ' ')
i += 1;
}
}
return false;
}
public static bool CompareWildcard(this string WildString, string Mask, bool IgnoreCase)
{
int i = 0, k = 0;
while (k != WildString.Length)
{
switch (Mask[i])
{
case '*':
if ((i + 1) == Mask.Length)
return true;
while (k != WildString.Length)
{
if (CompareWildcard(WildString.Substring(k + 1), Mask.Substring(i + 1), IgnoreCase))
return true;
k += 1;
}
return false;
case '?':
break;
default:
if (IgnoreCase == false && WildString[k] != Mask[i])
return false;
if (IgnoreCase && Char.ToLower(WildString[k]) != Char.ToLower(Mask[i]))
return false;
break;
}
i += 1;
k += 1;
}
if (k == WildString.Length)
{
if (i == Mask.Length || Mask[i] == ';' || Mask[i] == '*')
return true;
}
return false;
}
Please feel free to post fixes, and suggestions in the comments below.







