# -*- coding: utf-8 # $Id$ # # Copyright 2001, 2002 by IVA Team and contributors # # This file is part of IVA. # # IVA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # IVA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with IVA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA __version__ = "$Revision$"[11:-2] from common import translate import AccessControl import OFS, Globals from OFS import SimpleItem import types import time from TraversableWrapper import Traversable from Globals import Persistent from AccessControl import ClassSecurityInfo from Cruft import Cruft from common import perm_view, perm_edit from zope.interface import implements from zope.component import getUtility from interfaces import IMessage, IMailbox, IUserManager class Kiri( OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager, Traversable, Cruft, ): """ Message in inbox """ meta_type = "MailMessage" security = ClassSecurityInfo() implements(IMessage) def __init__(self, pealkiri, sisu, saatja, saaja, remote_id): "Kirja loomine" self.pealkiri=pealkiri self.sisu=sisu self.saatja=saatja self.loomisaeg=time.time() self.loetud=0 self.saaja = saaja self.remote_id = remote_id security.declareProtected(perm_edit,'kysiPealkiri') def kysiPealkiri(self): "Pealkirja kysimine" if self.pealkiri == "": self.pealkiri = "(untitled)" return self.pealkiri security.declareProtected(perm_edit,'kysiSisu') def kysiSisu(self,sup=''): "Sisu kysimine" import re if sup == 1: sup = '\n' if sup: return re.sub('
',sup,self.sisu) else: return self.sisu security.declareProtected(perm_view,'kysiSaatja') def kysiSaatja(self): return self.saatja security.declareProtected(perm_view,'kasOmaKoopia') def kasOmaKoopia(self): return getattr(self, 'omakopi', 0) security.declareProtected(perm_view,'kysiSaatja_nimega') def kysiSaatja_nimega(self): """Saatja kysimine""" return self.firstAndLastNG(self.saatja) def kysiAeg(self): "Aja kysimine" return self.loomisaeg def kysiAegTekstina(self, REQUEST): "Saatmisaeg" return self.aegTekstina(REQUEST, self.loomisaeg) def aegTekstina(self, REQUEST, aeg): "tekstiesitus" if aeg==-1: return "*" return time.strftime(translate(self,'timestamp_format',default="%H:%M %Y-%m-%d"), time.localtime(aeg)) security.declareProtected(perm_view,'kasLoetud') def kasLoetud(self): "Kas loetud" return self.loetud security.declareProtected(perm_edit,'setRemoteRead') def setRemoteRead(self,REQUEST): """ set mail read in senders mailbox """ k = self.fle_root().fle_users try: kasutaja = getattr(k, self.saatja).kysiKirjadeKataloog() except AttributeError: return 0 try: saatja_kopi = getattr(kasutaja, self.remote_id) setattr(saatja_kopi, str(REQUEST.AUTHENTICATED_USER)+"_hasread" ,1) except: pass return 1 class Kirjakast( OFS.Folder.Folder, OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager, Traversable, Cruft ): kirjaNr=0 uusiKirju=0 meta_type = "MailBox" security = ClassSecurityInfo() implements(IMailbox) def __init__(self): """ init """ self.id = 'kirjad' security.declareProtected(perm_edit,'listMessages') def listMessages(self, REQUEST): """ list messsage objects location == 1 == outbox else inbox """ mblocation = REQUEST.get('mblocation', 0) if self.kasUusiKirju(): self.uusiKirju = 0 messages = [] for mess in self.objectValues(): omakopi = mess.kasOmaKoopia() if mblocation and omakopi: messages.append(mess) if not mblocation and not omakopi: messages.append(mess) messages.reverse() return messages security.declareProtected(perm_edit,'kirjakastiMuutus') def kirjakastiMuutus(self, REQUEST, kiri=(),userLocation='Organizer'): """Esiotsa vaid kustutamine""" REQUEST.set('userLocation',userLocation) if type(kiri)==types.StringType: kiri=(kiri,) for x in kiri: self._delObject(x) return self.absolute_url() security.declareProtected(perm_edit,'lisaKiri') def lisaKiri(self, REQUEST=None, pealkiri='', sisu='', saatja='', saaja='', remote_id=''): "Kirja lisamine kasti" import re self.uusiKirju=time.time() k=Kiri(pealkiri, re.sub('\n', '
', sisu), saatja, saaja, remote_id) self.kirjaNr=self.kirjaNr+1 kirjanimi="kiri"+str(self.kirjaNr) k.id=kirjanimi if not hasattr(self, kirjanimi): self._setObject(kirjanimi, k) else: knr = self.kirjaNr while hasattr(self, kirjanimi): knr += 1 kirjanimi = 'kiri'+str(knr) k.id = kirjanimi self._setObject(kirjanimi, k) if REQUEST: return k.id else: return k def kasUusiKirju(self): """ jah/ei """ return self.uusiKirju security.declareProtected(perm_edit,'kirjaSaatmiseLeht') def kirjaSaatmiseLeht(self, REQUEST, kellele, pealkiri, sisu, lisa='', s_kellele='',userLocation='Organizer', courseid=None): "Saatmine, kellele on inimeste komadega eraldatud loetelu" REQUEST.set('userLocation',userLocation) kiri_saadetud=[] if REQUEST.SESSION.has_key('kellele'): REQUEST.SESSION.delete('kellele') if lisa: if s_kellele.startswith('sg_'): s_kellele = s_kellele[3:] if courseid is None: s_kellele = '' course = getattr(self.courses, courseid) sg = course.subgroups.getSubgroupById(s_kellele) tmp = sg.subgroup_members() s_kellele = ','.join(tmp) if s_kellele: if kellele: kellele += ", " kellele += s_kellele tmp = kellele.split(',') tmp2 = [] for x in tmp: x = x.strip() if x not in tmp2: tmp2.append(x) kellele = ', '.join(tmp2) REQUEST.set('kellele', kellele) return self.restrictedTraverse('createMail.html')() if not kellele: REQUEST.set('emptyto','1') return self.restrictedTraverse('createMail.html')() saaja = kellele omakopi_id = self.omakoopia(REQUEST, kellele,saaja,pealkiri,sisu) kellele=kellele.split(',') for i in range(len(kellele)): kellele[i]=kellele[i].strip() result = [] for kasutaja in kellele: tulemus = [] tulemus.append(kasutaja) if kasutaja not in kiri_saadetud: kass = self.saadaKiri(REQUEST, kasutaja, saaja, pealkiri, sisu, omakopi_id) kiri_saadetud.append(kasutaja) else: tulemus.append(translate(self,'No double postings')) continue if kass[0] != 0: tulemus.append(translate(self,'Internal mail message was sent succesfully')) else: tulemus.append(translate(self,'Internal mail message failed')) if kass[1] == 0: tulemus.append(translate(self,'E-mail failed')) if kass[1] != 3 and kass[1] !=0: tulemus.append(translate(self,'E-mail was sent succesfully')) result.append(tulemus) return self.restrictedTraverse('mailStatus.html')(result=result) security.declareProtected(perm_edit,'saadaKiri') def saadaKiri(self, REQUEST, kellele, saaja, pealkiri, sisu, remote_id,fleroot=''): """Kellele on yks inimene""" if fleroot: k = fleroot else: #k=self.fle_root().fle_users k = getUtility(IUserManager) if not hasattr(k, kellele): return 0,0 kasutaja = k.get_user_info(kellele) saatja = k.get_user_info(str(REQUEST.AUTHENTICATED_USER)) try: if saatja.get_first_name()!='' and saatja.get_last_name()!='': lisa_saatja = saatja.get_first_name()+" "+saatja.get_last_name() else: lisa_saatja = saatja.get_uname() if kasutaja.email_kirjad == 1 and kasutaja.get_email(): raport = self.saadaEmail(kasutaja.get_email().strip(),pealkiri,sisu+"\n\n\n"+\ lisa_saatja,saatja.get_email().strip()) except: pass kirja_id = getattr(k, kellele).kysiKirjadeKataloog().lisaKiri( REQUEST, pealkiri, sisu, str(REQUEST.AUTHENTICATED_USER), saaja, remote_id) try: if raport == 999: pass except: raport = 3 return kirja_id,raport security.declareProtected(perm_edit,'omakoopia') def omakoopia(self, REQUEST, kellele,saaja, pealkiri,sisu): kirja_id = self.lisaKiri(REQUEST, pealkiri, sisu, str(REQUEST.AUTHENTICATED_USER), saaja, '9999') uuskiri = getattr(self,kirja_id) uuskiri.omakopi = 1 return kirja_id