Get the most recent received email(s)

 Possible options:
   count: number of emails to retrieve. The default value is 1.
   order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
541630
def last(options = nil, &block)
      options = options ? Hash[options] : {}
      options[:what] = :last
      options[:count] ||= 1
      find(options, &block)
    end
398656
def get(self):
        
        mail = {
            'from': self._get_or_none(self.from_email),
            'subject': self._get_or_none(self.subject),
            'personalizations': [p.get() for p in self.personalizations or []],
            'content': [c.get() for c in self.contents or []],
            'attachments': [a.get() for a in self.attachments or []],
            'template_id': self._get_or_none(self.template_id),
            'sections': self._flatten_dicts(self.sections),
            'headers': self._flatten_dicts(self.headers),
            'categories': [c.get() for c in self.categories or []],
            'custom_args': self._flatten_dicts(self.custom_args),
            'send_at':  self._get_or_none(self.send_at),
            'batch_id': self._get_or_none(self.batch_id),
            'asm': self._get_or_none(self.asm),
            'ip_pool_name': self._get_or_none(self.ip_pool_name),
            'mail_settings': self._get_or_none(self.mail_settings),
            'tracking_settings': self._get_or_none(self.tracking_settings),
            'reply_to': self._get_or_none(self.reply_to),
        }

        return {key: value for key, value in mail.items()
                if value is not None and value != [] and value != {}}
832080
def get_count(self, query=None):
        
        query = query or Query()
        return self.get_db().alerts.find(query.where).count()
164233
def get_email_subject(email, default):
  
  s = get_settings(string="OVP_EMAILS")
  email_settings = s.get(email, {})

  title = email_settings.get("subject", default)

  return _(title)
1171404
def query_recent(num=8, **kwargs):
        '''
        
        '''
        order_by_create = kwargs.get('order_by_create', False)
        kind = kwargs.get('kind', None)
        if order_by_create:
            if kind:
                recent_recs = TabPost.select().where(
                    (TabPost.kind == kind) & (TabPost.valid == 1)
                ).order_by(
                    TabPost.time_create.desc()
                ).limit(num)
            else:
                recent_recs = TabPost.select().where(
                    TabPost.valid == 1
                ).order_by(
                    TabPost.time_create.desc()
                ).limit(num)
        else:
            if kind:
                recent_recs = TabPost.select().where(
                    (TabPost.kind == kind) & (TabPost.valid == 1)
                ).order_by(
                    TabPost.time_update.desc()
                ).limit(num)
            else:
                recent_recs = TabPost.select().where(
                    TabPost.valid == 1
                ).order_by(
                    TabPost.time_update.desc()
                ).limit(num)
        return recent_recs
859238
def get_queued():
    
    return Email.objects.filter(status=STATUS.queued) \
        .select_related('template') \
        .filter(Q(scheduled_time__lte=now()) | Q(scheduled_time=None)) \
        .order_by(*get_sending_order()).prefetch_related('attachments')[:get_batch_size()]
1294463
def deferred_emails():
    """"""
    status = SERVER_STATUS['OK']
    count = Message.objects.deferred().count()

    if DEFERRED_WARNING_THRESHOLD <= count < DEFERRED_DANGER_THRESHOLD:
        status = SERVER_STATUS['WARNING']
    if count >= DEFERRED_DANGER_THRESHOLD:
        status = SERVER_STATUS['DANGER']

    return {
        'label': 'Deferred Email',
        'status': status,
        'info': 'There are currently {0} deferred messages.'.format(count)
    }
1257978
function filter_email(value) {
    var m = EMAIL_RE.exec(value);
    if(m == null) throw OptError('Excpeted an email address.');
    return m[1];
}
1344912
def emails_parse(emails_dict):
    
    result = emails_dict['ListVerifiedEmailAddressesResponse'][
        'ListVerifiedEmailAddressesResult']
    emails = [email for email in result['VerifiedEmailAddresses']]

    return sorted(emails)
10814
def get_last(postid, limit=10):
        '''
        
        '''
        recs = TabPostHist.select().where(
            TabPostHist.post_id == postid
        ).order_by(TabPostHist.time_update.desc()).limit(limit)
        if recs.count():
            return recs.get()
        return None
