示例#1
0
  ENVELOPE * 
  ImapClient::fetchEnvelope(const std::string& aHost, 
                            const std::string& aUsername, 
                            const std::string& aPassword, 
                            const std::string& aMailbox, 
                            unsigned long aMessageNumber,
                            std::vector<int>& aFlagsVector,
                            const bool aUid) 
  {
#include "linkage.c"
    MAILSTREAM* lSource = getMailStream(aHost, aUsername, aPassword, aMailbox, true); 
    
    if (aUid) {
      aMessageNumber = mail_msgno(lSource, aMessageNumber);
    }
    
    ENVELOPE* lResult = mail_fetchenvelope(lSource, aMessageNumber);
    
    if (!lResult) {
      throw EmailException("WRONG_ID", "Could not get message - wrong message id.");
    }
    
    
    MESSAGECACHE* lCache = mail_elt(lSource, aMessageNumber);
    
    if (lCache->seen == 1) {
      aFlagsVector[0] = 1;
    }
    if (lCache->deleted == 1) {
      aFlagsVector[1] = 1;
    }
    if (lCache->flagged == 1) {
      aFlagsVector[2] = 1;
    }
    if (lCache->answered == 1) {
      aFlagsVector[3] = 1;
    }
    if (lCache->draft == 1) {
      aFlagsVector[4] = 1;
    }
    
    return  lResult;
    
  }
示例#2
0
文件: ext_imap.cpp 项目: 2bj/hhvm
Variant f_imap_headerinfo(const Resource& imap_stream, int64_t msg_number,
                          int64_t fromlength /* = 0 */,
                          int64_t subjectlength /* = 0 */,
                          const String& defaulthost /* = "" */) {
  ImapStream *obj = imap_stream.getTyped<ImapStream>();
  if (fromlength < 0 || fromlength > MAILTMPLEN) {
    Logger::Warning("From length has to be between 0 and %d", MAILTMPLEN);
    return false;
  }
  if (subjectlength < 0 || subjectlength > MAILTMPLEN) {
    Logger::Warning("Subject length has to be between 0 and %d", MAILTMPLEN);
    return false;
  }
  if (!obj->checkMsgNumber(msg_number)) {
    return false;
  }
  if (!mail_fetchstructure(obj->m_stream, msg_number, NIL)) {
    return false;
  }

  MESSAGECACHE *cache = mail_elt(obj->m_stream, msg_number);
  ENVELOPE *en = mail_fetchenvelope(obj->m_stream, msg_number);

  /* call a function to parse all the text, so that we can use the
     same function to parse text from other sources */
  Object ret = _php_make_header_object(en);

  /* now run through properties that are only going to be returned
     from a server, not text headers */
  ret.o_set("Recent",   cache->recent ? (cache->seen ? "R": "N") : " ");
  ret.o_set("Unseen",   (cache->recent | cache->seen) ? " " : "U");
  ret.o_set("Flagged",  cache->flagged  ? "F" : " ");
  ret.o_set("Answered", cache->answered ? "A" : " ");
  ret.o_set("Deleted",  cache->deleted  ? "D" : " ");
  ret.o_set("Draft",    cache->draft    ? "X" : " ");

  char dummy[2000], fulladdress[MAILTMPLEN + 1];
  snprintf(dummy, sizeof(dummy), "%4ld", cache->msgno);
  ret.o_set("Msgno", String(dummy, CopyString));

  mail_date(dummy, cache);
  ret.o_set("MailDate", String(dummy, CopyString));

  snprintf(dummy, sizeof(dummy), "%ld", cache->rfc822_size);
  ret.o_set("Size", String(dummy, CopyString));

  ret.o_set("udate", (int64_t)mail_longdate(cache));

  if (en->from && fromlength) {
    fulladdress[0] = 0x00;
    mail_fetchfrom(fulladdress, obj->m_stream, msg_number, fromlength);
    ret.o_set("fetchfrom", String(fulladdress, CopyString));
  }
  if (en->subject && subjectlength) {
    fulladdress[0] = 0x00;
    mail_fetchsubject(fulladdress, obj->m_stream, msg_number, subjectlength);
    ret.o_set("fetchsubject", String(fulladdress, CopyString));
  }

  return ret;
}