<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Im code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 21:00:17 GMT</pubDate>
    <description>DZone Snippets: Im code</description>
    <item>
      <title>Post a message to identi.ca using XMPP via HTTP</title>
      <link>http://snippets.dzone.com/posts/show/5739</link>
      <description>This Ruby code posts a message to identi.ca using XMPP which uses a simple web server.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;&lt;br /&gt;require 'rubygems'  &lt;br /&gt;require 'socket'&lt;br /&gt;require 'open-uri'&lt;br /&gt;require 'xmpp4r-simple'&lt;br /&gt;&lt;br /&gt;server = TCPServer.new('127.0.0.1', 9090)&lt;br /&gt;messenger = Jabber::Simple.new('my-bot@gmail.com', "bot-password")&lt;br /&gt;&lt;br /&gt;while (session = server.accept)&lt;br /&gt;  request = session.gets&lt;br /&gt;  project = request[/(\w+)\?msg=(.*) HTTP\/1.1/,1]&lt;br /&gt;  msg = URI.unescape($2)&lt;br /&gt;&lt;br /&gt;  puts request&lt;br /&gt;  session.print "HTTP/1.1 200/OK\rContent-type: text/html\r\n\r\n"&lt;br /&gt;  session.print "&lt;html&gt;&lt;head&gt;&lt;title&gt;Response from Jeeves&lt;/title&gt;&lt;/head&gt;\r\n"&lt;br /&gt;  session.print "&lt;body&gt;"&lt;br /&gt;&lt;br /&gt;  if project != '' and msg != '' then&lt;br /&gt;    case project&lt;br /&gt;      when 'identica'&lt;br /&gt;        messenger.deliver("update@identi.ca", msg)&lt;br /&gt;    else&lt;br /&gt;      puts "Project #{project} wasn't found on this server"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  session.print URI.unescape(request)&lt;br /&gt;&lt;br /&gt;  session.print "&lt;/body&gt;&lt;/html&gt;"&lt;br /&gt;  session.close&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;To post the message you would type your message within the browser URL e.g. http://127.0.0.1:9090/identica?msg=just%20testing%20xmpp4r-simple%20from%20tcpserver1&lt;br /&gt;</description>
      <pubDate>Tue, 08 Jul 2008 20:03:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5739</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Make your own IM bot in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5710</link>
      <description>The following code was copied from the article &lt;a href="http://rubypond.com/articles/2008/06/26/make-your-own-im-bot-in-ruby-and-interface-it-with-your-rails-app"&gt;'Make your own IM bot in Ruby, and interface it with your Rails app'&lt;/a&gt; [rubypond.com].&lt;br /&gt;&lt;br /&gt;installation:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;git clone git://github.com/ln/xmpp4r.git xmpp4r&lt;br /&gt;cd xmpp4r&lt;br /&gt;rake gem:install&lt;br /&gt;sudo gem install xmpp4r-simple&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;connect:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'  &lt;br /&gt;require 'xmpp4r-simple'&lt;br /&gt;messenger = Jabber::Simple.new('my-bot@gmail.com', "bot-password")&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;send:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;messenger.deliver("a-real-person@gmail.com", "Why hello there Mr. Person, your bot is here now!") &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;listen:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;while true&lt;br /&gt;  messenger.received_messages do |msg|  &lt;br /&gt;    puts msg.body  &lt;br /&gt;    messenger.deliver("a-real-person@gmail.com", "Got your message, thanks!")  &lt;br /&gt;  end  &lt;br /&gt;  sleep 2  &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;at your service:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'  &lt;br /&gt;require 'xmpp4r-simple'&lt;br /&gt;messenger = Jabber::Simple.new('my-bot@gmail.com', "bot-password")&lt;br /&gt;while true&lt;br /&gt;  messenger.received_messages do |msg|&lt;br /&gt;    user = User.find_by_im_name(msg.from)&lt;br /&gt;    if user&lt;br /&gt;      case msg.body&lt;br /&gt;      when /^help /i&lt;br /&gt;        messenger.deliver(msg.from, "Valid commands are......")  &lt;br /&gt;      when /^status /i&lt;br /&gt;        user.status = msg.body.sub(/^status /i)&lt;br /&gt;        user.save&lt;br /&gt;        messenger.deliver(msg.from, "Thanks #{user.first_name}, your status has been updated")  &lt;br /&gt;      when /^balance\?/i&lt;br /&gt;        messenger.deliver(msg.from, "#{user.first_name}, your current remaining balance is #{user.remaining_balance}")  &lt;br /&gt;      else&lt;br /&gt;        messenger.deliver(msg.from, "Sorry #{user.first_name}, I didn't understand that. Message me with 'help' for a list of commands")  &lt;br /&gt;      end&lt;br /&gt;    else&lt;br /&gt;      messenger.deliver(msg.from, "Sorry, but we've not got this account registered on our system. Sign-up or update your details at http://www.mysite.com/")  &lt;br /&gt;    end    &lt;br /&gt;  end  &lt;br /&gt;  sleep 2  &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 29 Jun 2008 18:42:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5710</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>May fortune be my IM status.</title>
      <link>http://snippets.dzone.com/posts/show/5049</link>
      <description>// Tired of having others have cooler status on their IM clients,&lt;br /&gt;// I decided that I shall put an end to that.&lt;br /&gt;// Yet, I am no factory of coolness, but I figured my favorite buddy,&lt;br /&gt;// "fortune" will help me out a little.&lt;br /&gt;&lt;br /&gt;// By the way, this tool can definitely be done much better with regard&lt;br /&gt;// to the way it updates the MSN, but hey, I just wanted to play with&lt;br /&gt;// C#. My first time :P&lt;br /&gt;&lt;br /&gt;// BTW, the MSN thing works only if you have your MSN not minimized PLUS&lt;br /&gt;// the toolbar showing. (LAME! I know.)&lt;br /&gt;&lt;br /&gt;// If you really want to do it right, use http://www.xihsolutions.net/dotmsn/&lt;br /&gt;// and send me the code ;) bhtek@yahoo.com&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;using Microsoft.Win32;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Windows.Automation;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;namespace ZenStatusUpdater&lt;br /&gt;{&lt;br /&gt;    class Program &lt;br /&gt;    {&lt;br /&gt;        [DllImport("USER32.DLL", EntryPoint = "FindWindowA", CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;        private static extern IntPtr FindWindow(string sClassName, string sWindowName);&lt;br /&gt;&lt;br /&gt;        [DllImport("USER32.DLL", EntryPoint = "PostMessageA", CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;        private static extern bool PostMessage(IntPtr hWnd, uint iMsg, long wParam, long lParam); &lt;br /&gt;&lt;br /&gt;        static void exploreElement(AutomationElement sub)&lt;br /&gt;        {&lt;br /&gt;            foreach (AutomationProperty prop in sub.GetSupportedProperties())&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("\tProp[" + prop.ProgrammaticName + "]: " + sub.GetCurrentPropertyValue(prop));&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            foreach (AutomationPattern pat in sub.GetSupportedPatterns())&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("\tPat[" + pat.ProgrammaticName + "]");&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        static void explore(AutomationElement el)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Self...");&lt;br /&gt;            exploreElement(el);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            foreach (AutomationElement sub in el.FindAll(TreeScope.Descendants, Condition.TrueCondition))&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("Sub...");&lt;br /&gt;                exploreElement(sub);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            String fortune = null;&lt;br /&gt;            int tries = 0;&lt;br /&gt;&lt;br /&gt;            do&lt;br /&gt;            {&lt;br /&gt;                fortune = GetFortune();&lt;br /&gt;                tries++;&lt;br /&gt;            } while (fortune.Length &gt; 130);&lt;br /&gt;&lt;br /&gt;            Console.WriteLine("Try #" + tries + ": " + fortune);&lt;br /&gt;&lt;br /&gt;            updateMsnStatus(fortune);&lt;br /&gt;            updateYahooStatus(fortune);&lt;br /&gt;&lt;br /&gt;            System.Threading.Thread.Sleep(5000);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected static void updateYahooStatus(String fortune)&lt;br /&gt;        {&lt;br /&gt;            // Get the current signed in user&lt;br /&gt;            //&lt;br /&gt;            string sUserName = "bhtek";&lt;br /&gt;            Console.WriteLine("The currently logged in user is " + sUserName);&lt;br /&gt;&lt;br /&gt;            // Now open the current user's profile and set the current status message, pass true to&lt;br /&gt;            // OpenSubKey to request write access&lt;br /&gt;&lt;br /&gt;            RegistryKey keyYahooCustomMessages = Registry.CurrentUser.OpenSubKey("Software\\Yahoo\\Pager\\profiles\\"&lt;br /&gt;            + sUserName + "\\Custom Msgs", true);&lt;br /&gt;&lt;br /&gt;            // Set the 5th message, seems like yahoo messenger has the functionality to move the newly set&lt;br /&gt;            // message up as the first one.&lt;br /&gt;            String status = fortune;&lt;br /&gt;            keyYahooCustomMessages.SetValue("5", status);&lt;br /&gt;            byte[] statusBin = (new ASCIIEncoding()).GetBytes(status);&lt;br /&gt;            keyYahooCustomMessages.SetValue("5_bin", (byte[])statusBin); &lt;br /&gt;            keyYahooCustomMessages.Close();&lt;br /&gt;                &lt;br /&gt;            // We are done setting the value in the registry. We now need to notify y! of this change&lt;br /&gt;            //&lt;br /&gt;&lt;br /&gt;            // Find the yahoo messenger window and sent it the notification&lt;br /&gt;            // 0x111: WM_COMMAND&lt;br /&gt;            // 0x188: Code 392&lt;br /&gt;&lt;br /&gt;            IntPtr hWndY = FindWindow("YahooBuddyMain", null);&lt;br /&gt;            System.Diagnostics.Debug.WriteLine("Find window got: " + hWndY.ToString());&lt;br /&gt;            PostMessage(hWndY, 0x111, 0x188, 0);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected static void updateMsnStatus(String fortune)&lt;br /&gt;        {&lt;br /&gt;            AutomationElementCollection msnWindows = AutomationElement.RootElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "MSBLWindowClass"));&lt;br /&gt;            if (msnWindows.Count &gt; 1)&lt;br /&gt;            {&lt;br /&gt;                foreach (AutomationElement potentialMsn in msnWindows)&lt;br /&gt;                {&lt;br /&gt;                    exploreElement(potentialMsn);&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                return;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            AutomationElement msn = msnWindows[0];&lt;br /&gt;            msn.SetFocus();&lt;br /&gt;&lt;br /&gt;            AutomationElement tools = msn.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AccessKeyProperty, "Alt+T"));&lt;br /&gt;            ExpandCollapsePattern toolsPat = (ExpandCollapsePattern)tools.GetCurrentPattern(ExpandCollapsePattern.Pattern);&lt;br /&gt;            toolsPat.Expand();&lt;br /&gt;&lt;br /&gt;            AutomationElement options = tools.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Options..."));&lt;br /&gt;            InvokePattern optionsPat = (InvokePattern)options.GetCurrentPattern(InvokePattern.Pattern);&lt;br /&gt;            optionsPat.Invoke();&lt;br /&gt;&lt;br /&gt;            AutomationElement optionsWindow = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Options"));&lt;br /&gt;&lt;br /&gt;            AutomationElement personalMessage = optionsWindow.FindFirst(TreeScope.Descendants,&lt;br /&gt;                new AndCondition(&lt;br /&gt;                    new PropertyCondition(AutomationElement.ClassNameProperty, "RichEdit20W"),&lt;br /&gt;                    new PropertyCondition(AutomationElement.NameProperty, "Type a personal message for your contacts to see:")&lt;br /&gt;                    )&lt;br /&gt;            );&lt;br /&gt;            ValuePattern personalMessagePat = (ValuePattern)personalMessage.GetCurrentPattern(ValuePattern.Pattern);&lt;br /&gt;            personalMessagePat.SetValue(fortune);&lt;br /&gt;&lt;br /&gt;            AutomationElement ok = optionsWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "OK"));&lt;br /&gt;            InvokePattern okPat = (InvokePattern)ok.GetCurrentPattern(InvokePattern.Pattern);&lt;br /&gt;            okPat.Invoke();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static String GetFortune()&lt;br /&gt;        {&lt;br /&gt;            System.Diagnostics.Process process = new System.Diagnostics.Process();&lt;br /&gt;            process.StartInfo.FileName = "c:\\cygwin\\bin\\fortune.exe";&lt;br /&gt;            process.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;            process.StartInfo.UseShellExecute = false;&lt;br /&gt;            process.Start();&lt;br /&gt;            String fortune = process.StandardOutput.ReadToEnd();&lt;br /&gt;&lt;br /&gt;            fortune = System.Text.RegularExpressions.Regex.Replace(fortune, "\\s+", " ");&lt;br /&gt;            return fortune;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;       &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 29 Jan 2008 11:54:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5049</guid>
      <author>bhtek (Boon Hian Tek)</author>
    </item>
    <item>
      <title>Quick and dirty email server checker, python</title>
      <link>http://snippets.dzone.com/posts/show/4024</link>
      <description>// description of your code here&lt;br /&gt;This sends an email from a gmail account with a GUID for the subject to another email account, and then writes this GUID to file. On the other end, the other half of the program checks the GUID in the recieved message and matches it to the GUID in the file to verify that the message has been recieved. I schedule the sender to run every ten minutes, and the reciever/checker to run every minute. The reciever has a threshold value of 20 so if it has checked 20 times and not recieved the email it sends an IM to my gmail account. Whew is that contrived or what.  &lt;br /&gt;&lt;code&gt;&lt;br /&gt;// First part, email sender, schedule to run every 10 minutes or so&lt;br /&gt;// this uses GUID from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/163604&lt;br /&gt;&lt;br /&gt;from smtplib import SMTP&lt;br /&gt;from socket import sslerror         #if desired&lt;br /&gt;import Guid&lt;br /&gt;import os&lt;br /&gt;&lt;br /&gt;guidSubj = Guid.generate()&lt;br /&gt;guidBod1 = Guid.generate()&lt;br /&gt;guidBod2 = Guid.generate()&lt;br /&gt;&lt;br /&gt;if not os.path.exists("sent.txt"):   #check whether the file exists, if not create it&lt;br /&gt;    fileHandle = open('sent.txt','w')&lt;br /&gt;    fileHandle.write (guidSubj)&lt;br /&gt;    fileHandle.close()&lt;br /&gt;    server = SMTP('smtp.gmail.com',587)&lt;br /&gt;    server.set_debuglevel(1) # or 1 for verbosity&lt;br /&gt;    server.ehlo('user@gmail.com')&lt;br /&gt;    server.starttls()&lt;br /&gt;    server.ehlo('user@gmail.com')  # say hello again&lt;br /&gt;    server.login('user@gmail.com', 'password')&lt;br /&gt;    # i have a suspicion that smptlib does not add the required newline dot newline so i do it myself&lt;br /&gt;    server.sendmail('user@gmail.com', 'user@place.com', "Subject:Ping," + guidSubj + '\n\n' + guidBod1 + '\n\n' + guidBod2 + '\n.\n')&lt;br /&gt;    # next line generates the ignorable socket.sslerror&lt;br /&gt;    server.quit()&lt;br /&gt;&lt;br /&gt;// Second email checker/reciever, check every minute or so&lt;br /&gt;# This script is a helper to clean POP3 mailboxes&lt;br /&gt;# containing malformed mails that hangs MUA's, that &lt;br /&gt;# are too large, or whatever...&lt;br /&gt;#&lt;br /&gt;# It iterates over the non-retrieved mails, prints&lt;br /&gt;# selected elements from the headers and prompt the &lt;br /&gt;# user to delete bogus messages.&lt;br /&gt;#&lt;br /&gt;# Written by Xavier Defrang &lt;xavier.defrang@brutele.be&gt;&lt;br /&gt;# &lt;br /&gt;&lt;br /&gt;# &lt;br /&gt;import getpass, poplib, re, os, fileinput, sys, xmpp&lt;br /&gt;&lt;br /&gt;def sendIM(toAddress=None):&lt;br /&gt;    &lt;br /&gt;    # Google Talk constants&lt;br /&gt;    FROM_GMAIL_ID = "user@gmail.com"&lt;br /&gt;    GMAIL_PASS = "pass"&lt;br /&gt;    GTALK_SERVER = "talk.google.com"&lt;br /&gt;    TO_GMAIL_ID = "user@gmail.com"&lt;br /&gt;    jid=xmpp.protocol.JID(FROM_GMAIL_ID)&lt;br /&gt;    cl=xmpp.Client(jid.getDomain(),debug=[])&lt;br /&gt;    if not cl.connect((GTALK_SERVER,5222)):&lt;br /&gt;        raise IOError('Can not connect to server.')&lt;br /&gt;    if not cl.auth(jid.getNode(),GMAIL_PASS):&lt;br /&gt;        raise IOError('Can not auth with server.')&lt;br /&gt;&lt;br /&gt;    cl.send( xmpp.Message( TO_GMAIL_ID ,"Fix your email!" ) )&lt;br /&gt;    cl.disconnect()&lt;br /&gt;&lt;br /&gt;# Change this to your needs&lt;br /&gt;POPHOST = "131.0.0.1"&lt;br /&gt;POPUSER = "user"&lt;br /&gt;POPPASS = "pass"&lt;br /&gt;&lt;br /&gt;# How many lines of message body to retrieve&lt;br /&gt;MAXLINES = 10&lt;br /&gt;&lt;br /&gt;# Headers we're actually interrested in&lt;br /&gt;rx_headers  = re.compile(r"^(Subject)")&lt;br /&gt;&lt;br /&gt;try:&lt;br /&gt;&lt;br /&gt;    # Connect to the POPer and identify user&lt;br /&gt;    pop = poplib.POP3(POPHOST)&lt;br /&gt;    pop.user(POPUSER)&lt;br /&gt;&lt;br /&gt;    if not POPPASS:&lt;br /&gt;        # If no password was supplied, ask for it&lt;br /&gt;        POPPASS = getpass.getpass("Password for %s@%s:" % (POPUSER, POPHOST))&lt;br /&gt;&lt;br /&gt;    # Authenticate user&lt;br /&gt;    pop.pass_(POPPASS)&lt;br /&gt;&lt;br /&gt;    # Get some general informations (msg_count, box_size)&lt;br /&gt;    stat = pop.stat()&lt;br /&gt;&lt;br /&gt;    bye = 0&lt;br /&gt;    count_del = 0&lt;br /&gt;    &lt;br /&gt;    #for n in range(stat[0]):&lt;br /&gt;&lt;br /&gt;    msgnum = stat[0]&lt;br /&gt;&lt;br /&gt;    # Retrieve headers&lt;br /&gt;    response, lines, bytes = pop.top(msgnum, MAXLINES)&lt;br /&gt;&lt;br /&gt;    # Print message info and headers we're interrested in&lt;br /&gt;    test = "".join(filter(rx_headers.match, lines))&lt;br /&gt;    num = test.split(',')&lt;br /&gt;    out = num[1]&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;    #Read the sent.txt file to get the GUID&lt;br /&gt;    fileHandle = open ( 'sent.txt' )&lt;br /&gt;    sentGuid = fileHandle.readline()&lt;br /&gt;    print sentGuid&lt;br /&gt;    fileHandle.close()&lt;br /&gt;    &lt;br /&gt;    if out == sentGuid:&lt;br /&gt;        print "They match!! yay"&lt;br /&gt;        pop.dele(msgnum)&lt;br /&gt;        print "Message %d marked for deletion" % msgnum&lt;br /&gt;        count_del += 1&lt;br /&gt;        #delete the retry.txt and sent.txt file&lt;br /&gt;        os.remove("retry.txt")&lt;br /&gt;        os.remove("sent.txt")&lt;br /&gt;    else:&lt;br /&gt;&lt;br /&gt;        #There are no messages yet, so we will increment the retry value&lt;br /&gt;        if not os.path.exists("retry.txt"):&lt;br /&gt;            fileHandle = open ( 'retry.txt','a')&lt;br /&gt;            fileHandle.write('1')&lt;br /&gt;            fileHandle.close()&lt;br /&gt;        else:&lt;br /&gt;        &lt;br /&gt;        fileHandle = open("retry.txt")&lt;br /&gt;        retryValue = fileHandle.readline()&lt;br /&gt;        fileHandle.close()&lt;br /&gt;        #delete the file then recreate with new value&lt;br /&gt;        os.remove('retry.txt')&lt;br /&gt;&lt;br /&gt;        if retryValue != '':&lt;br /&gt;            retryValue = int(retryValue) + 1&lt;br /&gt;            out = str(retryValue)&lt;br /&gt;            fileHandle = open ( 'retry.txt','a')&lt;br /&gt;            fileHandle.write(out)&lt;br /&gt;            fileHandle.close()&lt;br /&gt;            if retryValue &gt; 20 and retryValue &lt;25:&lt;br /&gt;                sendIM()&lt;br /&gt;&lt;br /&gt;   # Summary&lt;br /&gt;    print "Deleting %d message(s) in mailbox %s@%s" % (count_del, POPUSER, POPHOST)&lt;br /&gt;&lt;br /&gt;    # Commit operations and disconnect from server&lt;br /&gt;    print "Closing POP3 session"&lt;br /&gt;    pop.quit()&lt;br /&gt;&lt;br /&gt;except poplib.error_proto, detail:&lt;br /&gt;&lt;br /&gt;    # Fancy error handling&lt;br /&gt;    print "POP3 Protocol Error:", detail&lt;br /&gt;&lt;br /&gt;    #There are no messages yet, so we will increment the retry value&lt;br /&gt;    if not os.path.exists("retry.txt"):&lt;br /&gt;        fileHandle = open ( 'retry.txt','a')&lt;br /&gt;        fileHandle.write('1')&lt;br /&gt;        fileHandle.close()&lt;br /&gt;    else:&lt;br /&gt;        &lt;br /&gt;        fileHandle = open("retry.txt")&lt;br /&gt;        retryValue = fileHandle.readline()&lt;br /&gt;        fileHandle.close()&lt;br /&gt;        #delete the file then recreate with new value&lt;br /&gt;        os.remove('retry.txt')&lt;br /&gt;&lt;br /&gt;        if retryValue != '':&lt;br /&gt;            retryValue = int(retryValue) + 1&lt;br /&gt;            out = str(retryValue)&lt;br /&gt;            fileHandle = open ( 'retry.txt','a')&lt;br /&gt;            fileHandle.write(out)&lt;br /&gt;            fileHandle.close()&lt;br /&gt;            if retryValue &gt; 20 and retryValue &lt;25:&lt;br /&gt;                sendIM()&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 15 May 2007 18:26:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4024</guid>
      <author>mellerbeck (Michael Ellerbeck)</author>
    </item>
  </channel>
</rss>
