Calling an external batch file for each message

using System;
using System.Collections.Generic;
using System.Text;
using FTGate.Framework;
using System.IO;
using System.Diagnostics;

// spooler extension to run batch file for each message in the spooler
// working folder is same as spooler inbox

public class SpoolerExtension : SpoolBehaviour
{
    private const string strCommand = @"C:\test.bat";

    /// 
    /// Called by a the spooler when it starts processing a new message
    ///  
    public ProcessMessageReturnType OnPreProcessMessage(MailMessage message)
    {
        Log log = new Log();
        log.Write(LogType.Normal, "spooler script running");
		try
		{
            System.Diagnostics.ProcessStartInfo processInfo;
            System.Diagnostics.Process process;

            processInfo = new ProcessStartInfo("cmd.exe", "/c " + strCommand+" "+message.textPath);
            processInfo.CreateNoWindow = true;
            processInfo.UseShellExecute = false;
            // *** Redirect the output ***
            processInfo.RedirectStandardError = false;
            processInfo.RedirectStandardOutput = false;

            process = Process.Start(processInfo);
            process.WaitForExit();
            //return ProcessMessageReturnType.RequestDelete;
		}
		catch(Exception e)
		{
            log.Write(LogType.Normal, "spooler script error: " + e.Message);

			return ProcessMessageReturnType.Error; // also same as Continue (doesnt delete message)
		}
		return ProcessMessageReturnType.Continue;
    }
}

Alter the subject line of a message in the spooler

using System;
using System.Collections.Generic;
using System.Text;
using FTGate.Framework;
using System.IO;

public class SpoolerExtension : SpoolBehaviour
{
	private const string TAG = "[ext]";
    private bool prepend = true;

    /// 
    /// Called by a the spooler when it starts processing a new message
    ///  
    public ProcessMessageReturnType OnPreProcessMessage(MailMessage message)
    {
		string filePath = Path.GetDirectoryName(message.textPath);
		string fileName = Path.GetFileNameWithoutExtension(message.textPath);

		string fullSrcPath = filePath + @"\" + fileName + ".txt";
		string fullDstPath = filePath + @"\" + fileName + ".tmp";
        Log log=new Log();
		try
		{
            // open the file and read lines 
            // find the header line we want and alter it, then process all the other lines
            bool isTagged = false;
            bool isInbound = false;
            FileStream fin = File.Open(fullSrcPath, FileMode.Open);
            FileStream fout = File.Open(fullDstPath, FileMode.Create);
            StreamReader sr = new StreamReader(fin);
            StreamWriter sw = new StreamWriter(fout);
            string line="";
            while ((line = sr.ReadLine()) != null)
            {
                if (!isInbound && line.Contains("by FTGate SmartPop;"))
                    isInbound = true;
                if (!isTagged && isInbound && line.StartsWith("subject:", StringComparison.OrdinalIgnoreCase))
                {
                    isTagged = true;
                    if (!line.Contains(TAG))
                    {
                        if (prepend)
                            line = "Subject: " + TAG + line.Substring(8);
                        else
                            line = line + " " + TAG;
                    }
                }
                sw.WriteLine(line);
            }
            fin.Close();
            fout.Close();
            // now delete the origial
            File.Delete(fullSrcPath);
            // and rename the new
            File.Move(fullDstPath, fullSrcPath);
			log.Write(LogType.Normal, "Tag: Success " + fileName);
		}
		catch(Exception e)
		{
			log.Write(LogType.Normal, "Tag error: " + fileName + ": " + e.Message);
			return ProcessMessageReturnType.Error; // also same as Continue (doesnt delete message)
		}
		return ProcessMessageReturnType.Continue;
    }
}