aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2018-09-05 21:54:48 +0000
committerVincent Richard <[email protected]>2018-09-05 21:54:48 +0000
commitb55bdc9c0bb68236aa2de0a8eaec9f4c80cc2769 (patch)
treeefa18d623d3bc67c41d643aae145c16aa8f1006d /doc
parentMerge pull request #198 from xguerin/master (diff)
downloadvmime-b55bdc9c0bb68236aa2de0a8eaec9f4c80cc2769.tar.gz
vmime-b55bdc9c0bb68236aa2de0a8eaec9f4c80cc2769.zip
Code style and clarity.
Diffstat (limited to 'doc')
-rw-r--r--doc/book/basics.tex95
-rw-r--r--doc/book/intro.tex4
-rw-r--r--doc/book/msg.tex133
-rw-r--r--doc/book/net.tex144
-rw-r--r--doc/book/start.tex4
5 files changed, 209 insertions, 171 deletions
diff --git a/doc/book/basics.tex b/doc/book/basics.tex
index 6dbbff04..94633efd 100644
--- a/doc/book/basics.tex
+++ b/doc/book/basics.tex
@@ -46,17 +46,17 @@ use the function {\vcode vmime::make\_shared} instead of the {\vcode new}
operator.
\begin{lstlisting}[caption={Smarts pointers and creating objects}]
-class myObject : public vmime::object
-{
+class myObject : public vmime::object {
+
public:
myObject(const vmime::string& name)
- : m_name(name)
- {
+ : m_name(name) {
+
}
- void sayHello()
- {
+ void sayHello() {
+
std::cout << "Hello " << m_name << std::endl;
}
@@ -65,8 +65,8 @@ private:
vmime::string m_name;
};
-int main()
-{
+int main() {
+
vmime::shared_ptr <myObject> obj =
vmime::make_shared <myObject>("world");
@@ -105,12 +105,12 @@ directly or indirectly to itself). The following example illustrates a
typical problem of reference counting:
\begin{lstlisting}
-class parent : public vmime::object
-{
+class parent : public vmime::object {
+
public:
- void createChild(vmime::shared_ptr <child> c)
- {
+ void createChild(vmime::shared_ptr <child> c) {
+
m_child = c;
}
@@ -119,13 +119,13 @@ private:
vmime::shared_ptr <child> m_child;
};
-class child : public vmime::object
-{
+class child : public vmime::object {
+
public:
child(vmime::shared_ptr <parent> p)
- : m_parent(p)
- {
+ : m_parent(p) {
+
}
private:
@@ -133,8 +133,8 @@ private:
vmime::shared_ptr <parent> m_parent;
};
-int main()
-{
+int main() {
+
vmime::shared_ptr <parent> p = vmime::make_shared <parent>();
vmime::shared_ptr <child> c = vmime::make_shared <child>();
@@ -179,30 +179,31 @@ Following is an example code for catching VMime exceptions and writing error
messages to the console:
\begin{lstlisting}[caption={Catching VMime exceptions}]
-std::ostream& operator<<(std::ostream& os, const vmime::exception& e)
-{
+std::ostream& operator<<(std::ostream& os, const vmime::exception& e) {
+
os << "* vmime::exceptions::" << e.name() << std::endl;
os << " what = " << e.what() << std::endl;
// Recursively print all encapsuled exceptions
- if (e.other() != NULL)
+ if (e.other() != NULL) {
os << *e.other();
+ }
return os;
}
...
-try
-{
+try {
+
// ...some call to VMime...
-}
-catch (vmime::exception& e)
-{
+
+} catch (vmime::exception& e) {
+
std::cerr << e; // VMime exception
-}
-catch (std::exception& e)
-{
+
+} catch (std::exception& e) {
+
std::cerr << e.what(); // standard exception
}
\end{lstlisting}
@@ -250,7 +251,8 @@ vmime::datetime d1("Sat, 08 Oct 2005 14:07:52 +0200");
vmime::datetime d2(
/* date */ 2005, vmime::datetime::OCTOBER, 8,
/* time */ 14, 7, 52,
- /* zone */ vmime::datetime::GMT2);
+ /* zone */ vmime::datetime::GMT2
+);
// Getting day of week
const int dow = d2.getWeekDay(); // 'dow' should be datetime::SATURDAY
@@ -275,7 +277,8 @@ media type with:
\begin{lstlisting}
vmime::mediaType theType(
/* top-level type */ vmime::mediaTypes::IMAGE,
- /* sub-type */ vmime::mediaTypes::IMAGE_JPEG);
+ /* sub-type */ vmime::mediaTypes::IMAGE_JPEG
+);
// theType.getType() is "image"
// theType.getSubType() is "jpeg"
@@ -594,8 +597,9 @@ std::ifstream* fileStream = new std::ifstream();
fileStream->open("/home/vincent/paris.jpg", std::ios::binary);
-if (!*fileStream)
+if (!*fileStream) {
// handle error
+}
vmime::shared_ptr <utility::stream> dataStream =
vmime::make_shared <vmime::utility::inputStreamPointerAdapter>(fileStream);
@@ -608,13 +612,12 @@ vmime::shared_ptr <contentHandler> data =
vmime::make_shared <vmime::streamContentHandler>(dataStream, 0);
// Now create the attachment
-ref <vmime::attachment> att = vmime::make_shared <vmime::defaultAttachment>
- (
- /* attachment data */ data,
- /* content type */ vmime::mediaType("image/jpeg"),
- /* description */ vmime::text("Holiday photo"),
- /* filename */ vmime::word("paris.jpg")
- );
+ref <vmime::attachment> att = vmime::make_shared <vmime::defaultAttachment>(
+ /* attachment data */ data,
+ /* content type */ vmime::mediaType("image/jpeg"),
+ /* description */ vmime::text("Holiday photo"),
+ /* filename */ vmime::word("paris.jpg")
+);
\end{lstlisting}
You will see later that the {\vcode vmime::fileAttachment} class already
@@ -647,10 +650,11 @@ vmime::shared_ptr <const vmime::contentHandler> cth = body->getContents();
// Then, extract and convert the contents
vmime::utility::outputStreamAdapter out(std::cout);
-vmime::utility::charsetFilteredOutputStream fout
- (/* source charset */ body->getCharset(),
+vmime::utility::charsetFilteredOutputStream fout(
+ /* source charset */ body->getCharset(),
/* dest charset */ vmime::charset("utf-8"),
- /* dest stream */ out);
+ /* dest stream */ out
+);
cth->extract(fout);
@@ -778,8 +782,8 @@ vmime::shared_ptr <vmime::utility::encoder::encoderFactory> ef =
std::cout << "Available encoders:" << std::endl;
-for (int i = 0 ; i < ef->getEncoderCount() ; ++i)
-{
+for (int i = 0 ; i < ef->getEncoderCount() ; ++i) {
+
// Output encoder name
vmime::shared_ptr <const vmime::utility::encoder::encoderFactory::registeredEncoder>
enc = ef->getEncoderAt(i);
@@ -792,8 +796,9 @@ for (int i = 0 ; i < ef->getEncoderCount() ; ++i)
std::vector <vmime::string> props = e->getAvailableProperties();
std::vector <vmime::string>::const_iterator it;
- for (it = props.begin() ; it != props.end() ; ++it)
+ for (it = props.begin() ; it != props.end() ; ++it) {
std::cout << " - " << *it << std::endl;
+ }
\end{lstlisting}
diff --git a/doc/book/intro.tex b/doc/book/intro.tex
index 4fa172e9..fe7bcf51 100644
--- a/doc/book/intro.tex
+++ b/doc/book/intro.tex
@@ -55,7 +55,7 @@ General Public License\footnote{See Appendix \ref{appendix_license} and
\url{http://www.gnu.org/copyleft/gpl.html}} (GPL) version 3:
\begin{verbatim}
- Copyright (C) 2002-2013 Vincent Richard
+ Copyright (C) 2002 Vincent Richard
VMime library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -79,7 +79,7 @@ GNU Free Documentation
License\footnote{See \url{http://www.gnu.org/copyleft/fdl.html}} (FDL):
\begin{verbatim}
- Copyright (C) 2004-2013 Vincent Richard
+ Copyright (C) 2004 Vincent Richard
Permission is granted to copy, distribute and/or modify
this document under the terms of the GNU Free Documentation
diff --git a/doc/book/msg.tex b/doc/book/msg.tex
index 50344b62..ce9d8a80 100644
--- a/doc/book/msg.tex
+++ b/doc/book/msg.tex
@@ -94,8 +94,8 @@ vmime::messageParser mp(msg);
std::cout << "Message has " << mp.getAttachmentCount()
<< " attachment(s)" << std::endl;
-for (int i = 0 ; i < mp.getAttachmentCount() ; ++i)
-{
+for (int i = 0 ; i < mp.getAttachmentCount() ; ++i) {
+
vmime::shared_ptr <const vmime::attachment> att = mp.getAttachmentAt(i);
std::cout << " - " << att->getType().generate() << std::endl;
}
@@ -104,13 +104,13 @@ for (int i = 0 ; i < mp.getAttachmentCount() ; ++i)
std::cout << "Message has " << mp.getTextPartCount()
<< " text part(s)" << std::endl;
-for (int i = 0 ; i < mp.getTextPartCount() ; ++i)
-{
+for (int i = 0 ; i < mp.getTextPartCount() ; ++i) {
+
vmime::shared_ptr <const vmime::textPart> tp = mp.getTextPartAt(i);
// text/html
- if (tp->getType().getSubType() == vmime::mediaTypes::TEXT_HTML)
- {
+ if (tp->getType().getSubType() == vmime::mediaTypes::TEXT_HTML) {
+
vmime::shared_ptr <const vmime::htmlTextPart> htp =
vmime::dynamicCast <const vmime::htmlTextPart>(tp);
@@ -118,18 +118,18 @@ for (int i = 0 ; i < mp.getTextPartCount() ; ++i)
// Plain text is in tp->getPlainText()
// Enumerate embedded objects
- for (int j = 0 ; j < htp->getObjectCount() ; ++j)
- {
+ for (int j = 0 ; j < htp->getObjectCount() ; ++j) {
+
vmime::shared_ptr <const vmime::htmlTextPart::embeddedObject> obj =
htp->getObjectAt(j);
// Identifier (Content-Id or Content-Location) is obj->getId()
// Object data is in obj->getData()
}
- }
+
// text/plain or anything else
- else
- {
+ } else {
+
// Text is in tp->getText()
}
}
@@ -172,8 +172,7 @@ hdr->appendField(subjectField);
vmime::shared_ptr <vmime::headerField> fromField =
hfFactory->create(vmime::fields::FROM);
-fromField->setValue
- (vmime::make_shared <vmime::mailbox>("[email protected]"));
+fromField->setValue(vmime::make_shared <vmime::mailbox>("[email protected]"));
hdr->appendField(fromField);
// Append a 'To:' field
@@ -190,8 +189,11 @@ toField->setValue(recipients);
hdr->appendField(toField);
// Set the body contents
-bdy->setContents(vmime::make_shared <vmime::stringContentHandler>
- ("This is the text of your message..."));
+bdy->setContents(
+ vmime::make_shared <vmime::stringContentHandler>(
+ "This is the text of your message..."
+ )
+);
// Output raw message data to standard output
vmime::utility::outputStreamAdapter out(std::cout);
@@ -207,19 +209,23 @@ previous example, using the {\vcode vmime::messageBuilder} object:
\begin{lstlisting}[caption={Building a simple message
using {\vcode vmime::messageBuilder}}]
-try
-{
+try {
+
vmime::messageBuilder mb;
// Fill in some header fields and message body
mb.setSubject(vmime::text("Message subject"));
mb.setExpeditor(vmime::mailbox("[email protected]"));
- mb.getRecipients().appendAddress
- (vmime::make_shared <vmime::mailbox>("[email protected]"));
+ mb.getRecipients().appendAddress(
+ vmime::make_shared <vmime::mailbox>("[email protected]")
+ );
mb.getTextPart()->setCharset(vmime::charsets::ISO8859_15);
- mb.getTextPart()->setText(vmime::make_shared <vmime::stringContentHandler>
- ("This is the text of your message..."));
+ mb.getTextPart()->setText(
+ vmime::make_shared <vmime::stringContentHandler>(
+ "This is the text of your message..."
+ )
+ );
// Message construction
vmime::shared_ptr <vmime::message> msg = mb.construct();
@@ -227,15 +233,15 @@ try
// Output raw message data to standard output
vmime::utility::outputStreamAdapter out(std::cout);
msg->generate(out);
-}
+
// VMime exception
-catch (vmime::exception& e)
-{
+} catch (vmime::exception& e) {
+
std::cerr << "vmime::exception: " << e.what() << std::endl;
-}
+
// Standard exception
-catch (std::exception& e)
-{
+} catch (std::exception& e) {
+
std::cerr << "std::exception: " << e.what() << std::endl;
}
\end{lstlisting}
@@ -250,17 +256,17 @@ previous example to attach a file to the message:
{\vcode vmime::messageBuilder}}]
// Create an attachment
vmime::shared_ptr <vmime::fileAttachment> att =
- vmime::make_shared <vmime::fileAttachment>
- (
- /* full path to file */ "/home/vincent/paris.jpg",
- /* content type */ vmime::mediaType("image/jpeg),
- /* description */ vmime::text("My holidays in Paris")
+ vmime::make_shared <vmime::fileAttachment>(
+ /* full path to file */ "/home/vincent/paris.jpg",
+ /* content type */ vmime::mediaType("image/jpeg),
+ /* description */ vmime::text("My holidays in Paris")
);
// You can also set some infos about the file
att->getFileInfo().setFilename("paris.jpg");
-att->getFileInfo().setCreationDate
- (vmime::datetime("30 Apr 2003 14:30:00 +0200"));
+att->getFileInfo().setCreationDate(
+ vmime::datetime("30 Apr 2003 14:30:00 +0200")
+);
// Add this attachment to the message
mb.appendAttachment(att);
@@ -283,14 +289,19 @@ using the {\vcode vmime::messageBuilder}}]
// Fill in some header fields
mb.setSubject(vmime::text("An HTML message"));
mb.setExpeditor(vmime::mailbox("[email protected]"));
-mb.getRecipients().appendAddress
- (vmime::make_shared <vmime::mailbox>("[email protected]"));
+mb.getRecipients().appendAddress(
+ vmime::make_shared <vmime::mailbox>("[email protected]")
+);
// Set the content-type to "text/html": a text part factory must be
// available for the type you are using. The following code will make
// the message builder construct the two text parts.
-mb.constructTextPart(vmime::mediaType
- (vmime::mediaTypes::TEXT, vmime::mediaTypes::TEXT_HTML));
+mb.constructTextPart(
+ vmime::mediaType(
+ vmime::mediaTypes::TEXT,
+ vmime::mediaTypes::TEXT_HTML
+ )
+);
// Set contents of the text parts; the message is available in two formats:
// HTML and plain text. The HTML format also includes an embedded image.
@@ -306,12 +317,18 @@ const vmime::string id = textPart->addObject("<...image data...>",
// -- Set the text
textPart->setCharset(vmime::charsets::ISO8859_15);
-textPart->setText(vmime::make_shared <vmime::stringContentHandler>
- ("This is the <b>HTML text</b>, and the image:<br/>"
- "<img src=\"") + id + vmime::string("\"/>"));
-
-textPart->setPlainText(vmime::make_shared <vmime::stringContentHandler>
- ("This is the plain text."));
+textPart->setText(
+ vmime::make_shared <vmime::stringContentHandler>(
+ "This is the <b>HTML text</b>, and the image:<br/>"
+ "<img src=\"") + id + vmime::string("\"/>"
+ )
+);
+
+textPart->setPlainText(
+ vmime::make_shared <vmime::stringContentHandler>(
+ "This is the plain text."
+ )
+);
\end{lstlisting}
This will create a message having the following structure:
@@ -336,11 +353,18 @@ vmime::shared_ptr <vmime::utility::file> imageFile =
fs->create(fs->stringToPath("/path/to/image.jpg"));
vmime::shared_ptr <vmime::contentHandler> imageCts =
- vmime::make_shared <vmime::streamContentHandler>
- (imageFile->getFileReader()->getInputStream(), imageFile->getLength());
+ vmime::make_shared <vmime::streamContentHandler>(
+ imageFile->getFileReader()->getInputStream(),
+ imageFile->getLength()
+ );
-const vmime::string cid = textPart.addObject(imageCts,
- vmime::mediaType(vmime::mediaTypes::IMAGE, vmime::mediaTypes::IMAGE_JPEG));
+const vmime::string cid = textPart.addObject(
+ imageCts,
+ vmime::mediaType(
+ vmime::mediaTypes::IMAGE,
+ vmime::mediaTypes::IMAGE_JPEG
+ )
+);
\end{lstlisting}
@@ -361,8 +385,8 @@ extract its contents to the standard output:
\begin{lstlisting}[caption={Testing if a body part is an attachment}]
vmime::shared_ptr <vmime::bodyPart> part; // suppose we have a body part
-if (vmime::attachmentHelper::isBodyPartAnAttachment(part))
-{
+if (vmime::attachmentHelper::isBodyPartAnAttachment(part)) {
+
// The body part contains an attachment, get it
vmime::shared_ptr <const vmime::attachment> attach =
attachmentHelper::getBodyPartAttachment(part);
@@ -394,11 +418,10 @@ vmime::shared_ptr <vmime::message> msg; // suppose we have a message
// Create an attachment
vmime::shared_ptr <vmime::fileAttachment> att =
- vmime::make_shared <vmime::fileAttachment>
- (
- /* full path to file */ "/home/vincent/paris.jpg",
- /* content type */ vmime::mediaType("image/jpeg),
- /* description */ vmime::text("My holidays in Paris")
+ vmime::make_shared <vmime::fileAttachment>(
+ /* full path to file */ "/home/vincent/paris.jpg",
+ /* content type */ vmime::mediaType("image/jpeg),
+ /* description */ vmime::text("My holidays in Paris")
);
// Attach it to the message
diff --git a/doc/book/net.tex b/doc/book/net.tex
index 301e3f11..3fab903a 100644
--- a/doc/book/net.tex
+++ b/doc/book/net.tex
@@ -300,10 +300,10 @@ The following example shows how to use a custom authenticator to request
the user to enter her/his credentials:
\begin{lstlisting}[caption={A simple interactive authenticator}]
-class myAuthenticator : public vmime::security::defaultAuthenticator
-{
- const string getUsername() const
- {
+class myAuthenticator : public vmime::security::defaultAuthenticator {
+
+ const string getUsername() const {
+
std::cout << "Enter your username: " << std::endl;
vmime::string res;
@@ -312,8 +312,8 @@ class myAuthenticator : public vmime::security::defaultAuthenticator
return res;
}
- const string getPassword() const
- {
+ const string getPassword() const {
+
std::cout << "Enter your password: " << std::endl;
vmime::string res;
@@ -331,9 +331,10 @@ This is how to use it:
vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create();
// Next, initialize a service which will use our authenticator
-vmime::shared_ptr <vmime::net::store> st =
- sess->getStore(vmime::utility::url("imap://imap.example.com"),
- /* use our authenticator */ vmime::make_shared <myAuthenticator>());
+vmime::shared_ptr <vmime::net::store> st = sess->getStore(
+ vmime::utility::url("imap://imap.example.com"),
+ /* use our authenticator */ vmime::make_shared <myAuthenticator>()
+);
\end{lstlisting}
\vnote{An authenticator object should be used with one and only one service
@@ -354,14 +355,15 @@ use the SASL-specific methods {\vcode getAcceptableMechanisms()} and
implementation of an SASL authenticator.
\begin{lstlisting}[caption={A simple SASL authenticator}]
-class mySASLAuthenticator : public vmime::security::sasl::defaultSASLAuthenticator
-{
+class mySASLAuthenticator : public vmime::security::sasl::defaultSASLAuthenticator {
+
typedef vmime::security::sasl::SASLMechanism mechanism; // save us typing
- const std::vector <vmime::shared_ptr <mechanism> > getAcceptableMechanisms
- (const std::vector <vmime::shared_ptr <mechanism> >& available,
- const vmime::shared_ptr <mechanism>& suggested) const
- {
+ const std::vector <vmime::shared_ptr <mechanism> > getAcceptableMechanisms(
+ const std::vector <vmime::shared_ptr <mechanism> >& available,
+ const vmime::shared_ptr <mechanism>& suggested
+ ) const {
+
// Here, you can sort the SASL mechanisms in the order they will be
// tried. If no SASL mechanism is acceptable (ie. for example, not
// enough secure), you can return an empty list.
@@ -372,8 +374,8 @@ class mySASLAuthenticator : public vmime::security::sasl::defaultSASLAuthenticat
getAcceptableMechanisms(available, suggested);
}
- void setSASLMechanism(const vmime::shared_ptr <mechanism>& mech)
- {
+ void setSASLMechanism(const vmime::shared_ptr <mechanism>& mech) {
+
// This is called when the authentication process is going to
// try the specified mechanism.
//
@@ -435,7 +437,8 @@ tr->send(
/* expeditor */ from,
/* recipient(s) */ to,
/* data */ is,
- /* total length */ msgData.length());
+ /* total length */ msgData.length()
+);
// We have finished using the service
tr->disconnect();
@@ -556,22 +559,26 @@ std::vector <ref <vmime::net::message> > allMessages =
folder->getMessages(vmime::net::messageSet::byNumber(1, -1));
// -1 is a special value to mean "the number of the last message in the folder"
-folder->fetchMessages(allMessages,
+folder->fetchMessages(
+ allMessages,
vmime::net::fetchAttributes::FLAGS |
- vmime::net::fetchAttributes::ENVELOPE);
+ vmime::net::fetchAttributes::ENVELOPE
+);
+
+for (unsigned int i = 0 ; i < allMessages.size() ; ++i) {
-for (unsigned int i = 0 ; i < allMessages.size() ; ++i)
-{
vmime::shared_ptr <vmime::net::message> msg = allMessages[i];
const int flags = msg->getFlags();
std::cout << "Message " << i << ":" << std::endl;
- if (flags & vmime::net::message::FLAG_SEEN)
+ if (flags & vmime::net::message::FLAG_SEEN) {
std::cout << " - is read" << std::endl;
- if (flags & vmime::net::message::FLAG_DELETED)
+ }
+ if (flags & vmime::net::message::FLAG_DELETED) {
std::cout << " - is deleted" << std::endl;
+ }
vmime::shared_ptr <const vmime::header> hdr = msg->getHeader();
@@ -698,8 +705,8 @@ running.
An interface called {\vcode timeoutHandler} is provided:
\begin{lstlisting}
-class timeoutHandler : public object
-{
+class timeoutHandler : public object {
+
/** Called to test if the time limit has been reached.
*
* @return true if the timeout delay is elapsed
@@ -738,27 +745,27 @@ is thrown.
The following example shows how to implement a simple timeout handler:
\begin{lstlisting}[caption={Implementing a simple timeout handler}]
-class myTimeoutHandler : public vmime::net::timeoutHandler
-{
+class myTimeoutHandler : public vmime::net::timeoutHandler {
+
public:
- myTimeoutHandler()
- {
+ myTimeoutHandler() {
+
m_startTime = time(NULL);
}
- const bool isTimeOut()
- {
- return (time(NULL) >= m_startTime + 30); // 30 seconds timeout
+ const bool isTimeOut() {
+
+ return time(NULL) >= m_startTime + 30; // 30 seconds timeout
}
- void resetTimeOut()
- {
+ void resetTimeOut() {
+
m_startTime = time(NULL);
}
- const bool handleTimeOut()
- {
+ const bool handleTimeOut() {
+
std::cout << "Operation timed out." << std::endl;
<< "Press [Y] to continue, or [N] to "
<< "cancel the operation." << std::endl;
@@ -766,7 +773,7 @@ public:
std::string response;
std::cin >> response;
- return (response == "y" || response == "Y");
+ return response == "y" || response == "Y";
}
private:
@@ -781,12 +788,12 @@ is required because the service can use several connections to the server
simultaneously, and each connection needs its own timeout handler.
\begin{lstlisting}
-class myTimeoutHandlerFactory : public vmime::net::timeoutHandlerFactory
-{
+class myTimeoutHandlerFactory : public vmime::net::timeoutHandlerFactory {
+
public:
- ref <timeoutHandler> create()
- {
+ ref <timeoutHandler> create() {
+
return vmime::make_shared <myTimeoutHandler>();
}
};
@@ -918,13 +925,12 @@ First, we need some code to load existing X.509 certificates:
\begin{lstlisting}[caption={Reading a X.509 certificate from a file}]
vmime::shared_ptr <vmime::security::cert::X509Certificate>
- loadX509CertificateFromFile(const std::string& path)
-{
+ loadX509CertificateFromFile(const std::string& path) {
+
std::ifstream certFile;
certFile.open(path.c_str(), std::ios::in | std::ios::binary);
- if (!certFile)
- {
+ if (!certFile) {
// ...handle error...
}
@@ -978,12 +984,12 @@ use this in a production application as this is obviously a serious security
issue):
\begin{lstlisting}[caption={A custom certificate verifier}]
-class myCertVerifier : public vmime::security::cert::certificateVerifier
-{
+class myCertVerifier : public vmime::security::cert::certificateVerifier {
+
public:
- void verify(const vmime::shared_ptr <certificateChain>& certs)
- {
+ void verify(const vmime::shared_ptr <certificateChain>& certs) {
+
// Obtain the subject's certificate
vmime::shared_ptr <vmime::security::cert::certificate> cert = chain->getAt(0);
@@ -996,8 +1002,9 @@ public:
std::string answer;
std::getline(std::cin, answer);
- if (answer.length() != 0 && (answer[0] == 'Y' || answer[0] == 'y'))
+ if (answer.length() != 0 && (answer[0] == 'Y' || answer[0] == 'y')) {
return; // OK, we trust the certificate
+ }
// Don't trust this certificate
throw vmime::security::cert::certificateException();
@@ -1092,25 +1099,26 @@ First, you have to create your own tracer, which must implement the
simply logs to the standard output:
\begin{lstlisting}[caption={A simple tracer}]
-class myTracer : public vmime::net::tracer
-{
+class myTracer : public vmime::net::tracer {
+
public:
myTracer(const vmime::string& proto, const int connectionId)
- : m_proto(proto), m_connectionId(connectionId)
- {
+ : m_proto(proto),
+ m_connectionId(connectionId) {
+
}
// Called by VMime to trace what is sent on the socket
- void traceSend(const vmime::string& line)
- {
+ void traceSend(const vmime::string& line) {
+
std::cout << "[" << m_proto << ":" << m_connectionId
<< "] C: " << line << std::endl;
}
// Called by VMime to trace what is received from the socket
- void traceReceive(const vmime::string& line)
- {
+ void traceReceive(const vmime::string& line) {
+
std::cout << "[" < < m_proto << ":" << m_connectionId
<< "] S: " << line << std::endl;
}
@@ -1125,16 +1133,18 @@ private:
Also create a factory class, used to instanciate your tracer objects:
\begin{lstlisting}
-class myTracerFactory : public vmime::net::tracerFactory
-{
+class myTracerFactory : public vmime::net::tracerFactory {
+
public:
- vmime::shared_ptr <vmime::net::tracer> create
- (const vmime::shared_ptr <vmime::net::service>& serv,
- const int connectionId)
- {
- return vmime::make_shared <myTracer>
- (serv->getProtocolName(), connectionId);
+ vmime::shared_ptr <vmime::net::tracer> create(
+ const vmime::shared_ptr <vmime::net::service>& serv,
+ const int connectionId
+ ) {
+
+ return vmime::make_shared <myTracer>(
+ serv->getProtocolName(), connectionId
+ );
}
};
\end{lstlisting}
diff --git a/doc/book/start.tex b/doc/book/start.tex
index 74084941..f1693301 100644
--- a/doc/book/start.tex
+++ b/doc/book/start.tex
@@ -82,8 +82,8 @@ So, if your platform is POSIX, your program should look like this:
#include <vmime/vmime.hpp>
#include <vmime/platforms/posix/posixHandler.hpp>
-int main()
-{
+int main() {
+
vmime::platform::
setHandler <vmime::platforms::posix::posixHandler>();