summaryrefslogtreecommitdiffstats
path: root/libmail/smapstore.C
blob: 614af12de54140fdcee27f97bc11b3c8c9d75cd8 (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
/*
** Copyright 2003, Double Precision Inc.
**
** See COPYING for distribution information.
*/

#include "smapstore.H"
#include <sstream>

using namespace std;

const char *mail::smapSTORE::getName()
{
	return "STORE";
}

mail::smapSTORE::smapSTORE(size_t messageNumArg,
			   string propsArg,
			   imap &imapAccount,
			   mail::callback &callback)
	: uidSet(imapAccount, vector<size_t>(&messageNumArg,
					     &messageNumArg+1)),
	  props(propsArg)
{
	defaultCB= &callback;
}

mail::smapSTORE::smapSTORE(const vector<size_t> &messages,
			   string propsArg,
			   imap &imapAccount,
			   mail::callback &callback)
	: uidSet(imapAccount, messages), props(propsArg)
{
	defaultCB= &callback;
}

mail::smapSTORE::~smapSTORE()
{
}

void mail::smapSTORE::installed(imap &imapAccount)
{
	msgRange.init(imapAccount, uidSet);

	uidSet.clear();

	if (go())
		return;

	ok("OK");
	imapAccount.uninstallHandler(this);
}

bool mail::smapSTORE::ok(std::string msg)
{
	if (go())
	{
		doDestroy=false;
		return true;
	}
	return smapHandler::ok(msg);
}

bool mail::smapSTORE::go()
{
	std::ostringstream o;

	o << "STORE";

	if (!myimap->currentFolder ||
	    myimap->currentFolder->closeInProgress ||
	    !(msgRange >> o))
		return false;

	o << " " << props << "\n";

	myimap->imapcmd("", o.str());
	return true;
}