def __init__(self, repository, url, itemCollection, sendToList, account=None): assert isinstance(url, basestring), "URL must be a String" assert isinstance(sendToList, list), "sendToList must be of a list of email addresses" assert len(sendToList) > 0, "sendToList must contain at least one email address" assert isinstance(itemCollection, pim.ItemCollection), \ "itemCollection must be of type osaf.pim.ItemCollection" #XXX: Theses may eventual need i18n decoding self.fromAddress = None self.url = url self.sendToList = sendToList self.repository = repository if isinstance(itemCollection.displayName, unicode): self.collectionName = itemCollection.displayName.encode(constants.DEFAULT_CHARSET) else: self.collectionName = itemCollection.displayName try: self.collectionBody = utils.textToStr(itemCollection.body) except ItemError.NoValueForAttributeError: self.collectionBody = u"" if account is None: accountUUID = None else: accountUUID = account.itsUUID self.account, self.fromAddress = Mail.getCurrentSMTPAccount(self.repository.view, \ accountUUID)
def onSendMailEvent (self, event): # commit changes, since we'll be switching to Twisted thread self.RepositoryCommitWithStatus() # get default SMTP account item = event.arguments ['item'] account = Mail.getCurrentSMTPAccount(self.itsView)[0] # put a sending message into the status bar self.setStatusMessage ('Sending mail...') # Now send the mail Globals.mailService.getSMTPInstance(account).sendMail(item)
def onSendMailEvent(self, event): # commit changes, since we'll be switching to Twisted thread self.RepositoryCommitWithStatus() # get default SMTP account item = event.arguments["item"] account = Mail.getCurrentSMTPAccount(self.itsView)[0] # put a sending message into the status bar self.setStatusMessage("Sending mail...") # Now send the mail Globals.mailService.getSMTPInstance(account).sendMail(item)
def GenerateMailMessage(view): global M_FROM message = Mail.MailMessage(view=view) body = M_TEXT outbound = random.randint(0, 1) type = random.randint(1, 8) numTo = random.randint(1, 3) if M_FROM is None: M_FROM = GenerateCalendarParticipant(view) message.fromAddress = M_FROM for num in range(numTo): message.toAddress.append(GenerateCalendarParticipant(view)) message.subject = random.choice(TITLES) message.dateSent = datetime.now() if outbound: acc = Mail.getCurrentSMTPAccount(view)[0] message.outgoingMessage(acc) """Make the Message appear as if it has already been sent""" message.deliveryExtension.sendSucceeded() else: acc = Mail.getCurrentMailAccount(view) message.incomingMessage(acc) if type == EVENT: message.StampKind('add', Calendar.CalendarEventMixin.getKind(message.itsView)) body += M_EVENT if type == TASK: message.StampKind('add', pim.TaskMixin.getKind(message.itsView)) body += M_TASK if type == BOTH: message.StampKind('add', pim.TaskMixin.getKind(message.itsView)) message.StampKind('add', Calendar.CalendarEventMixin.getKind(message.itsView)) body += M_BOTH message.body = message.getAttributeAspect('body', 'type').makeValue(body) return message
def __init__(self, repository, url, itemCollection, sendToList, account=None): assert isinstance(url, basestring), "URL must be a String" assert isinstance( sendToList, list), "sendToList must be of a list of email addresses" assert len(sendToList ) > 0, "sendToList must contain at least one email address" assert isinstance(itemCollection, pim.ItemCollection), \ "itemCollection must be of type osaf.pim.ItemCollection" #XXX: Theses may eventual need i18n decoding self.fromAddress = None self.url = url self.sendToList = sendToList self.repository = repository if isinstance(itemCollection.displayName, unicode): self.collectionName = itemCollection.displayName.encode( constants.DEFAULT_CHARSET) else: self.collectionName = itemCollection.displayName try: self.collectionBody = utils.textToStr(itemCollection.body) except ItemError.NoValueForAttributeError: self.collectionBody = u"" if account is None: accountUUID = None else: accountUUID = account.itsUUID self.account, self.fromAddress = Mail.getCurrentSMTPAccount(self.repository.view, \ accountUUID)
def __ApplyChanges(self): """ Take the data from the list and apply the values to the items. """ # First store the current form values to the data structure self.__StoreFormData(self.currentPanelType, self.currentPanel, self.data[self.currentIndex]['values']) for account in self.data: uuid = account['item'] if uuid: # We already have an account item created item = self.view.findUUID(account['item']) else: # We need to create an account item if account['type'] == "IMAP": item = Mail.IMAPAccount(view=self.view) elif account['type'] == "POP": item = Mail.POPAccount(view=self.view) elif account['type'] == "SMTP": item = Mail.SMTPAccount(view=self.view) #XXX: Temp change that checks if no SMTP Account currently # exists and makes the new account the defaultSMTPAccount # for the default IMAP ccount if Mail.getCurrentSMTPAccount(view=self.view)[0] is None: mailAccount = Mail.getCurrentMailAccount( view=self.view) if mailAccount is not None: mailAccount.defaultSMTPAccount = item elif account['type'] == "WebDAV": item = Sharing.WebDAVAccount(view=self.view) values = account['values'] panel = PANELS[account['type']] if panel.has_key("saveHandler"): # Call custom save handler; if None returned, we don't do # any more processing of that account within this loop item = panel["saveHandler"](item, panel['fields'], values) if item is not None: # Process each field defined in the PANEL data structure; # applying the values to the appropriate attributes: for (field, desc) in panel['fields'].iteritems(): if desc['type'] == 'currentPointer': # If this value is True, make this item current: if values[field]: app = schema.ns('osaf.app', self.view) ref = getattr(app, desc['pointer']) ref.item = item elif desc['type'] == 'itemRef': # Find the item for this UUID and assign the itemref: if values[field]: item.setAttributeValue( desc['attr'], self.view.findUUID(values[field])) else: # Otherwise, make the literal assignment: try: item.setAttributeValue(desc['attr'], values[field]) except: pass
def GenerateMailMessage(view, args): """ Generate one Mail message item """ message = Mail.MailMessage(itsView=view) # subject if args[0]=='*': # semi-random data message.subject = random.choice(TITLES) elif not args[0]=='': message.subject = u"%s" %args[0] else: #default value message.subject = u'untitled' if TEST_I18N: message.subject = uw(message.subject) # dateSent (date + time) message.dateSent = ReturnCompleteDatetime(view, args[2], args[3]) # fromAdress message.fromAddress = GenerateCalendarParticipant(view, args[4]) # toAddress if args[5]=='*': for num in range(random.randint(1,3)): message.toAddress.append(GenerateCalendarParticipant(view, args[5])) elif not args[5]=='': addressList = string.split(args[5],';') for add in addressList: message.toAddress.append(GenerateCalendarParticipant(view, add)) else: #default value message.toAddress.append(GenerateCalendarParticipant(view, '*****@*****.**')) # outbound smtpAccount = Mail.getCurrentSMTPAccount(view)[0] mailAccount = Mail.getCurrentMailAccount(view) if args[6]=='*': outbound = random.randint(0, 1) if outbound: message.outgoingMessage(smtpAccount) """Make the Message appear as if it has already been sent""" message.deliveryExtension.sendSucceeded() else: message.incomingMessage(mailAccount) elif args[6]=='TRUE': message.outgoingMessage(smtpAccount) """Make the Message appear as if it has already been sent""" message.deliveryExtension.sendSucceeded() else: # default value "incoming" message.incomingMessage(mailAccount) # Stamp Event if args[7]=='*': type = random.randint(0, 1) if type: Calendar.EventStamp(message).add() elif args[7]=='TRUE': Calendar.EventStamp(message).add() # Stamp Task if args[8]=='*': type = random.randint(0, 1) if type: TaskStamp(message).add() elif args[8]=='TRUE': TaskStamp(message).add() # body if args[9]=='*': message.body = message.getAttributeAspect('body', 'type').makeValue(M_TEXT) elif not args[9]=='': txt = u"%s"%args[9] message.body = message.getAttributeAspect('body', 'type').makeValue(txt) else: # default value message.body = message.getAttributeAspect('body', 'type').makeValue(M_TEXT) #collection if args[1]=='*': # semi-random data if not len(collectionsDict) == 0: collectionsDict.values()[random.randint(0,len(collectionsDict)-1)].add(message) elif not args[1]=='': collectionNames = string.split(args[1], ';') for name in collectionNames: if collectionsDict.has_key(name): collectionsDict[name].add(message) else: GenerateCollection(view, [name]) collectionsDict[name].add(message) return message
def __ApplyChanges(self): """ Take the data from the list and apply the values to the items. """ # First store the current form values to the data structure self.__StoreFormData(self.currentPanelType, self.currentPanel, self.data[self.currentIndex]["values"]) for account in self.data: uuid = account["item"] if uuid: # We already have an account item created item = self.view.findUUID(account["item"]) else: # We need to create an account item if account["type"] == "IMAP": item = Mail.IMAPAccount(view=self.view) elif account["type"] == "POP": item = Mail.POPAccount(view=self.view) elif account["type"] == "SMTP": item = Mail.SMTPAccount(view=self.view) # XXX: Temp change that checks if no SMTP Account currently # exists and makes the new account the defaultSMTPAccount # for the default IMAP ccount if Mail.getCurrentSMTPAccount(view=self.view)[0] is None: mailAccount = Mail.getCurrentMailAccount(view=self.view) if mailAccount is not None: mailAccount.defaultSMTPAccount = item elif account["type"] == "WebDAV": item = Sharing.WebDAVAccount(view=self.view) values = account["values"] panel = PANELS[account["type"]] if panel.has_key("saveHandler"): # Call custom save handler; if None returned, we don't do # any more processing of that account within this loop item = panel["saveHandler"](item, panel["fields"], values) if item is not None: # Process each field defined in the PANEL data structure; # applying the values to the appropriate attributes: for (field, desc) in panel["fields"].iteritems(): if desc["type"] == "currentPointer": # If this value is True, make this item current: if values[field]: app = schema.ns("osaf.app", self.view) ref = getattr(app, desc["pointer"]) ref.item = item elif desc["type"] == "itemRef": # Find the item for this UUID and assign the itemref: if values[field]: item.setAttributeValue(desc["attr"], self.view.findUUID(values[field])) else: # Otherwise, make the literal assignment: try: item.setAttributeValue(desc["attr"], values[field]) except: pass
def GenerateMailMessage(view, mainView, args): """ Generate one Mail message item """ message = Mail.MailMessage(view=view) # subject if args[0] == '*': # semi-random data message.subject = random.choice(TITLES) elif not args[0] == '': message.subject = args[0] else: #default value message.subject = 'untitled' # dateSent (date + time) message.dateSent = ReturnCompleteDatetime(args[2], args[3]) # fromAdress message.fromAddress = GenerateCalendarParticipant(view, args[4]) # toAddress if args[5] == '*': for num in range(random.randint(1, 3)): message.toAddress.append(GenerateCalendarParticipant( view, args[5])) elif not args[5] == '': addressList = string.split(args[5], ';') for add in addressList: message.toAddress.append(GenerateCalendarParticipant(view, add)) else: #default value message.toAddress.append( GenerateCalendarParticipant(view, '*****@*****.**')) # outbound smtpAccount = Mail.getCurrentSMTPAccount(view)[0] mailAccount = Mail.getCurrentMailAccount(view) if args[6] == '*': outbound = random.randint(0, 1) if outbound: message.outgoingMessage(smtpAccount) """Make the Message appear as if it has already been sent""" message.deliveryExtension.sendSucceeded() else: message.incomingMessage(mailAccount) elif args[6] == 'TRUE': message.outgoingMessage(smtpAccount) """Make the Message appear as if it has already been sent""" message.deliveryExtension.sendSucceeded() else: # default value "incoming" message.incomingMessage(mailAccount) # Stamp Event if args[7] == '*': type = random.randint(0, 1) if type: message.StampKind( 'add', Calendar.CalendarEventMixin.getKind(message.itsView)) elif args[7] == 'TRUE': message.StampKind('add', Calendar.CalendarEventMixin.getKind(message.itsView)) # Stamp Task if args[8] == '*': type = random.randint(0, 1) if type: message.StampKind('add', TaskMixin.getKind(message.itsView)) elif args[8] == 'TRUE': message.StampKind('add', TaskMixin.getKind(message.itsView)) # body if args[9] == '*': message.body = message.getAttributeAspect('body', 'type').makeValue(M_TEXT) elif not args[9] == '': message.body = message.getAttributeAspect('body', 'type').makeValue(args[9]) else: # default value message.body = message.getAttributeAspect('body', 'type').makeValue(M_TEXT) #collection if args[1] == '*': # semi-random data collectionsDict.values()[random.randint(0, len(collectionsDict) - 1)].add(message) elif not args[1] == '': collectionNames = string.split(args[1], ';') for name in collectionNames: if collectionsDict.has_key(name): collectionsDict[name].add(message) else: GenerateCollection(view, mainView, [name]) collectionsDict[name].add(message) return message