#include "IMFMultipart.h" #include "Log.h" namespace coreutils { IMFMultipart::IMFMultipart(int fd, ZString boundary) { int ch = 0; int rc = 0; while((ch != '\r') && (ch != '\n')) { rc = ::read(fd, &ch, 1); --length; if((ch != '\r') && (ch != '\n')) boundary.write(ch); } if(ch == '\r') { rc = ::read(fd, &ch, 1); --length; } while(1) { sections.emplace_back(fd, boundary); rc = ::read(fd, &ch, 1); --length; if(ch == '-') { rc = ::read(fd, &ch, 1); --length; if(ch == '-') { break; } } } rc = ::read(fd, &ch, 1); --length; if(ch == '\r') { rc = ::read(fd, &ch, 1); --length; if(ch == '\n') { } } } IMFMultipart::IMFMultipart(ZString &in, ZString &boundary) { Log(LOG_DEBUG_1) << in; std::stringstream temp; temp << "--" << boundary; sections = in.split(temp.str().c_str()); for(int ix = 0; ix < sections.size(); ++ix) { sections[ix].ifNext("\r\n"); sections[ix].trimCRLF(); Log(LOG_DEBUG_1) << "[" << sections[ix] << "]."; if(sections[ix].equals("--")) sections[ix] = ZString(""); sections[ix].ifNext("\r\n"); } } std::string IMFMultipart::toString() { return std::string(getData(), getLength()); } int IMFMultipart::getCount() { return sections.size(); } ZString IMFMultipart::getSectionAt(int index) { return sections[index]; } }