Пример #1
0
    def handle_messages(self, imbox, project, email=None, assignee=None):
        logger.info("--- Started processing emails ---")
        unread_messages = imbox.messages(unread=True,
                                         folder='INBOX',
                                         sent_to=email or project.email)
        for uid, message in unread_messages:
            try:
                subject = getattr(message, 'subject', 'Email ticket')
                logger.info("Got message %s: %s" % (uid, subject))

                if SETTINGS['ignore_autoreply'] and self._is_autoreply(
                        message):
                    logger.info('  Message is auto-submitted, skipping')
                    if SETTINGS['mark_seen']:
                        imbox.mark_seen(uid)
                    continue

                if Ticket.objects.filter(
                        message_id=uid).exists() or Comment.objects.filter(
                            message_id=uid).exists():
                    logger.info('  Message already exists, skipping')
                    if SETTINGS['mark_seen']:
                        imbox.mark_seen(uid)
                    continue

                try:
                    body = message.body['html'][0]
                except IndexError:
                    try:
                        body = message.body['plain'][0]
                    except IndexError:
                        body = ''

                initial = self._get_initial_issue(message)

                if initial is None:
                    ticket = Ticket.create(
                        title=subject[:255],
                        body=body,
                        customer=message.sent_from[0]['email'],
                        message_id=uid,
                        assignee=assignee or project.default_assignee,
                        project=project)
                    logger.info('  Created new ticket')
                    self._create_attachments(message.attachments, ticket)
                else:
                    comment = Comment.objects.create(body=body,
                                                     author=None,
                                                     message_id=uid,
                                                     ticket=initial)
                    self._create_attachments(message.attachments, comment)
                    logger.info('  Added comment to ticket')

                if SETTINGS['mark_seen']:
                    imbox.mark_seen(uid)
            except Exception:
                logger.exception('  Error while retrieving email %s' % uid)
        logger.info("--- Finished processing emails ---")
Пример #2
0
    def handle_messages(self, imbox, project, email=None, assignee=None):
        logger.info("--- Started processing emails ---")
        unread_messages = imbox.messages(unread=True, folder='INBOX', sent_to=email or project.email)
        for uid, message in unread_messages:
            try:
                subject = getattr(message, 'subject', 'Email ticket')
                logger.info("Got message %s: %s" % (uid, subject))

                if SETTINGS['ignore_autoreply'] and self._is_autoreply(message):
                    logger.info('  Message is auto-submitted, skipping')
                    if SETTINGS['mark_seen']:
                        imbox.mark_seen(uid)
                    continue

                if Ticket.objects.filter(message_id=uid).exists() or Comment.objects.filter(message_id=uid).exists():
                    logger.info('  Message already exists, skipping')
                    if SETTINGS['mark_seen']:
                        imbox.mark_seen(uid)
                    continue

                try:
                    body = message.body['html'][0]
                except IndexError:
                    try:
                        body = message.body['plain'][0]
                    except IndexError:
                        body = ''

                initial = self._get_initial_issue(message)

                if initial is None:
                    ticket = Ticket.create(
                            title=subject[:255],
                            body=body,
                            customer=message.sent_from[0]['email'],
                            message_id=uid,
                            assignee=assignee or project.default_assignee,
                            project=project
                    )
                    logger.info('  Created new ticket')
                    self._create_attachments(message.attachments, ticket)
                else:
                    comment = Comment.objects.create(
                            body=body,
                            author=None,
                            message_id=uid,
                            ticket=initial
                    )
                    self._create_attachments(message.attachments, comment)
                    logger.info('  Added comment to ticket')

                if SETTINGS['mark_seen']:
                    imbox.mark_seen(uid)
            except Exception:
                logger.exception('  Error while retrieving email %s' % uid)
        logger.info("--- Finished processing emails ---")
Пример #3
0
    def form_valid(self, form):
        if not self.attachment_formset.is_valid():
            return self.render_to_response(self.get_context_data())
        data = form.cleaned_data
        comment = data.pop('comment')
        ticket = Ticket.create(body='This ticket was created by [user:%d]' % self.request.user.pk,
                               message_id='ticket-%d' % time.mktime(now().timetuple()),
                               author=self.request.user,
                               **data)
        reply = Comment.objects.create(ticket=ticket, body=comment, author=self.request.user)

        self.attachment_formset.instance = reply
        self.attachment_formset.save()

        new_answer.send(sender=Comment, ticket=ticket, answer=reply)
        return HttpResponseRedirect(reverse('helpdesk_home'))
Пример #4
0
    def form_valid(self, form):
        if not self.attachment_formset.is_valid():
            return self.render_to_response(self.get_context_data())
        data = form.cleaned_data
        comment = data.pop('comment')
        ticket = Ticket.create(
            body='This ticket was created by [user:%d]' % self.request.user.pk,
            message_id='ticket-%d' % time.mktime(now().timetuple()),
            author=self.request.user,
            **data)
        reply = Comment.objects.create(ticket=ticket,
                                       body=comment,
                                       author=self.request.user)

        self.attachment_formset.instance = reply
        self.attachment_formset.save()

        new_answer.send(sender=Comment, ticket=ticket, answer=reply)
        return HttpResponseRedirect(reverse('helpdesk_home'))