IBR-DTNSuite  0.12
EMailImapService.h
Go to the documentation of this file.
1 /*
2  * EMailImapService.h
3  *
4  * Copyright (C) 2013 IBR, TU Braunschweig
5  *
6  * Written-by: Björn Gernert <mail@bjoern-gernert.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef EMAILIMAPSERVICE_H_
23 #define EMAILIMAPSERVICE_H_
24 
25 #include "Configuration.h"
26 #include "net/EMailSmtpService.h"
27 
29 #include <vmime/vmime.hpp>
30 
31 namespace dtn
32 {
33  namespace net
34  {
36  {
37  public:
38 
42  static EMailImapService& getInstance();
43 
47  void run() throw ();
48 
52  void __cancellation() throw ();
53 
63 
67  void fetchMails();
68 
69  private:
73  class TimeoutHandler : public vmime::net::timeoutHandler
74  {
75  public:
76  bool isTimeOut();
77  void resetTimeOut();
78  bool handleTimeOut();
79  private:
80  unsigned int getTime()
81  {
82  return vmime::platform::getHandler()->getUnixTime();
83  }
84  unsigned int last;
85  };
86 
90  class TimeoutHandlerFactory : public vmime::net::timeoutHandlerFactory
91  {
92  public:
93  vmime::ref<vmime::net::timeoutHandler> create()
94  {
95  return vmime::create<TimeoutHandler>();
96  }
97  };
98 
103 
107  virtual ~EMailImapService();
108 
113  void connect();
114 
121  bool isConnected();
122 
127  void disconnect();
128 
138  void queryServer();
139 
143  void loadCerificates();
144 
160  void generateBundle(vmime::ref<vmime::net::message> &msg);
161 
171  void returningMailCheck(vmime::ref<vmime::net::message> &msg);
172 
183  dtn::data::BundleID extractBID(const std::string &message);
184 
196  std::string searchString(const std::string &search, const std::string &s);
197 
205  void setProcFlags(dtn::data::Block &block, size_t &flags);
206 
215  vmime::ref<vmime::security::cert::X509Certificate> loadCertificateFromFile(const std::string &path);
216 
220  const dtn::daemon::Configuration::EMail& _config;
221 
225  static bool _run;
226 
230  vmime::ref<vmime::net::store> _store;
231 
235  ibrcommon::Mutex _threadMutex;
236 
240  vmime::ref<vmime::security::cert::defaultCertificateVerifier> _certificateVerifier;
241 
245  vmime::net::folder::path _path;
246 
250  vmime::ref<vmime::net::folder> _folder;
251 
255  std::list<EMailSmtpService::Task*> _processedTasks;
256 
260  ibrcommon::Mutex _processedTasksMutex;
261 
271  int toInt(std::string s);
272 
280  std::string toString(int i);
281 
289  void addEIDList(dtn::data::Block &block,
290  vmime::utility::ref<const vmime::attachment> &attachment);
291 
295  class InvalidCertificate : public ibrcommon::Exception {
296  public:
297  InvalidCertificate() {}
298  InvalidCertificate(std::string msg) : Exception(msg) {}
299  };
300 
304  class InvalidConversion : public ibrcommon::Exception {
305  public:
306  InvalidConversion() {}
307  InvalidConversion(std::string msg) : Exception(msg) {}
308  };
309 
313  class StringNotFound : public ibrcommon::Exception {
314  public:
315  StringNotFound() {}
316  StringNotFound(std::string msg) : Exception(msg) {}
317  };
318 
322  class BidNotFound : public ibrcommon::Exception {
323  public:
324  BidNotFound() {}
325  BidNotFound(std::string msg) : Exception(msg) {}
326  };
327 
331  class IMAPException : public ibrcommon::Exception {
332  public:
333  IMAPException() {}
334  IMAPException(std::string msg) : Exception(msg) {}
335  };
336  };
337  }
338 }
339 
340 #endif /* EMAILIMAPSERVICE_H_ */