/usr/bin/setOOmailer is in gnome-gmail 1.8.2-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | #!/usr/bin/python
#
# Copyright 2011 David Steele <daves@users.sourceforge.net>
# This file is part of gnome-gmail
# Available under the terms of the GNU General Public License version 2 or later
#
""" This script attempts to edit the open officeconfiguration XML file for
the current user so that the Gnome Preferred Email Application is used for the
"Send Document as Email" command.
Since OO suports only a few, specific mailers, keyed off of the mailer name, a
compatibility script masquerades as a supported app.
"""
import os
import xml.etree.ElementTree as ET
import shutil
import gconf
import sys
import gio
class OOMailerCfg( object ):
""" Class to support query and edit of the Open Office email handler """
def __init__( self ):
# OO XML paramters
self.registry_uri = "http://openoffice.org/2001/registry"
self.registry_ns = "oor"
self.registry_prefix = "{" + self.registry_uri + "}"
# OO XML path
self.homedir = os.path.expanduser( '~' )
self.oo_xml_path = "/.openoffice.org/3/user/registry/data/org/openoffice/Office/Common.xcu"
self.backup_ext = ".bak"
self.ooxmlfile = self.homedir + self.oo_xml_path
registry_namespace = None
# bug(?) in ElementTree
try:
register_namespace = ET.register_namespace
except AttributeError:
def register_namespace(prefix, uri):
ET._namespace_map[uri] = prefix
register_namespace( self.registry_ns, self.registry_uri )
def _parse_tree( self ):
self.tree = ET.parse( self.ooxmlfile )
self.root = self.tree.getroot()
def _del_external_mailer ( self, root_node ):
""" Delete the XML key for the existing OO mailer """
for node in root_node:
if( node.attrib[self.registry_prefix + 'name'] == \
"ExternalMailer" ):
root_node.remove( node )
def _add_external_mailer( self, root_node, cmd ):
""" add the key for the compatibility mailer """
external_mailer = ET.SubElement( root_node, "node" )
external_mailer.attrib[ self.registry_prefix + 'name'] = \
"ExternalMailer"
external_mailer_prop = ET.SubElement( external_mailer, "prop" )
external_mailer_prop.attrib[ self.registry_prefix + 'name'] = \
"Program"
external_mailer_prop.attrib[ self.registry_prefix + 'type'] = \
"xs:string"
external_mailer_value = ET.SubElement( external_mailer_prop, "value" )
external_mailer_value.text = cmd
def get_external_mailer( self ):
""" what is the external mailer, if any, currently configured in
Open Office? """
return_value = ""
try:
for node in self.root:
if( node.attrib[self.registry_prefix + 'name'] == \
"ExternalMailer" ):
prop_node = node.find( "prop" )
value_node = prop_node.find( "value" )
return_value = value_node.text
except:
pass
return( return_value )
def _set_external_mailer_xml( self, cmd_path ):
""" given a path to the OO XML file, set the external mailer """
self._del_external_mailer( self.root )
self._add_external_mailer( self.root, cmd_path )
return self.tree
def set_external_mailer( self, cmd_path ):
""" cleanly set the external mailer, with a backup """
self._parse_tree()
if( self.get_external_mailer() != cmd_path ):
tree = self._set_external_mailer_xml( cmd_path )
try:
os.unlink( self.ooxmlfile + self.backup_ext )
except:
pass
shutil.move( self.ooxmlfile, self.ooxmlfile + self.backup_ext )
tree.write( self.ooxmlfile )
class LibreMailerCfg( OOMailerCfg):
def __init__( self, xml_path="/.openoffice.org/3/user/registrymodifications.xcu" ):
super( LibreMailerCfg, self).__init__()
self.oo_xml_path = xml_path
self.ooxmlfile = self.homedir + self.oo_xml_path
register_namespace = None
def _del_external_mailer ( self, root_node ):
""" Delete the XML key for the existing OO mailer """
for node in root_node:
if( node.attrib[self.registry_prefix + 'path' ] == \
"/org.openoffice.Office.Common/ExternalMailer" ):
root_node.remove( node )
def _add_external_mailer( self, root_node, cmd ):
""" add the key for the compatibility mailer """
external_mailer = ET.SubElement( root_node, "item" )
external_mailer.attrib[ self.registry_prefix + 'path'] = \
"/org.openoffice.Office.Common/ExternalMailer"
external_mailer_prop = ET.SubElement( external_mailer, "prop" )
external_mailer_prop.attrib[ self.registry_prefix + 'name'] = \
"Program"
external_mailer_prop.attrib[ self.registry_prefix + 'op'] = \
"fuse"
external_mailer_value = ET.SubElement( external_mailer_prop, "value" )
external_mailer_value.text = cmd
def get_external_mailer( self ):
return_value = ""
try:
for node in self.root:
if( node.attrib[self.registry_prefix + 'path'] == \
"/org.openoffice.Office.Common/ExternalMailer" ):
prop_node = node.find( "prop" )
value_node = prop_node.find( "value" )
return_value = value_node.text
except:
pass
return( return_value )
def set_external_mailer( self, cmd_path ):
""" cleanly set the external mailer, with a backup """
self._parse_tree()
self.root.set( "xmlns:xs", "http://www.w3.org/2001/XMLSchema" )
if( self.get_external_mailer() != cmd_path ):
tree = self._set_external_mailer_xml( cmd_path )
try:
os.unlink( self.ooxmlfile + self.backup_ext )
except:
pass
shutil.move( self.ooxmlfile, self.ooxmlfile + self.backup_ext )
try:
tree.write( self.ooxmlfile, encoding="UTF-8", \
xml_declaration=True, method='xml' )
except TypeError:
tree.write( self.ooxmlfile, encoding="UTF-8" )
def should_set_oo_mailer( basedir = "/apps/gnome-gmail/" ):
""" Check gconf. Should I update the mailer? """
client = gconf.client_get_default()
the_bool = client.get_bool( basedir + "OOfix" )
return( the_bool )
if __name__ == "__main__":
external_mailer = "/usr/share/gnome-gmail/evolution"
gclient = gconf.client_get_default()
if( not gclient.get_bool( '/apps/gnome-gmail/suppresspreferred' ) ):
# set this app as the GNOME mailto handler, new-style
[ app.set_as_default_for_type( "x-scheme-handler/mailto" )
for app in gio.app_info_get_all_for_type( "x-scheme-handler/mailto" )
if app.get_name() == "Gnome Gmail" ]
if( not should_set_oo_mailer() ):
sys.exit( 0 )
# this is best effort
try:
Oom = OOMailerCfg()
Oom.set_external_mailer( external_mailer )
except:
pass
try:
Lbm = LibreMailerCfg( xml_path="/.libreoffice/3/user/registrymodifications.xcu" )
Lbm.set_external_mailer( external_mailer )
except:
pass
try:
Obm = LibreMailerCfg( xml_path="/.openoffice.org/3/user/registrymodifications.xcu" )
Obm.set_external_mailer( external_mailer )
except:
pass
|