aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2006-10-14 08:31:25 +0000
committerVincent Richard <[email protected]>2006-10-14 08:31:25 +0000
commit6139afdbf8a0fced0cb31f1229df8ab85405514f (patch)
tree01772f3da000f7296bffde3a53c4f4c52a11dd9f
parentRenamed 'vmime::platformDependant' to 'vmime::platform'. (diff)
downloadvmime-6139afdbf8a0fced0cb31f1229df8ab85405514f.tar.gz
vmime-6139afdbf8a0fced0cb31f1229df8ab85405514f.zip
Updated example and doc with some code showing how to read embedded object data from a file.
-rw-r--r--doc/book/msg.tex34
-rw-r--r--examples/example3.cpp17
2 files changed, 43 insertions, 8 deletions
diff --git a/doc/book/msg.tex b/doc/book/msg.tex
index 84d4aa2d..9e43427e 100644
--- a/doc/book/msg.tex
+++ b/doc/book/msg.tex
@@ -269,8 +269,10 @@ mb.appendAttachment(att);
\subsection{HTML messages and embedded objects} % ----------------------------
-VMime also supports aggregated messages, which permits to build MIME messages
-containing HTML text and embedded objects (such as images).
+VMime also supports aggregate messages, which permits to build MIME messages
+containing HTML text and embedded objects (such as images). For more information
+about aggregate messages, please read RFC-2557 (\emph{MIME Encapsulation of
+Aggregate Documents, such as HTML}).
Creating such messages is quite easy, using the {\vcode vmime::messageBuilder}
object. The following code constructs a message containing text in both plain
@@ -295,12 +297,13 @@ mb.constructTextPart(vmime::mediaType
vmime::ref <vmime::htmlTextPart> textPart =
mb.getTextPart().dynamicCast <vmime::htmlTextPart>();
-// -- add the JPEG image (the returned identifier is used to identify the
-// -- embedded object in the HTML text, the famous "CID", or "Content-Id")
-vmime::string id = textPart->addObject("<...image data...>",
+// -- Add the JPEG image (the returned identifier is used to identify the
+// -- embedded object in the HTML text, the famous "CID", or "Content-Id").
+// -- Note: you can also read data from a file; see the next example.
+const vmime::string id = textPart->addObject("<...image data...>",
vmime::mediaType(vmime::mediaTypes::IMAGE, vmime::mediaTypes::IMAGE_JPEG));
-// -- set the text
+// -- Set the text
textPart->setCharset(vmime::charsets::ISO8859_15);
textPart->setText(vmime::create <vmime::stringContentHandler>
@@ -321,6 +324,25 @@ multipart/alternative
image/jpeg
\end{verbatim}
+You can easily tell VMime to read the embedded object data from a file. The
+following code opens the file \emph{/path/to/image.jpg}, connects it to an
+input stream, then add an embedded object:
+
+\begin{lstlisting}
+vmime::utility::fileSystemFactory* fs =
+ vmime::platform::getHandler()->getFileSystemFactory();
+
+vmime::ref <vmime::utility::file> imageFile =
+ fs->create(fs->stringToPath("/path/to/image.jpg"));
+
+vmime::ref <vmime::contentHandler> imageCts =
+ vmime::create <vmime::streamContentHandler>
+ (imageFile->getFileReader()->getInputStream(), imageFile->getLength());
+
+const vmime::string cid = textPart.addObject(imageCts,
+ vmime::mediaType(vmime::mediaTypes::IMAGE, vmime::mediaTypes::IMAGE_JPEG));
+\end{lstlisting}
+
% ============================================================================
\section{Working with attachments: the attachment helper}
diff --git a/examples/example3.cpp b/examples/example3.cpp
index 3b9d2d26..bc9aa4a0 100644
--- a/examples/example3.cpp
+++ b/examples/example3.cpp
@@ -73,8 +73,21 @@ int main()
// -- embed an image (the returned "CID" (content identifier) is used to reference
// -- the image into HTML content).
- vmime::string cid = textPart.addObject("<...IMAGE DATA...>",
- vmime::mediaType(vmime::mediaTypes::IMAGE, vmime::mediaTypes::IMAGE_JPEG));
+ vmime::utility::fileSystemFactory* fs =
+ vmime::platform::getHandler()->getFileSystemFactory();
+
+ vmime::ref <vmime::utility::file> imageFile =
+ fs->create(fs->stringToPath("/path/to/image.jpg"));
+
+ vmime::ref <vmime::utility::fileReader> fileReader =
+ imageFile->getFileReader();
+
+ vmime::ref <vmime::contentHandler> imageCts =
+ vmime::create <vmime::streamContentHandler>
+ (fileReader->getInputStream(), imageFile->getLength());
+
+ const vmime::string cid = textPart.addObject(imageCts,
+ vmime::mediaType(vmime::mediaTypes::IMAGE, vmime::mediaTypes::IMAGE_JPEG));
// -- message text
textPart.setText(vmime::create <vmime::stringContentHandler>