File: commandsprocessor.cpp

package info (click to toggle)
aethera 0.9.3-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,588 kB
  • ctags: 7,282
  • sloc: cpp: 64,544; sh: 9,913; perl: 1,756; makefile: 1,680; python: 258
file content (161 lines) | stat: -rw-r--r-- 3,920 bytes parent folder | download
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/***************************************************************************
                commandsprocessor.cpp  -  a smart command list
                             -------------------
    begin                : Thu Jul  5 17:35:17 EEST 2001
    copyright            : (C) 2001 by Eugen C.
    email                : eug@thekompany.com
 ***************************************************************************/

#include <netimap4.h>
#include <imap4handler.h>
#include <commandsprocessor.h>

CommandProcessor::CommandProcessor()
{
  lastCommand.type=IMAP4Handler::NO_COMMANDS;
  lastCommand.account="";
  lastCommand.mailbox="";
  lastCommand.other="";
  lastCommand.parameters="";
  commands.clear();
}

CommandProcessor::~CommandProcessor()
{
  commands.clear();
}

bool CommandProcessor::insertCommand(unsigned type, string account, string mailbox, string other, string parameters)
{
  CommandsListIterator itFind;
  COMMAND_STRUCT  oldCommand=lastCommand;

  lastCommand.type=type;
  lastCommand.account=account;
  lastCommand.mailbox=mailbox;
  lastCommand.other=other;
  lastCommand.parameters=parameters;

  switch( type )
  {
    case IMAP4Handler::SYNC :
    case IMAP4Handler::NOOP :
      itFind=find(type, account);
      if( itFind==commands.end() )
        commands.push_back(lastCommand);
      break;
    case IMAP4Handler::ADD_MESSAGE :
      commands.push_back(lastCommand);
      lastCommand.type=IMAP4Handler::LOGOUT;
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::DELETE_MESSAGE :
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::UPDATE_MESSAGE :
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::EXPUNGE :
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::CLOSE :
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::LOGOUT :
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::LOGIN :
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::SELECT :
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::MOUNT :
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::UNMOUNT :
      commands.push_back(lastCommand);
      break;
    case IMAP4Handler::CREATE_FOLDER :
      commands.push_back(lastCommand);
      if( oldCommand.type!=IMAP4Handler::LOGOUT )
      {
        lastCommand.type=IMAP4Handler::LOGOUT;
        commands.push_back(lastCommand);
      }
      break;
    case IMAP4Handler::DELETE_FOLDER :
      commands.push_back(lastCommand);
      if( oldCommand.type!=IMAP4Handler::LOGOUT )
      {
        lastCommand.type=IMAP4Handler::LOGOUT;
        commands.push_back(lastCommand);
      }
      break;
    case IMAP4Handler::SUBFOLDERS :
      commands.push_back(lastCommand);
      if( oldCommand.type!=IMAP4Handler::LOGOUT )
      {
        lastCommand.type=IMAP4Handler::LOGOUT;
        commands.push_back(lastCommand);
      }
      break;
    default:
      break;
  }

  // start the thread
  IMAP4Handler::startThread();
}

bool CommandProcessor::popCommand(COMMAND_STRUCT& commandBuffer)
{
  if( commands.empty() )
    return false;

  COMMAND_STRUCT &firstCommand=commands.front();

  commandBuffer.type=firstCommand.type;
  commandBuffer.account=firstCommand.account;
  commandBuffer.mailbox=firstCommand.mailbox;
  commandBuffer.other=firstCommand.other;
  commandBuffer.parameters=firstCommand.parameters;

  // remove it from the list
  commands.pop_front();
  return true;
}

bool CommandProcessor::isEmpty()
{
  return commands.empty();
}

void CommandProcessor::clear()
{
  commands.clear();
}

CommandsListIterator CommandProcessor::find(unsigned type, string account)
{
  CommandsListIterator it;

  for(it=commands.begin(); it!=commands.end(); ++it)
    if( (*it).type==type && (*it).account==account )
      break;

  return it;
}