Exemplo n.º 1
0
    def command(self):
        session, config, idx = self.session, self.session.config, self._idx()
        results = []
        args = list(self.args)
        if args and args[0].lower() == 'raw':
            raw = args.pop(0)
        else:
            raw = False
        emails = [Email(idx, mid) for mid in self._choose_messages(args)]

        rv = self._side_effects(emails)
        if rv is not None:
            # This is here so derived classes can do funky things.
            return rv

        for email in emails:
            if raw:
                subject = email.get_msg_info(idx.MSG_SUBJECT)
                results.append(
                    self.RawResult({
                        'summary': _('Raw message: %s') % subject,
                        'source': email.get_file().read()
                    }))
            else:
                old_result = None
                for result in results:
                    if email.msg_idx_pos in result.results:
                        old_result = result
                if old_result:
                    old_result.add_email(email)
                    continue

                conv = [
                    int(c[0], 36)
                    for c in idx.get_conversation(msg_idx=email.msg_idx_pos)
                ]
                if email.msg_idx_pos not in conv:
                    conv.append(email.msg_idx_pos)

                # FIXME: This is a hack. The indexer should just keep things
                #        in the right order on rescan. Fixing threading is a
                #        bigger problem though, so we do this for now.
                def sort_conv_key(msg_idx_pos):
                    info = idx.get_msg_at_idx_pos(msg_idx_pos)
                    return -int(info[idx.MSG_DATE], 36)

                conv.sort(key=sort_conv_key)

                results.append(
                    SearchResults(session,
                                  idx,
                                  results=conv,
                                  num=len(conv),
                                  emails=[email]))
        if len(results) == 1:
            return self._success(_('Displayed a single message'),
                                 result=results[0])
        else:
            return self._success(_('Displayed %d messages') % len(results),
                                 result=results)
Exemplo n.º 2
0
 def command(self):
     session, idx = self.session, self._idx()
     session.order = self.args and self.args[0] or None
     idx.sort_results(session, session.results, session.order)
     session.displayed = SearchResults(session, idx)
     return self._success(_('Changed sort order to %s') % session.order,
                          result=session.displayed)
Exemplo n.º 3
0
    def command(self):
        session, config, idx = self.session, self.session.config, self._idx()
        results = []
        args = list(self.args)
        args.extend(
            ['=%s' % mid.replace('=', '') for mid in self.data.get('mid', [])])
        if args and args[0].lower() == 'raw':
            raw = args.pop(0)
        else:
            raw = False
        emails = [Email(idx, mid) for mid in self._choose_messages(args)]

        rv = self._side_effects(emails)
        if rv is not None:
            # This is here so derived classes can do funky things.
            return rv

        for email in emails:
            if raw:
                subject = email.get_msg_info(idx.MSG_SUBJECT)
                results.append(
                    self.RawResult({
                        'summary': _('Raw message: %s') % subject,
                        'source': email.get_file().read()
                    }))
            else:
                old_result = None
                for result in results:
                    if email.msg_idx_pos in result.results:
                        old_result = result
                if old_result:
                    old_result.add_email(email)
                    continue

                # Get conversation
                conv = idx.get_conversation(msg_idx=email.msg_idx_pos)

                # Sort our results by date...
                def sort_conv_key(info):
                    return -int(info[idx.MSG_DATE], 36)

                conv.sort(key=sort_conv_key)

                # Convert to index positions only
                conv = [int(info[idx.MSG_MID], 36) for info in conv]

                session.results = conv
                results.append(
                    SearchResults(session, idx, emails=[email], num=len(conv)))
        if len(results) == 1:
            return self._success(_('Displayed a single message'),
                                 result=results[0])
        else:
            session.results = []
            return self._success(_('Displayed %d messages') % len(results),
                                 result=results)
Exemplo n.º 4
0
 def command(self, search=None):
     session, idx, start, num = self._do_search(search=search)
     full_threads = self.data.get('full', False)
     session.displayed = SearchResults(session,
                                       idx,
                                       start=start,
                                       num=num,
                                       full_threads=full_threads)
     session.ui.mark(_('Prepared %d search results') % len(session.results))
     return self._success(
         _('Found %d results in %.3fs') %
         (len(session.results), session.ui.report_marks(quiet=True)),
         result=session.displayed)
Exemplo n.º 5
0
 def command(self):
     session, idx = self._do_search()
     full_threads = self.data.get('full', False)
     session.displayed = SearchResults(session,
                                       idx,
                                       start=self._start,
                                       num=self._num,
                                       emails=self._emails,
                                       view_pairs=self._email_view_pairs,
                                       full_threads=full_threads)
     session.ui.mark(
         _('Prepared %d search results (context=%s)') %
         (len(session.results), self.context))
     return self._success(
         _('Found %d results in %.3fs') %
         (len(session.results), session.ui.report_marks(quiet=True)),
         result=session.displayed)
Exemplo n.º 6
0
 def command(self):
     session, idx = self.session, self._idx()
     session.order = self.args and self.args[0] or None
     idx.sort_results(session, session.results, session.order)
     session.displayed = SearchResults(session, idx)
     return session.displayed
Exemplo n.º 7
0
 def command(self, search=None):
     session, idx, start, num = self._do_search(search=search)
     session.displayed = SearchResults(session, idx, start=start, num=num)
     return session.displayed