1 //=============================================================================
2 // File: exampl02.cpp
3 // Contents: Source code for Example 2 -- Parsing a simple message
4 // Maintainer: Doug Sauder <dwsauder@fwb.gulf.net>
5 // WWW: http://www.fwb.gulf.net/~dwsauder/mimepp.html
6 // $Revision: 1.6 $
7 // $Date: 1997/09/27 11:55:40 $
8 //
9 // Copyright (c) 1996, 1997 Douglas W. Sauder
10 // All rights reserved.
11 //
12 // IN NO EVENT SHALL DOUGLAS W. SAUDER BE LIABLE TO ANY PARTY FOR DIRECT,
13 // INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
14 // THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF DOUGLAS W. SAUDER
15 // HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 //
17 // DOUGLAS W. SAUDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
18 // NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19 // PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
20 // BASIS, AND DOUGLAS W. SAUDER HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
21 // SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
22 //
23 //=============================================================================
24
25 #include <stdlib.h>
26 #include <iostream>
27 #include <fstream.h>
28 #include "basicmsg.h"
29
30 #include <mimelib/token.h>
31
32
main()33 int main()
34 {
35 // Initialize the library
36
37 DwInitialize();
38
39 // Read message from file
40
41 DwString messageStr = "";
42 DwString line;
43 ifstream istrm("exampl02.txt");
44 while (DwTrue) {
45 getline(istrm, line);
46 if (istrm.eof()) {
47 break;
48 }
49 messageStr += line + DW_EOL;
50 }
51 istrm.close();
52
53 // Create a DwMessage and parse it. The DwMessage should be created on
54 // the free store, since it will be added to the BasicMessage.
55
56 DwMessage* msg = DwMessage::NewMessage(messageStr, 0);
57 msg->Parse();
58
59 // Create a Message and add the DwMessage to it
60
61 BasicMessage message(msg);
62
63 // Open file stream for output
64
65 ofstream ostrm("exampl02.out");
66
67 // Print the header fields
68
69 ostrm << "Type -> " << message.TypeStr() << "\n";
70 ostrm << "Subtype -> " << message.SubtypeStr() << "\n";
71 ostrm << "Content-Transfer-Encoding -> " << message.CteStr() << "\n";
72 ostrm << "Date -> " << message.DateStr() << "\n";
73 ostrm << "From -> " << message.From() << "\n";
74 ostrm << "To -> " << message.To() << "\n";
75 ostrm << "Cc -> " << message.Cc() << "\n";
76 ostrm << "Bcc -> " << message.Bcc() << "\n";
77 ostrm << "Subject -> " << message.Subject() << "\n";
78
79 // Print the body
80
81 ostrm << "\nBody ->\n";
82 ostrm << message.Body() << "\n";
83
84 return 0;
85 }
86
87