#!/usr/bin/python -tt # skvidal@fedoraproject.org # (c) red hat, inc 2013 # gpl whatever # this is a direct port of exo-compos-mail-1 from xfce # from perl to python # the idea is to dump the 2000000000 perl pkgs pulled in # by this for a single item :( # it should handle all the behaviour the same # it probably has bugs # TODO: # - figure out what the attachment parsing is trying to do # - figure out if rebuilding the mailto for evo, sylpheed and balsa # is actually necessary or not - feels silly but I'm not shocked by silly # - would be nice to have an actual set of tests :) import sys import posix import os import urlparse import urllib def parse_url(mailto): urlparse.uses_query.append('mailto') url = urlparse.urlparse(mailto) res = {} to = [] query = None if url.query or '?' not in url.path: if url.path: to.append(urlparse.unquote(url.path)) else: (thisto, ques, query) = url.path.partition('?') if thisto.strip(): to.append(urlparse.unquote(thisto)) if not query: query = url.query q_dict = urlparse.parse_qs(query) to.extend(q_dict.get('to', [])) res['to'] = to if 'to' in q_dict: del(q_dict['to']) res.update(q_dict) return res if len(sys.argv) < 3: print >> sys.stderr, "Usage: %s