42003
public function getMessages($number = 0, $start = 0, $order = 'DESC') {
        if ($number == 0)
        {
            $number = $this->countMessages();
        }
        $emails = array();
        $result = imap_search($this->imap, 'ALL');
        if ($result)
        {
            $ids = array();
            foreach ($result as $k => $i)
            {
                $ids[] = $i;
            }

            if ($order == 'DESC')
            {
                $ids = array_reverse($ids);
            }
            $ids = array_chunk($ids, $number);
            $ids = $ids[$start];

            foreach ($ids as $id)
            {
                $emails[] = $this->getMessage($id);
            }
        }
        return $emails;
    }
478933
def get_email(self, token):
        """"""
        resp = requests.get(self.emails_url,
                            params={'access_token': token.token})
        emails = resp.json().get('values', [])
        email = ''
        try:
            email = emails[0].get('email')
            primary_emails = [e for e in emails if e.get('is_primary', False)]
            email = primary_emails[0].get('email')
        except (IndexError, TypeError, KeyError):
            return ''
        finally:
            return email
697418
function list_emails($default = false)
    {
        if ($this->emails === null) {
            $this->emails = array();

            $sql_result = $this->db->query(
                "SELECT `identity_id`, `name`, `email`"
                ." FROM " . $this->db->table_name('identities', true)
                ." WHERE `user_id` = ? AND `del` <> 1"
                ." ORDER BY `standard` DESC, `name` ASC, `email` ASC, `identity_id` ASC",
                $this->ID);

            while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
                $this->emails[] = $sql_arr;
            }
        }

        return $default ? $this->emails[0] : $this->emails;
    }
140870
def send_messages(self, emails):
        
        num_sent = 0
        for e in emails:
            html = None
            if isinstance(e, EmailMultiAlternatives):
                for a in e.alternatives:
                    if a[1] == 'text/html':
                        html = a[0]
            r = self._connection.send(
                from_=e.from_email,
                to=e.to,
                subject=e.subject,
                text=e.body,
                html=html,
                cc=e.cc,
                bcc=e.bcc,
                attachments=list(self._process_attachments(e)),
            )
            if 'error' not in r:
                num_sent += 1
        return num_sent
673265
def return_daily_messages_count(self, sender):
        
        h24 = now() - timedelta(days=1)
        return Message.objects.filter(sender=sender, sent_at__gte=h24).count()
451833
def ProcessResponse(self, state, response):
    """"""
    emails_left = self.args.emails_limit - self.IncrementCounter()
    if emails_left < 0:
      return

    if data_store.RelationalDBEnabled():
      client_id = response.source.Basename()
      client = data_store.REL_DB.ReadClientSnapshot(client_id)
      hostname = client.knowledge_base.fqdn or "unknown hostname"
      client_fragment_id = "/clients/%s" % client_id
    else:
      client_id = response.source
      client = aff4.FACTORY.Open(client_id, token=self.token)
      hostname = client.Get(client.Schema.HOSTNAME) or "unknown hostname"
      client_fragment_id = "/clients/%s" % client_id.Basename()

    if emails_left == 0:
      additional_message = (self.too_many_mails_msg % self.args.emails_limit)
    else:
      additional_message = ""

    subject = self.__class__.subject_template.render(
        source_urn=utils.SmartUnicode(self.source_urn))
    body = self.__class__.template.render(
        client_id=client_id,
        client_fragment_id=client_fragment_id,
        admin_ui_url=config.CONFIG["AdminUI.url"],
        source_urn=self.source_urn,
        additional_message=additional_message,
        signature=config.CONFIG["Email.signature"],
        hostname=utils.SmartUnicode(hostname),
        creator=utils.SmartUnicode(self.token.username))

    email_alerts.EMAIL_ALERTER.SendEmail(
        self.args.email_address,
        "grr-noreply",
        utils.SmartStr(subject),
        utils.SmartStr(body),
        is_html=True)
353374
def get_email_lists
      url = ApiRequest.base_path("questionpro.survey.getEmailLists")
      result = self.class.get(url, body: self.options)

      self.full_response = result
      self.status = result['status']
      
      email_lists = []
      result_email_lists = result['response']['emailLists']
      result_email_lists.each do |email_list|
        email_lists.push(EmailList.new(email_list))
      end
      
      return email_lists
    end