Module: sems
Branch: master
Commit: 2e3c2b16a5d3ee7bd0cd8d870d7c03402ebb9c69
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=2e3c2b16a5d3ee7bd0cd8d870d7c03402ebb9c69

Author: Juha Heinanen <[email protected]>
Committer: Juha Heinanen <[email protected]>
Date:   Thu May  8 14:47:20 2014 +0300

core: new AmMimeMody methods
- added public method deletePart(const string& content_type)
- added private methods clearPart(Parts::iterator position) and
  convertToSinglepart()

---

 core/AmMimeBody.cpp |   36 ++++++++++++++++++++++++++++++++++++
 core/AmMimeBody.h   |    7 +++++++
 2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/core/AmMimeBody.cpp b/core/AmMimeBody.cpp
index fb3c912..29e6820 100644
--- a/core/AmMimeBody.cpp
+++ b/core/AmMimeBody.cpp
@@ -137,6 +137,11 @@ void AmMimeBody::clearParts()
   }
 }
 
+void AmMimeBody::clearPart(Parts::iterator position)
+{
+  parts.erase(position);
+}
+
 void AmMimeBody::clearPayload()
 {
   delete [] payload;
@@ -602,6 +607,17 @@ void AmMimeBody::convertToMultipart()
   content_len = 0;
 }
 
+void AmMimeBody::convertToSinglepart()
+{
+  if (parts.size() == 1) {
+    this->ct = parts.front()->ct;
+    setPayload(parts.front()->payload, parts.front()->content_len);
+    clearParts();
+  } else {
+    DBG("body does not have exactly one part\n");
+  }
+}
+
 void AmContentType::setType(const string& t)
 {
   type = t;
@@ -659,6 +675,26 @@ AmMimeBody* AmMimeBody::addPart(const string& content_type)
   return body;
 }
 
+int AmMimeBody::deletePart(const string& content_type)
+{
+  if (!ct.isType(MULTIPART)) {
+    DBG("body is not multipart\n");
+    return -1;
+  }
+
+  for(Parts::iterator it = parts.begin();
+      it != parts.end(); ++it) {
+    if((*it)->hasContentType(content_type)) {
+      clearPart(it);
+      if (parts.size() == 1) convertToSinglepart();
+      return 0;
+    }
+  }
+
+  DBG("no match");
+  return -1;
+}
+
 void AmMimeBody::setPayload(const unsigned char* buf, unsigned int len)
 {
   if(payload)
diff --git a/core/AmMimeBody.h b/core/AmMimeBody.h
index 6f020ac..8d6b847 100644
--- a/core/AmMimeBody.h
+++ b/core/AmMimeBody.h
@@ -83,6 +83,7 @@ private:
   Parts parts;
 
   void clearParts();
+  void clearPart(Parts::iterator position);
   void clearPayload();
 
   int parseMultipart(const unsigned char* buf, unsigned int len);
@@ -90,6 +91,7 @@ private:
   int parseSinglePart(unsigned char* buf, unsigned int len);
 
   void convertToMultipart();
+  void convertToSinglepart();
 
 public:
   /** Empty constructor */
@@ -122,6 +124,11 @@ public:
    */
   AmMimeBody* addPart(const string& content_type);
 
+  /** 
+   * Delete a body part, converting resulting body to single-part if necessary.
+   */
+  int deletePart(const string& content_type);
+
   /** Get content-type without any parameters */
   string getCTStr() const { return ct.getStr(); }
 

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to