Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
static void _php_imap_add_body(Object &ret, BODY *body, bool do_multipart) {

  if (body->type <= TYPEMAX) {
   ret.o_set("type", body->type);
  }

  if (body->encoding <= ENCMAX) {
    ret.o_set("encoding", body->encoding);
  }

  if (body->subtype) {
    ret.o_set("ifsubtype", 1);
    ret.o_set("subtype", String((const char*)body->subtype, CopyString));
  } else {
    ret.o_set("ifsubtype", 0);
  }

  if (body->description) {
    ret.o_set("ifdescription", 1);
    ret.o_set("description",
      String((const char*)body->description, CopyString));
  } else {
    ret.o_set("ifdescription", 0);
  }

  if (body->id) {
    ret.o_set("ifid", 1);
    ret.o_set("id", String((const char*)body->id, CopyString));
  } else {
    ret.o_set("ifid", 0);
  }


  if (body->size.lines) {
    ret.o_set("lines", (int64_t)body->size.lines);
  }

  if (body->size.bytes) {
    ret.o_set("bytes", (int64_t)body->size.bytes);
  }

  if (body->disposition.type) {
    ret.o_set("ifdisposition", 1);
    ret.o_set("disposition",
      String((const char*)body->disposition.type, CopyString));
  } else {
    ret.o_set("ifdisposition", 0);
  }

  if (body->disposition.parameter) {
    PARAMETER *dpar;
    dpar = body->disposition.parameter;
    ret.o_set("ifdparameters", 1);

    Array dparametres(Array::Create());
    do {
      Object dparam(SystemLib::AllocStdClassObject());
      dparam.o_set("attribute",
        String((const char*)dpar->attribute, CopyString));
      dparam.o_set("value", String((const char*)dpar->value, CopyString));
      dparametres.append(dparam);
    } while ((dpar = dpar->next));
    ret.o_set("dparameters", dparametres);
  } else {
    ret.o_set("ifdparameters", 0);
  }

  PARAMETER *par;
  Array parametres(Array::Create());

  if ((par = body->parameter)) {
    ret.o_set("ifparameters", 1);
    do {
      Object param(SystemLib::AllocStdClassObject());
      OBJ_SET_ENTRY(param, par, "attribute", attribute);
      OBJ_SET_ENTRY(param, par, "value", value);
      parametres.append(param);
    } while ((par = par->next));
    ret.o_set("parameters", parametres);
  } else {
    ret.o_set("ifparameters", 0);
  }

  if (do_multipart) {
    /* multipart message ? */
    if (body->type == TYPEMULTIPART) {
      parametres.clear();
      PART *part;
      for (part = body->nested.part; part; part = part->next) {
        Object param(SystemLib::AllocStdClassObject());
        _php_imap_add_body(param, &part->body, do_multipart);
        parametres.append(param);
      }
      ret.o_set("parts", parametres);
    }

    /* encapsulated message ? */
    if ((body->type == TYPEMESSAGE) && (!strcasecmp(body->subtype, "rfc822"))) {
      body = body->nested.msg->body;
      parametres.clear();
      Object param(SystemLib::AllocStdClassObject());
      _php_imap_add_body(param, body, do_multipart);
      parametres.append(param);
      ret.o_set("parts", parametres);
    }
  }
}