<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"/> <title>mail::folder::addMessage</title> <link rel="stylesheet" href="manpage.css" type="text/css"/> <link rel="start" href="index.html" title="Cone: COnsole Newsreader And Emailer"/> <link rel="up" href="libmail-folder.html" title="mail::folder Native API reference"/> <link rel="prev" href="libmail-folder.html" title="mail::folder Native API reference"/> <link rel="next" href="folder-clone.html" title="mail::folder::clone"/> <link xmlns="" rel="icon" href="icon.gif" type="image/gif"/> <meta xmlns="" name="MSSmartTagsPreventParsing" content="TRUE"/> <!-- Copyright 2002 - 2007 Double Precision, Inc. See COPYING for distribution information. --> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center" rowspan="1"> mail::folder::addMessage</th> </tr> <tr> <td width="20%" align="left" rowspan="1" colspan="1"> <a accesskey="p" href="libmail-folder.html" shape="rect">Prev</a> </td> <th width="60%" align="center" rowspan="1" colspan="1"> <span class="structname">mail::folder</span> Native API reference</th> <td width="20%" align="right" rowspan="1" colspan="1">  <a accesskey="n" href="folder-clone.html" shape="rect">Next</a></td> </tr> </table> <hr/> </div> <div class="refentry" lang="en" xml:lang="en"> <a id="folder-addmessage" shape="rect" name="folder-addmessage"> </a> <div class="titlepage"/> <div class="refnamediv"> <h2>Name</h2> <p>mail::folder::addMessage — Add a message to a folder</p> </div> <div class="refsynopsisdiv"> <h2>Synopsis</h2> <div class="literallayout"> <p><br clear="none"/> <br clear="none"/> <br clear="none"/> <br clear="none"/> #include <libmail/mail.H><br clear="none"/> <br clear="none"/> <br clear="none"/> class myCallback : public mail::callback {<br clear="none"/> public:<br clear="none"/>     void success(std::string msg);<br clear="none"/>     void fail(std::string msg);<br clear="none"/> };<br clear="none"/></p> </div> <div class="literallayout"> <p><br clear="none"/> #include <libmail/addmessage.H><br clear="none"/> <br clear="none"/> mail::folder *folder;<br clear="none"/> time_t messageDate;<br clear="none"/> mail::messageInfo newMessageInfo;<br clear="none"/> std::string messageBody;<br clear="none"/></p> </div> <div class="funcsynopsis"> <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"> <tr> <td rowspan="1" colspan="1"><code class="funcdef">mail::addMessage *msg=folder-><b class="fsfunc">addMessage</b>(</code></td> <td rowspan="1" colspan="1">myCallback & </td> <td rowspan="1" colspan="1"><var class="pdparam">callback</var><code>)</code>;</td> </tr> </table> </div> <div class="literallayout"> <p><br clear="none"/> msg->messageDate=messageDate;<br clear="none"/> msg->messageInfo=messageInfo;<br clear="none"/> msg->saveMessageContents(messageBody);<br clear="none"/> <br clear="none"/> if (changedMyMind)<br clear="none"/>     msg->fail(std::string errmsg);<br clear="none"/> else<br clear="none"/>     msg->go();<br clear="none"/></p> </div> </div> <div class="refsect1" lang="en" xml:lang="en"> <a id="id614936" shape="rect" name="id614936"> </a> <h2>USAGE</h2> <p>This method begins the process of manually adding a message to a folder. The <code class="function">mail::folder::addMessage</code> method returns a pointer to a <span class="structname">mail::addMessage</span> object. The application should then define the contents of the message by invoking the object's <code class="function">saveMessageContents</code> method. The entire contents of the message does not have to be specified at once. A large message may be defined by repeatedly invoking <code class="function">saveMessageContents</code>, consecutively, each time specifying the next portion of the message's contents.</p> <p>After the contents of the message are defined by invoking <code class="function">saveMessageContents</code>, the application must invoke the <code class="function">go</code> method in order to actually place the new message into the folder. The application may abort the process at any time by invoking the <code class="function">fail</code> method, and specifying the error message.</p> <p>The application does not need to explicitly destroy the <span class="structname">mail::addMessage</span> object, the object is automatically destroyed by <code class="function">go</code> or <code class="function">fail</code>.</p> <p>The application may set the following <span class="structname">mail::addMessage</span> fields prior to invoking <code class="function">go</code>. If not initialized, the following fields will be set to their default values.</p> <div class="variablelist"> <dl> <dt><span class="term">messageDate</span></dt> <dd> <p>The message's timestamp, as retrieved by <code class="literal">mail::account::ARRIVALDATE</code> parameter to <a class="link" href="mail-readmsgattr.html" title="mail::account::readMessageAttributes" shape="rect"><span class="citerefentry"><span class="refentrytitle">mail::account::readMessageAttributes</span>(3x)</span></a>().</p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p>This timestamp does not necessarily have to be the same as the timestamp in the message's <code class="literal">Date:</code> header.</p> </div> </dd> <dt><span class="term">messageInfo</span></dt> <dd> <p>The message flags, as returned by <a class="link" href="mail-getfolderindexinfo.html" title="mail::account::getFolderIndexInfo" shape="rect"><span class="citerefentry"><span class="refentrytitle">mail::account::getFolderIndexInfo</span>(3x)</span></a>().</p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p>The contents of <em class="structfield"><code>uid</code></em>, the message's unique ID, are ignored, only the message flags in <em class="structfield"><code>messageInfo</code></em> are read. The message gets automatically assigned a new unique ID when it gets added to the folder.</p> </div> </dd> </dl> </div> </div> <div class="refsect1" lang="en" xml:lang="en"> <a id="id615118" shape="rect" name="id615118"> </a> <h2>MIME-BASED MESSAGE COMPOSITION</h2> <div class="literallayout"> <p><br clear="none"/> <br clear="none"/> <br clear="none"/> <br clear="none"/> #include <libmail/mail.H><br clear="none"/> <br clear="none"/> <br clear="none"/> class myCallback : public mail::callback {<br clear="none"/> public:<br clear="none"/>     void success(std::string msg);<br clear="none"/>     void fail(std::string msg);<br clear="none"/> };<br clear="none"/></p> </div> <div class="funcsynopsis"> <pre class="funcsynopsisinfo" xml:space="preserve"> mail::addMessage *msg; </pre> <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"> <tr> <td rowspan="1" colspan="1"><code class="funcdef">msg-><b class="fsfunc">assembleContent</b>(</code></td> <td rowspan="1" colspan="1">size_t & </td> <td rowspan="1" colspan="1"><var class="pdparam">handleRet</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">const mail::Attachment & </td> <td rowspan="1" colspan="1"><var class="pdparam">attachment</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">mail::callback & </td> <td rowspan="1" colspan="1"><var class="pdparam">cb</var><code>)</code>;</td> </tr> </table> <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"> <tr> <td rowspan="1" colspan="1"><code class="funcdef">msg-><b class="fsfunc">assembleMessageRfc822</b>(</code></td> <td rowspan="1" colspan="1">size_t & </td> <td rowspan="1" colspan="1"><var class="pdparam">handleRet</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">std::string  </td> <td rowspan="1" colspan="1"><var class="pdparam">headers</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">size_t  </td> <td rowspan="1" colspan="1"><var class="pdparam">handle</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">mail::callback & </td> <td rowspan="1" colspan="1"><var class="pdparam">cb</var><code>)</code>;</td> </tr> </table> <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"> <tr> <td rowspan="1" colspan="1"><code class="funcdef">msg-><b class="fsfunc">assembleMultipart</b>(</code></td> <td rowspan="1" colspan="1">size_t & </td> <td rowspan="1" colspan="1"><var class="pdparam">handleRet</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">std::string  </td> <td rowspan="1" colspan="1"><var class="pdparam">headers</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">const std::vector<size_t>  </td> <td rowspan="1" colspan="1"><var class="pdparam">parts</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">std::string  </td> <td rowspan="1" colspan="1"><var class="pdparam">multipart_type</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">const mail::mimestruct::parameterList & </td> <td rowspan="1" colspan="1"><var class="pdparam">options</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">mail::callback & </td> <td rowspan="1" colspan="1"><var class="pdparam">cb</var><code>)</code>;</td> </tr> </table> <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"> <tr> <td rowspan="1" colspan="1"><code class="funcdef">bool flag=msg-><b class="fsfunc">assemble</b>(</code></td> <td rowspan="1" colspan="1"><code>void)</code>;</td> <td rowspan="1" colspan="1"> </td> </tr> </table> </div> <p>This is an alternative way of adding a message to a folder by assembling it one MIME section at a time. First, use the <code class="function">assembleContent</code> method to specify the individual content-containing (non-<code class="literal">multipart</code> and non-<code class="literal">message/rfc822</code>) MIME sections. Before <code class="function">assembleContent</code> invokes <em class="parameter"><code>cb</code></em>'s <code class="function">success</code> method it will initialize <em class="parameter"><code>handleRet</code></em> with a “<span class="quote">handle</span>” that refers to this MIME section. Use these MIME section handles to assemble the individual MIME sections into <code class="literal">multipart</code> and <code class="literal">message/rfc822</code> MIME sections. The <code class="function">assembleMessageRfc822</code> and <code class="function">assembleMultipart</code> methods also create a new MIME section handle, which refers to the assembled MIME section, in the same way. Those handles themselves may also be re-assembled into higher-level <code class="literal">multipart</code> or <code class="literal">message/rfc822</code> MIME sections.</p> <p>Finally, after defining the topmost MIME section, use <code class="function">assemble</code> to assemble the entire message. If <code class="function">assemble</code> returns <code class="literal">true</code>, use the <code class="function">go</code> (or the <code class="function">fail</code>) method. If <code class="function">assemble</code> returns <code class="literal">false</code>, an <code class="literal">errno</code>-related error has occured; the application should call <code class="function">fail</code> to report it, and clean up the <span class="structname">mail::addMessage</span> object.</p> <p>The <code class="function">assembleContent</code> method receives a <a class="link" href="mail-attachments.html" title="mail::Attachment" shape="rect"><span class="citerefentry"><span class="refentrytitle">mail::Attachment</span>(3x)</span></a> object.</p> <p>The second parameter to <code class="function">assembleMessageRfc822</code> are the MIME headers of the <code class="literal">message/rfc822</code> attachment. The MIME headers must be terminated by a single newline character, and include the <code class="literal">Content-Type</code> header. In nearly all situations, this parameter should be set to the fixed string “<span class="quote">Content-Type: message/rfc822\n</span>” (note the trailing newline). The third parameter is the handle of the attachment's top-level MIME section.</p> <p>The second parameter to <code class="function">assembleMultipart</code> is a string containing MIME headers for the multipart MIME section. These headers should <span class="emphasis"><em>not</em></span> include the <code class="literal">Content-Type</code> header. The <code class="literal">Content-Type</code> header for the multipart section will be generated internally. If there are any extra headers, they must have a single trailing newline character. Most situations do not need extra headers, so this parameter should be an empty string, “”.</p> <p>The third parameter to <code class="function">assembleMultipart</code> is the vector of previously-defined handles of each MIME section that's to be assembled into a multipart MIME section. The fourth parameter is the actual MIME type of this section, usually “<span class="quote">multipart/mixed</span>” or “<span class="quote">multipart/alternative</span>” (any “<span class="quote">multipart</span>” type is allowed). The fifth parameter is optional, and specifies the MIME content type parameter list (the parameter list should not include the “<span class="quote">boundary</span>” parameter, because it's taken care of automatically by this function).</p> <p>The last parameter to <code class="function">assembleContent</code>, <code class="function">assembleMessageRfc822</code>, or <code class="function">assembleMultipart</code> is the callback object. The callback object's <code class="function">success</code> method will be invoked when the MIME section has been assembled. The <code class="function">fail</code> method will be invoked if an error occured. Depending on the type of the folder the message is being added to, the MIME section may be assembled immediately (in which case <code class="function">success</code> or <code class="function">fail</code> gets called right before the function terminates) or the function will terminate immediately, and the callback function will be called at a later time.</p> <div class="refsect2" lang="en" xml:lang="en"> <a id="id615622" shape="rect" name="id615622"> </a> <h3>COPYING ATTACHMENTS FROM OTHER MESSAGES</h3> <div class="funcsynopsis"> <pre class="funcsynopsisinfo" xml:space="preserve"> mail::addMessage *msg; </pre> <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"> <tr> <td rowspan="1" colspan="1"><code class="funcdef">msg-><b class="fsfunc">assembleImportAttachment</b>(</code></td> <td rowspan="1" colspan="1">size_t & </td> <td rowspan="1" colspan="1"><var class="pdparam">handleRet</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">mail::account * </td> <td rowspan="1" colspan="1"><var class="pdparam">acct</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">std::string  </td> <td rowspan="1" colspan="1"><var class="pdparam">uid</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">const mail::mimestruct & </td> <td rowspan="1" colspan="1"><var class="pdparam">attachment</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">mail::callback & </td> <td rowspan="1" colspan="1"><var class="pdparam">cb</var><code>)</code>;</td> </tr> </table> <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"> <tr> <td rowspan="1" colspan="1"><code class="funcdef">msg-><b class="fsfunc">assembleRemoveAttachmentsFrom</b>(</code></td> <td rowspan="1" colspan="1">size_t & </td> <td rowspan="1" colspan="1"><var class="pdparam">handleRet</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">mail::account * </td> <td rowspan="1" colspan="1"><var class="pdparam">acct</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">std::string  </td> <td rowspan="1" colspan="1"><var class="pdparam">uid</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">const mail::mimestruct & </td> <td rowspan="1" colspan="1"><var class="pdparam">attachment</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">const std::set & </td> <td rowspan="1" colspan="1"><var class="pdparam">mimeIdList</var>,</td> </tr> <tr> <td rowspan="1" colspan="1"> </td> <td rowspan="1" colspan="1">mail::callback & </td> <td rowspan="1" colspan="1"><var class="pdparam">cb</var><code>)</code>;</td> </tr> </table> </div> <p>The <code class="function">assembleImportAttachment</code> function assembles a new MIME section by copying an existing MIME section from another message. <em class="parameter"><code>acct</code></em> specifies an open mail account, with an open mail folder. <em class="parameter"><code>uid</code></em> specifies the unique identifier of a message in <em class="parameter"><code>acct</code></em>'s open folder, which can be obtained from <a class="link" href="mail-getfolderindexinfo.html" title="mail::account::getFolderIndexInfo" shape="rect"><span class="citerefentry"><span class="refentrytitle">mail::account::getFolderIndexInfo</span>(3x)</span></a>. <em class="parameter"><code>attachment</code></em> specifies which attachment in message <em class="parameter"><code>uid</code></em> should be copied. <em class="parameter"><code>attachment</code></em> must be obtained using <code class="literal">mail::account::MIMESTRUCTURE</code> with <a class="link" href="mail-readmsgattr.html" title="mail::account::readMessageAttributes" shape="rect"><span class="citerefentry"><span class="refentrytitle">mail::account::readMessageAttributes</span>(3x)</span></a>.</p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p><em class="parameter"><code>acct</code></em> can refer to any open mail account or folder, and does not have to be the same folder the message is being added to!</p> </div> <p><em class="parameter"><code>attachment</code></em> may refer to a multipart, or a non-multipart MIME section. An <em class="parameter"><code>attachment</code></em> referring to a multipart MIME section imports the entire multipart MIME section, and all subsections it contains. <code class="function">assembleRemoveAttachmentsFrom</code> also copies the entire multipart MIME section, but skips selected MIME subsections. Any subsection appearing in <em class="parameter"><code>mimeIdList</code></em> is not copied. <em class="parameter"><code>mimeIdList</code></em> is a list of MIME section identifiers, obtained from <a class="link" href="mimestruct.html" title="mail::mimestruct" shape="rect"><span class="citerefentry"><span class="refentrytitle">mail::mimestruct</span>(3x)</span></a>'s <em class="structfield"><code>mime_id</code></em> field.</p> <p><code class="function">assembleRemoveAttachmentsFrom</code> implements the “<span class="quote">Remove Attachments</span>” function in a typical mail client, which removes individual attachments from a message. To do that, set <em class="parameter"><code>attachment</code></em> to the top-level MIME section that refers to the entire message (literally the same object returned by <a class="link" href="mail-readmsgattr.html" title="mail::account::readMessageAttributes" shape="rect"><span class="citerefentry"><span class="refentrytitle">mail::account::readMessageAttributes</span>(3x)</span></a>) and specify the attachments to remove in <em class="parameter"><code>mimeIdList</code></em>. Use <span class="citerefentry"><span class="refentrytitle">mail::folder::addMessage</span>(3x)</span> to add the message to the same folder as the original message (this must be done before invoking <code class="function">assembleRemoveAttachmentsFrom</code>, of course), then when that's done remove the original message.</p> </div> </div> <div class="refsect1" lang="en" xml:lang="en"> <a id="id615953" shape="rect" name="id615953"> </a> <h2>RETURN CODES AND CALLBACKS</h2> <p><code class="function">mail::addMessage::fail</code> automatically invokes the callback object's <code class="function">fail</code> method, prior to returning. <code class="function">mail::addMessage::go</code> automatically invokes the callback object's <code class="function">success</code> method, when the message is added. <code class="function">mail::addMessage::go</code> will invoke <code class="function">fail</code> if the message cannot be added to the folder, for some reason.</p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p>The <code class="function">mail::folder::addMessage</code> function returns a NULL pointer if the <span class="structname">mail::addMessage</span> object cannot be created. This does not necessarily indicate an out-of-memory condition. It is not possible to manually add messages to some types of folders. For example, messages cannot be manually added to POP3 folders, since this is not supported by the POP3 protocol.</p> <p>The callback object's <code class="function">fail</code> method gets invoked just prior to this function returning NULL, in these kinds of situations.</p> </div> <p>The application must wait until <em class="parameter"><code>callback</code></em>'s <code class="function">success</code> or <code class="function">fail</code> method is invoked. The <code class="function">success</code> method is invoked when this request is succesfully processed. The <code class="function">fail</code> method is invoked if this request cannot be processed. The application must not destroy <em class="parameter"><code>callback</code></em> until either the <code class="function">success</code> or <code class="function">fail</code> method is invoked.</p> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p><em class="parameter"><code>callback</code></em>'s <code class="function">fail</code> method may be invoked even after other callback methods were invoked. This indicates that the request was partially completed before the error was encountered.</p> </div> <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Note</h3> <p><em class="parameter"><code>folder</code></em> does not necessarily have to be a <span class="structname">mail::folder</span> object that refers to the currently open folder. Any <span class="structname">mail::folder</span> object from an active <span class="structname">mail::account</span> object may be used.</p> </div> </div> <div class="refsect1" lang="en" xml:lang="en"> <a id="id616138" shape="rect" name="id616138"> </a> <h2>SEE ALSO</h2> <p><a class="link" href="mail-getfolderindexinfo.html" title="mail::account::getFolderIndexInfo" shape="rect"><span class="citerefentry"><span class="refentrytitle">mail::account::getFolderIndexInfo</span>(3x)</span></a>(), <a class="link" href="mail-readmsgattr.html" title="mail::account::readMessageAttributes" shape="rect"><span class="citerefentry"><span class="refentrytitle">mail::account::readMessageAttributes</span>(3x)</span></a>().</p> </div> </div> <div class="navfooter"> <hr/> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left" rowspan="1" colspan="1"> <a accesskey="p" href="libmail-folder.html" shape="rect">Prev</a> </td> <td width="20%" align="center" rowspan="1" colspan="1"> <a accesskey="u" href="libmail-folder.html" shape="rect">Up</a></td> <td width="40%" align="right" rowspan="1" colspan="1">  <a accesskey="n" href="folder-clone.html" shape="rect">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top" rowspan="1" colspan="1"><span class="structname">mail::folder</span> Native API reference </td> <td width="20%" align="center" rowspan="1" colspan="1"> <a accesskey="h" href="index.html" shape="rect">Home</a> | <a accesskey="t" href="bk01-toc.html" shape="rect">ToC</a></td> <td width="40%" align="right" valign="top" rowspan="1" colspan="1"> mail::folder::clone</td> </tr> </table> </div> </body> </html>