Skip to content
Advertisement

How to find uid of existing python email object

I have been reading through this document. Most of the document is based on finding an email’s uid. From the article:

JavaScript

I’m working with a django app called django-mailbox (http://django-mailbox.readthedocs.org/en/latest/index.html) the purpose of which is to consume emails.

The app creates a “Message” model that looks like:

JavaScript

using the python “email” library I can select a record from a django queryset and turn it into an email object:

JavaScript

Does the existing data in the db have a uid, and if so how can I grab it.

Advertisement

Answer

The strict answer to your question is “no”. The document you quote is about looping through an IMAP folder (in this case, a Gmail account), which will certainly get a unique ID (uid) from the server which tracks the unique message ID for each Email message.

Because you are constructing a mail message object using Django, you won’t have such a UID. The “ID” field you do get from django.db.models.fields.AutoField is the sequential auto-increment ID that the Gmail/IMAP web page you quote says is “unacceptable”.

You may want to look at the “uuid” library (http://docs.python.org/2/library/uuid.html) to generate unique ID values for your messages, but unless you also store those in your database, you’ll be re-generating them over and over.

If you care to share more exact information about what you’re trying to build (a web-based Email reader, perhaps?) then we as a community might have some better ideas for you.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement