Skip to content

Instantly share code, notes, and snippets.

@bcoe
Created May 10, 2011 13:24
Show Gist options
  • Save bcoe/964461 to your computer and use it in GitHub Desktop.
Save bcoe/964461 to your computer and use it in GitHub Desktop.
Gmail Message ID
def _get_email_uuid(self, message_id):
try:
typ, data = self.connection.fetch(message_id, '(X-GM-MSGID)')
# 1 (X-GM-MSGID 1363378113778197832)
mid_regex = re.compile(r'^.* \(.* ([0-9]*)\)$')
match = mid_regex.match(data[0])
if match:
raw_hex = hex( int( match.group(1) ) )
# 0x12ebb12bc64aa548L
hex_regex = re.compile(r'^[0-9]x([0-9a-f]+)L$')
match = hex_regex.match(raw_hex)
if match:
return match.group(1)
except Exception, e:
self.user.logger.error("Could not get message id for %s from %s." % (
message_id,
self.user.email
))
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment