summaryrefslogtreecommitdiffstats
path: root/libmail/addmessage.H
blob: 1d01caf0f9898a60341994b0477b9ea88ed25c4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
** Copyright 2002, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef libmail_addmessage_H
#define libmail_addmessage_H

#include "mail.H"

#include <string>
#include <list>
#include <vector>
#include <time.h>

#include "objectmonitor.H"
#include "namespace.H"
#include "structure.H"

LIBMAIL_START

class Attachment;

////////////////////////////////////////////////////////////////////////////
//
// Add message to a folder.  Each mail account is expected to create a
// subclass of mail::addMessage.  A mail::addMessage object gets created by
// mail::folder::addMessage().  This superclass provides fields, initialized
// with defaults.  The fields may be changed at any time before invoking the
// go() method.  The message text is provided by calling saveMessageContents().
// saveMessageContents() may be called repeatedly to provide the contents of
// a large message in pieces.  The message is saved by the go() method.
// The process may be aborted at any time, prior to go(), by invoking fail(),
// which automatically destroys the mail::addMessage object.
//
// A failure occuring while trying to add the message (including invoking
// fail()) is reported by the callback's fail method (the subclass receives
// the callback object and is responsible for dispatching the proper
// notification).


class addMessage : private ptr<mail::account> {

protected:
	bool checkServer();

public:
	addMessage(mail::account *);
	virtual ~addMessage();

	mail::messageInfo messageInfo; // Message flags

	time_t messageDate;	// Message add date.

	virtual void saveMessageContents(std::string)=0;
	virtual void go()=0;
	virtual void fail(std::string errmsg)=0;

	// Default MIME composition implementation

protected:
	std::list<mail::Attachment> att_list;
	std::vector< std::list<mail::Attachment>::iterator > att_list_vec;

public:
	virtual void assembleContent(size_t &,
				     const mail::Attachment &,
				     mail::callback &);
	virtual void assembleMessageRfc822(size_t &, std::string, size_t,
					     mail::callback &);
	virtual void assembleMultipart(size_t &,
				       std::string,
				       const std::vector<size_t> &,
				       std::string,
				       const mail::mimestruct::parameterList &,
				       mail::callback &);
	void assembleMultipart(size_t &handleRet,
			       std::string headers,
			       const std::vector<size_t> &parts,
			       std::string multipart_type,
			       mail::callback &cb)
	{
		mail::mimestruct::parameterList dummy;

		return assembleMultipart(handleRet,
					 headers, parts, multipart_type, dummy,
					 cb);
	}

	virtual void assembleImportAttachment(size_t &handleRet,
					      mail::account *acct,
					      std::string msgUid,
					      const mail::mimestruct &attachment,
					      mail::callback &cb);
	class assembleImportHelper;

	virtual void assembleRemoveAttachmentsFrom(size_t &handleRet,
						   mail::account *acct,
						   std::string msgUid,
						   const mail::mimestruct
						   &msgStruct,
						   const std::set<std::string>
						   &removeUidList,
						   mail::callback &cb);
	class assembleRemoveAttachmentsHelper;

	virtual bool assemble();

private:
	static bool chkMsgNum(mail::account *ptr, std::string msgUid,
			      size_t &n);


};

// addMessage is a "push" interface - the application "pushes"
// the new message's contents via saveMessageContents().  The mail::ACCOUNT
// API provides an alternative "pull" implementation, where a
// addMessagePull object is passed instead, whose getMessageContents()
// method is repeatedly invoked.  getMessageContents() should return the
// next part of the message's contents.  getMessageContents() is called
// repeatedly, until it returns an empty string which signifies end of
// message contents.

class addMessagePull {
public:
	addMessagePull();
	virtual ~addMessagePull();

	mail::messageInfo messageInfo; // Message flags
	time_t messageDate;	// Message add date.

	virtual std::string getMessageContents()=0;
};

LIBMAIL_END

#endif