diff --git a/engine/Mime.cpp b/engine/Mime.cpp index dda7ad01..5f8d0707 100644 --- a/engine/Mime.cpp +++ b/engine/Mime.cpp @@ -321,6 +321,53 @@ MimeBody::~MimeBody() DDebug(DebugAll,"MimeBody::~MimeBody() '%s' [%p]",m_type.c_str(),this); } +// Find an additional header line by its name +MimeHeaderLine* MimeBody::findHdr(const char* name, const MimeHeaderLine* start) const +{ + ObjList* o = m_headers.skipNull(); + if (!o) + return 0; + // Find start point + if (start) + for (; o; o = o->skipNext()) + if (start == o->get()) { + o = o->skipNext(); + break; + } + // Find the header + for (; o; o = o->skipNext()) { + MimeHeaderLine* hdr = static_cast(o->get()); + if (hdr->name() &= name) + return hdr; + } + return 0; +} + +// Replace the value of an existing parameter or add a new one +bool MimeBody::setParam(const char* name, const char* value, const char* header) +{ + MimeHeaderLine* hdr = (!(header && *header)) ? &m_type : findHdr(header); + if (hdr) + hdr->setParam(name,value); + return (hdr != 0); +} + +// Remove a header parameter +bool MimeBody::delParam(const char* name, const char* header) +{ + MimeHeaderLine* hdr = (!(header && *header)) ? &m_type : findHdr(header); + if (hdr) + hdr->delParam(name); + return (hdr != 0); +} + +// Get a header parameter +const NamedString* MimeBody::getParam(const char* name, const char* header) const +{ + const MimeHeaderLine* hdr = (!(header && *header)) ? &m_type : findHdr(header); + return hdr ? hdr->getParam(name) : 0; +} + const DataBlock& MimeBody::getBody() const { if (m_body.null()) diff --git a/yatemime.h b/yatemime.h index c7942615..016d212b 100644 --- a/yatemime.h +++ b/yatemime.h @@ -256,6 +256,42 @@ public: inline void removeHdr(MimeHeaderLine* hdr) { if (hdr) m_headers.remove(hdr); } + /** + * Find an additional header line by its name. The names are compared case insensitive + * @param name The name of the header to find + * @param start The starting point in the list. 0 to start from the beginning + * @return Pointer to MimeHeaderLine or 0 if not found + */ + MimeHeaderLine* findHdr(const char* name, const MimeHeaderLine* start = 0) const; + + /** + * Replace the value of an existing parameter or add a new one + * @param name Parameter's name + * @param value Parameter's value + * @param header Header whose parameter will be changed. + * Set to 0 to use the body's content type header + * @return False if the header doesn't exist + */ + bool setParam(const char* name, const char* value = 0, const char* header = 0); + + /** + * Remove a header parameter + * @param name Parameter's name + * @param header Header whose parameter will be removed. + * Set to 0 to use the body's content type header + * @return False if the header doesn't exist + */ + bool delParam(const char* name, const char* header = 0); + + /** + * Get a header parameter + * @param name Parameter's name + * @param header Header whose parameter will be retrived. + * Set to 0 to use the body's content type header + * @return Pointer to the desired parameter or 0 if not found + */ + const NamedString* getParam(const char* name, const char* header = 0) const; + /** * Retrive the binary encoding of this MIME body * @return Block of binary data