summaryrefslogtreecommitdiffstats
path: root/libmail/nntpgroup.C
blob: 99cbf4702acbe1b0561667bb016d9f3f3ff4c428 (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
/*
** Copyright 2003, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#include "nntpgroup.H"
#include <sstream>

using namespace std;

//
// Make sure a particular group is selected, before proceeding
//

mail::nntp::GroupTask::GroupTask(callback *callbackArg, nntp &myserverArg,
				 std::string groupNameArg)
	: LoggedInTask(callbackArg, myserverArg),
	  groupName(groupNameArg)
{
}

mail::nntp::GroupTask::~GroupTask()
{
}

void mail::nntp::GroupTask::loggedIn()
{
	if (myserver->serverGroup == groupName &&
	    myserver->openedGroup == groupName)
		// Must check openedGroup
	{
		selectedCurrentGroup();
		return;
	}

	response_func= &mail::nntp::GroupTask::processGroupStatus;
	myserver->serverGroup="";
	myserver->socketWrite("GROUP " + groupName + "\r\n");
}

void mail::nntp::GroupTask::processLine(const char *message)
{
	(this->*response_func)(message);
}

void mail::nntp::GroupTask::selectedCurrentGroup()
{
	response_func= &mail::nntp::GroupTask::processOtherStatus;
	if (myserver->index.size() == 0)
		selectedGroup(0, 0, 0);
	else
		selectedGroup(myserver->index[0].msgNum,
			      myserver->index.end()[-1].msgNum,
			      myserver->index.size());
}

void mail::nntp::GroupTask::processGroupStatus(const char *msg)
{
	string buf=msg;
	istringstream i(buf);

	int status;
	msgnum_t est, lo, hi;

	i >> status >> est >> lo >> hi;

	if (i.bad() || i.fail() || (status / 100) != 2)
	{
		fail(msg);
		return;
	}

	++hi;

	if (est > hi-lo)
		est=hi-lo; // Fix an impossibility


	response_func= &mail::nntp::GroupTask::processOtherStatus;
	myserver->serverGroup=groupName;

	if (myserver->openedGroup == groupName)
		selectedCurrentGroup();
	else
		selectedGroup(est, lo, hi);
}

void mail::nntp::GroupTask::processOtherStatus(const char *msg)
{
	processGroup(msg);
}