gnome-gmail – “Unable to determine IMAP Drafts folder location” solution

If you are getting the error “Unable to determine IMAP Drafts folder location” when you try to send an email with attachment you need to hardcode the Gmail Drafts folder location into the script. Mostly this is the case if you are using localized version either of Gnome or Gmail and the language settings doesn’t match.

You need to modify the script located in /bin/gnome-gmail.

For English version of Gmail the path should look like this:
folder_name = ‘[Gmail]/Drafts’
For Czech version like this:
folder_name = ‘[Gmail]/Koncepty’

For other languages you will have to experiment and find out the right translated name of the IMAP folder.

The following excerpt from the script is starting on the line 171:

        try:
            # I may need this again someday
            #folder_name = _("Drafts")
            folder_name = '[Gmail]/Drafts'

            # xlist returns directories e.g. 
            #    (\HasNoChildren \Drafts) "/" "[Gmail]/Drafts"
            # where the first "Drafts" is a flag, and the second is localized
            #drafts_ln = [ x for x in imap_obj.xlist()[1]
            #                         if re.search( ' .Drafts\)', x ) ][0]

            #draft_folder = re.search( '\"([^\"]+)\"$', drafts_ln ).group(1)

        except:
            imap_obj.logout()
            raise GGError( _("Unable to determine IMAP Drafts folder location") )

        try:
            # upload the message to the Drafts folder
            #append_resp = imap_obj.append( draft_folder, None, None, self.message_text )
            append_resp = imap_obj.append( folder_name, None, None, self.message_text )
        except:
            imap_obj.logout()
            raise GGError( _("Error encountered while uploading the message") )

        try:
            # get the Google Message Id for the message, and convert to a hex string
            # http://code.google.com/apis/gmail/imap/#x-gm-msgid
            # nods to https://gist.github.com/964461

            # the append returns something like ('OK', ['[APPENDUID 9 3113] (Success)'])
            msg_uid = re.search( r'UID [0-9]+ ([0-9]+)', append_resp[1][0]).group(1)

            #imap_obj.select( draft_folder )
            imap_obj.select( folder_name )
            typ, data = imap_obj.uid( r'fetch', msg_uid, r'(X-GM-MSGID)')

            msgid_dec = re.search( r'X-GM-MSGID ([0-9]+)', data[0] ).group(1)
            msgid_hex = hex( int( msgid_dec ) )
            msgid_hex_strp = re.search( r'0x(.+)', msgid_hex ).group(1)
        except:
            imap_obj.logout()
            raise GGError( _("Error accessing message. Check the Drafts folder") )