From b8b096c44ffc63ed1fc4514a6b7f20bb87c1bfb8 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Fri, 15 Jul 2005 09:51:55 +0000 Subject: Added getName() to retrieve attachment filename. --- src/defaultAttachment.cpp | 18 +++++++++++++----- src/messageParser.cpp | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/defaultAttachment.cpp b/src/defaultAttachment.cpp index dc8f8ccc..118a301a 100644 --- a/src/defaultAttachment.cpp +++ b/src/defaultAttachment.cpp @@ -31,23 +31,24 @@ defaultAttachment::defaultAttachment() defaultAttachment::defaultAttachment(ref data, - const encoding& enc, const mediaType& type, const text& desc) - : m_type(type), m_desc(desc), m_data(data), m_encoding(enc) + const encoding& enc, const mediaType& type, const text& desc, const word& name) + : m_type(type), m_desc(desc), m_data(data), m_encoding(enc), m_name(name) { } defaultAttachment::defaultAttachment(ref data, - const mediaType& type, const text& desc) + const mediaType& type, const text& desc, const word& name) : m_type(type), m_desc(desc), m_data(data), - m_encoding(encoding::decide(data)) + m_encoding(encoding::decide(data)), m_name(name) { } defaultAttachment::defaultAttachment(const defaultAttachment& attach) : attachment(), m_type(attach.m_type), m_desc(attach.m_desc), - m_data(attach.m_data->clone().dynamicCast ()), m_encoding(attach.m_encoding) + m_data(attach.m_data->clone().dynamicCast ()), + m_encoding(attach.m_encoding), m_name(attach.m_name) { } @@ -61,6 +62,7 @@ defaultAttachment& defaultAttachment::operator=(const defaultAttachment& attach) { m_type = attach.m_type; m_desc = attach.m_desc; + m_name = attach.m_name; m_data = attach.m_data->clone().dynamicCast (); m_encoding = attach.m_encoding; @@ -103,6 +105,12 @@ const text& defaultAttachment::getDescription() const } +const word& defaultAttachment::getName() const +{ + return (m_name); +} + + const ref defaultAttachment::getData() const { return (m_data); diff --git a/src/messageParser.cpp b/src/messageParser.cpp index 94fec668..a3b71375 100644 --- a/src/messageParser.cpp +++ b/src/messageParser.cpp @@ -153,6 +153,7 @@ void messageParser::findAttachments(const bodyPart& part) if (isAttachment) { // Determine the media type of this attachment + const contentTypeField* contTypeField = NULL; mediaType type; try @@ -161,6 +162,8 @@ void messageParser::findAttachments(const bodyPart& part) (*hdr.findField(fields::CONTENT_TYPE)); type = ctf.getValue(); + + contTypeField = &ctf; } catch (exceptions::no_such_field) { @@ -184,10 +187,43 @@ void messageParser::findAttachments(const bodyPart& part) // No description available. } + // Get the name/filename (if available) + word name; + + // -- try the 'filename' parameter of 'Content-Disposition' field + if (contentDispField != NULL) + { + try + { + name = contentDispField->getFilename(); + } + catch (exceptions::no_such_parameter) + { + // No 'filename' parameter + } + } + + // -- try the 'name' parameter of 'Content-Type' field + if (name.getBuffer().empty() && contTypeField != NULL) + { + try + { + ref prm = contTypeField-> + findParameter("name").dynamicCast (); + + if (prm != NULL) + name = prm->getValue(); + } + catch (exceptions::no_such_parameter) + { + // No attachment name available. + } + } + // Construct the attachment object ref attach = vmime::create (bdy.getContents()->clone().dynamicCast (), - bdy.getEncoding(), type, description); + bdy.getEncoding(), type, description, name); if (contentDispField != NULL) { -- cgit v1.2.3