16384K
  7   ˆl–Ü4ý( ©¤ýÔâ�jãb¸Ë*bÑ¿‘äÇò 8à7…Þ+ò?Âƒh¹ÁÀ¿      1
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ã524_‘I|¥‰ÓMdœv ©ƒ†ü+=ÃÂ     ‹      Õ•ÑnÓ0†ï÷ÆÜµ'iG�c4šITtmÕ!„rb·±–Ø‘í´”§ÇiZZ¦1."Ÿ8¿ÿs>'ñ!OâÉ`þ~z…^Ï¯GhúöÕh8@¸ð®; ˆçqóà¼„ WcŒpæ\ÙX¯×íu·­Íæ3È\‘ŸƒuF¦®ÍÇôŒÔsô‘L0îGDœt¹ CÅÅg¤tå¬äÂ¯ÛXàb%SaëØ‰Ò²ª¯(ÍE …(´ÙtÁVI# Ð¸yØ% ‰æ›:oøÇrx«má,Ù¦ªCC‰ËÐŠår©"ìt‰)‘ÅY“Fdª•…$gê¶½”ŒXî"üa8˜|ô:pY½š†2#~9ˆÆ“(ÆtÌ
A€Ý¯¹öšKLGÌ:Th.Rð“â›F|#¿œ6ŒM,ljdé¤V)xÄcÔTç¶džõ™'ÈÌ±ª‘ðŸíK¿ÛŒéåìj<�‡³fKxmq¨îwÞ¦Sf„r(–F¤ÎÏípï§*±åÅþíŠ5r™9Lj¡{•¿@¸Ð9æ˜ñÝžÓ}t\é�Ò:A§×
ÃVø…ÏûA¡ÇÁ`äJ˜-Ã.z,•ºUz­Ž!ü‡ü#ˆO¬òVF'âÍaêX�½~'8‰åÎ7ÿ ëÒÿŠS‰•ÿ­1mÆ¿ðÀcv�À¶åhZÝWÃM       ˆÆ�þB g ßnI\d#gùÅƒh¹ÄÃÂ      16384K
  5   	ˆl–ß=¿Jõ4Ÿº‚ œP.\·˜´o�þB g Ùm–D7óÆƒh¹ÅÄÃ      	0
  C   ˆl–äY>”*h¥2 [¸!\*bÑ¿�þZ¡Y¹FHß)#}–�üÿÇ„ ÿÆ_ŠI|¥�+Wé3ž¯ÆÅ ?÷     # Caolan McNamara caolanm@redhat.com
# a simple email mailmerge component

# manual installation for hackers, not necessary for users
# cp mailmerge.py /usr/lib/libreoffice/program
# cd /usr/lib/libreoffice/program
# ./unopkg add --shared mailmerge.py
# edit ~/.openoffice.org2/user/registry/data/org/openoffice/Office/Writer.xcu
# and change EMailSupported to as follows...
#  <prop oor:name="EMailSupported" oor:type="xs:boolean">
#   <value>true</value>
#  </prop>

import unohelper
import uno
import re
import os
import encodings.idna

#to implement com::sun::star::mail::XMailServiceProvider
#and
#to implement com.sun.star.mail.XMailMessage

from com.sun.star.mail import XMailServiceProvider
from com.sun.star.mail import XMailService
from com.sun.star.mail import XSmtpService
from com.sun.star.mail import XConnectionListener
from com.sun.star.mail import XAuthenticator
from com.sun.star.mail import XMailMessage
from com.sun.star.mail.MailServiceType import SMTP
from com.sun.star.mail.MailServiceType import POP3
from com.sun.star.mail.MailServiceType import IMAP
from com.sun.star.uno import XCurrentContext
from com.sun.star.lang import IllegalArgumentException
from com.sun.star.lang import EventObject
from com.sun.star.lang import XServiceInfo
from com.sun.star.mail import SendMailMessageFailedException

from email.mime.base import MIMEBase
from email.message import Message
from email.charset import Charset
from email.charset import QP
from email.encoders import encode_base64
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.utils import formatdate
from email.utils import parseaddr
from socket import _GLOBAL_DEFAULT_TIMEOUT

import sys, smtplib, imaplib, poplib
dbg = False

# pythonloader looks for a static g_ImplementationHelper variable
g_ImplementationHelper = unohelper.ImplementationHelper()
g_providerImplName = "org.openoffice.pyuno.MailServiceProvider"
g_messageImplName = "org.openoffice.pyuno.MailMessage"

class PyMailSMTPService(unohelper.Base, XSmtpService):
	def __init__( self, ctx ):
		self.ctx = ctx
		self.listeners = []
		self.supportedtypes = ('Insecure', 'Ssl')
		self.server = None
		self.connectioncontext = None
		self.notify = EventObject(self)
		if dbg:
			print("PyMailSMTPService init", file=sys.stderr)
			print("python version is: " + sys.version, file=sys.stderr)
	def addConnectionListener(self, xListener):
		if dbg:
			print("PyMailSMTPService addConnectionListener", file=sys.stderr)
		self.listeners.append(xListener)
	def removeConnectionListener(self, xListener):
		if dbg:
			print("PyMailSMTPService removeConnectionListener", file=sys.stderr)
		self.listeners.remove(xListener)
	def getSupportedConnectionTypes(self):
		if dbg:
			print("PyMailSMTPService getSupportedConnectionTypes", file=sys.stderr)
		return self.supportedtypes
	def connect(self, xConnectionContext, xAuthenticator):
		self.connectioncontext = xConnectionContext
		if dbg:
			print("PyMailSMTPService connect", file=sys.stderr)
		server = xConnectionContext.getValueByName("ServerName").strip()
		if dbg:
			print("ServerName: " + server, file=sys.stderr)
		port = int(xConnectionContext.getValueByName("Port"))
		if dbg:
			print("P