예제 #1
0
static Variant HHVM_FUNCTION(imap_body, const Resource& imap_stream,
                             int64_t msg_number, int64_t options /* = 0 */) {
  if (options && ((options & ~(FT_UID|FT_PEEK|FT_INTERNAL)) != 0)) {
    raise_warning("invalid value for the options parameter");
    return false;
  }

  ImapStream *obj = imap_stream.getTyped<ImapStream>();

  int msgindex;
  if (options & FT_UID) {
    /* This should be cached; if it causes an extra RTT to the
       IMAP server, then that's the price we pay for making sure
       we don't crash. */
    msgindex = mail_msgno(obj->m_stream, msg_number);
  } else {
    msgindex = msg_number;
  }

  if (!obj->checkMsgNumber(msgindex)) {
    return false;
  }

  unsigned long body_len = 0;
  char *body = mail_fetchtext_full(obj->m_stream, msg_number,
                                   &body_len, (options ? options : NIL));
  if (body_len == 0) {
    return empty_string;
  } else {
    return String(body, body_len, CopyString);
  }
}
예제 #2
0
파일: ext_imap.cpp 프로젝트: 2bj/hhvm
Variant f_imap_uid(const Resource& imap_stream, int64_t msg_number) {
  ImapStream *obj = imap_stream.getTyped<ImapStream>();
  if (!obj->checkMsgNumber(msg_number)) {
    return false;
  }
  return (int64_t)mail_uid(obj->m_stream, msg_number);
}
예제 #3
0
파일: ext_imap.cpp 프로젝트: 2bj/hhvm
Variant f_imap_fetchheader(const Resource& imap_stream, int64_t msg_number,
                           int64_t options /* = 0 */) {
  if (options && ((options & ~(FT_UID|FT_INTERNAL|FT_PREFETCHTEXT)) != 0)) {
    Logger::Warning("invalid value for the options parameter");
    return false;
  }

  ImapStream *obj = imap_stream.getTyped<ImapStream>();
  int msgindex;
  if (options & FT_UID) {
    /* This should be cached; if it causes an extra RTT to the
       IMAP server, then that's the price we pay for making sure
       we don't crash. */
    msgindex = mail_msgno(obj->m_stream, msg_number);
  } else {
    msgindex = msg_number;
  }

  if (!obj->checkMsgNumber(msgindex)) {
    return false;
  }

  return String(mail_fetchheader_full(obj->m_stream, msgindex, NIL, NIL,
                                      (options ? options : NIL)), CopyString);
}
예제 #4
0
파일: ext_imap.cpp 프로젝트: 2bj/hhvm
Variant f_imap_fetchbody(const Resource& imap_stream, int64_t msg_number,
                         const String& section, int64_t options /* = 0 */) {
  if (options && ((options & ~(FT_UID|FT_PEEK|FT_INTERNAL)) != 0)) {
    raise_warning("invalid value for the options parameter");
    return false;
  }

  ImapStream *obj = imap_stream.getTyped<ImapStream>();

  if (!options || !(options & FT_UID)) {
    if (!obj->checkMsgNumber(msg_number)) {
      return false;
    }
  }

  unsigned long len;
  char *body = mail_fetchbody_full(obj->m_stream, msg_number,
                                   (char*)section.data(),
                                   &len, (options ? options : NIL));

  if (!body) {
    raise_warning("No body information available");
    return false;
  }

  return String(body, len, CopyString);
}
예제 #5
0
static Variant HHVM_FUNCTION(imap_bodystruct, const Resource& imap_stream,
                             int64_t msg_number, const String& section) {
  ImapStream *obj = imap_stream.getTyped<ImapStream>();
  if (!obj->checkMsgNumber(msg_number)) {
    return false;
  }
  Object ret(SystemLib::AllocStdClassObject());

  BODY *body;
  body = mail_body(obj->m_stream, msg_number, (unsigned char *)section.data());
  if (body == NULL) {
    return false;
  }

  _php_imap_add_body(ret, body, false);
  return ret;
}
예제 #6
0
파일: ext_imap.cpp 프로젝트: 2bj/hhvm
Variant f_imap_fetchstructure(const Resource& imap_stream, int64_t msg_number,
                              int64_t options /* = 0 */) {
  if (options && ((options & ~FT_UID) != 0)) {
    raise_warning("invalid value for the options parameter");
    return false;
  }

  if (msg_number < 1) {
    return false;
  }

  ImapStream *obj = imap_stream.getTyped<ImapStream>();
  int msgindex;
  if (options & FT_UID) {
    /* This should be cached; if it causes an extra RTT to the
       IMAP server, then that's the price we pay for making sure
       we don't crash. */
    msgindex = mail_msgno(obj->m_stream, msg_number);
  } else {
    msgindex = msg_number;
  }

  if (!obj->checkMsgNumber(msgindex)) {
    return false;
  }

  BODY *body;

  mail_fetchstructure_full(obj->m_stream, msg_number, &body,
                           (options ? options : NIL));

  if (!body) {
    raise_warning("No body information available");
    return false;
  }

  Object ret(SystemLib::AllocStdClassObject());
  _php_imap_add_body(ret, body, true);

  return ret;
}
예제 #7
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;
}