#import copy #import os #import sys #import lxml.etree as etree #from lxml.builder import ElementMaker from lxml import etree #import dating import filing import docing # import subscription from emailer import Emailer from nitpo import Nitpo from infile import Infile from itresu import Itresu from omnibus import Omnibus from kapro import Kapro from xpaths import Xpaths from profile import Profile #from subscription import Subscription class Sender(Nitpo): def __init__(self, do_verbose=False): """subscription profiles""" super().__init__() # a basename for the thing to send self.base = None # current repcode self.repcode = None # state variable for the current fufi self.repis_fufi = None self.omnibus = Omnibus() self.emailer = Emailer() self.infile = Infile() self.itresu = Itresu() self.xpaths = Xpaths() self.kapro = Kapro(do_verbose=do_verbose) self.profile = Profile() if not self.has_conf('folders', 'mail'): raise Exception("I need a 'mail' folder.") #self.do_verbose = do_verbose def repis(self, fufi): #print(fufi) # repcode = self.infile.get_repcode(fufi) ## om self.repis_fufi = fufi self.base = self.infile.get_base(fufi) self.repcode = self.infile.get_repcode(fufi) ### self.send_omnibus(fufi) if not self.has_conf('action', 'send_to_profiles'): return if not self.conf['action']['send_to_profiles'] == 'true': return self.send_to_profiles(fufi) def send_to_profiles(self, fufi): # should be done by the calling bin # self.kapro.update(repcode) emads = self.kapro.load(self.repcode) print(emads) for emad in emads: self.send_to_profile(fufi, emad) def send_to_profile(self, fufi, emad): surks_docu = self.profile.load(emad) repcodes = self.profile.repcodes(surks_docu) self.send(emad, surks_docu.getroot(), only=repcodes) #self.send(emad, surks_docu) #print(docing.show(surks_xml)) def send_omnibus(self, fufi): omnibus_doc = self.omnibus.read() count_base = 0 if omnibus_doc is None: print("sender: I have no omnibus.") return ## at this time, we only do the omnibus surk_docus = self.omnibus.disect(omnibus_doc) # avoid running prepare every time we send a mail mail_base_fufi = self.conf['folders']['mail'] + '/' + self.base # # now call the itresu, fills itesu.dups self.itresu.get_dups(fufi) filing.prepare(mail_base_fufi) # get the subs for the itresu for emad in surk_docus: # # increment by 1 for each recipient self.send(emad, surk_docus[emad]) # docing.inject(fufi, omnibus_doc) def send(self, emad, surk_docu, only=None): base = self.base + '/' + self.profile.relfi_from_emad(emad)[:-4] #print(etree.tostring(surk_docu, pretty_print=True).decode()) maix = filing.parse_lax(self.repis_fufi) if maix is None: return False maix_surk = docing.inject(maix, surk_docu) spro = self.xpaths.get_spro(surk_docu, repcode=self.repcode) if spro == 'v': # # None is all repcodes here, omnibus only subs_ele = self.itresu.xml(self.repis_fufi, None) maix_surk = docing.inject(maix, subs_ele) ## the mail xml self.emailer.prepare(maix_surk, base=base, only=only) #print(spro)