Error 

Archive for June, 2009

Wordpress 2.8 Database Upgrade Loop

Posted June 14, 2009 at 10:06am in General

Last night I upgraded both of my blogs to Wordpress 2.8 and ran into a couple problems. The redirection plugin caused some problems with wp-db.php so I had to disable that to get the site back up if you upgrade redirection prior to upgrading you won’t have that problem.

The other problem I ran into was that I would be presented with a page saying “Database Upgrade Required”, after upgrading it would bring me back to the same page. The problem ended up being the wp-content/object-cache.php file, moving that out fixed the problem. However because the page was still cached in memcache moving the file back raised the same issues. The faster fix is to restart memcache all together to clear the cache.

Retrieve Gmail/GApps Message Count

Posted June 14, 2009 at 01:06am in Python

Long ago I switched from using any sort of mail client to using the webmail interface of Gmail/Google Apps. This switch was really fueled by my increased usage of the interface after being hired by Google. I won’t go on and on about using the web interface, but sometimes it is nice to know how many actual emails are in your account. Google mail only shows you the number of threaded emails, not each individual response. If I look in “All Mail” for my manis@digital39.com account I see “1 – 100 of 21758″, which represents the number of email threads, the actual number of responses is 56578. FYI, this requires that you enable IMAP support for the account.

$ imap_count.py manis@digital39.com
Password for manis@digital39.com: *****
56578 messages in account manis@digital39.com

Expand the code below and copy it to a file on your system. It takes one argument, and that argument is a comma separated list of email addresses.

#!/usr/bin/python2.4
#
# Copyright (c) 2009, Peter Manis
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# Neither the name of the Peter Manis nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import getpass
import imaplib
import sys

results = []

def RetrieveMsgCount(username, password):
  """Retrieves message count by accessing Gmail or Google Apps IMAP account.

  Args:
    username: str, Username of the account we are accessing.
    password: str, Password of the account we are accessing.

  Returns:
    count: str, Number of messages in IMAP account

  Raises:
    imaplib.IMAP4.error: Failed to login to the IMAP account.
  """
  try:
    imap = imaplib.IMAP4_SSL('imap.gmail.com', 993)
    imap.login(username, password)
    status, [count] = imap.select("[Gmail]/All Mail")
    imap.close()
    imap.logout()
  except imaplib.IMAP4.error:
    return 'Unable to check'
  else:
    return count

def main():
  if len(sys.argv) > 1:
    accounts = sys.argv[1]
    for account in accounts.split(','):
      password = getpass.getpass("Password for %s: " % account)
      results.append('%s messages in account %s' % (
          RetrieveMsgCount(account, password), account))
    for account in results:
      print account
  else:
    print "Please provide a comma separated list of accounts to check."

if __name__ == '__main__':
  main()