00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <vector>
00022 #include <string>
00023 #include <ctype.h>
00024 #include "Account.hh"
00025
00026
00027 namespace acc {
00028
00029 Account::~Account() {
00030 vector<Header>::iterator curMessage = headers.begin();
00031
00032 for(;curMessage != headers.end(); curMessage++)
00033 curMessage->lines.clear();
00034
00035 headers.clear();
00036 }
00037
00038
00039
00040
00041 int Account::storeMessageHeader(string str, int message, int size) {
00042 Header curHeader;
00043 Line curLine;
00044 curHeader.number = message;
00045 curHeader.size = size;
00046
00047 int descrStart = 0, descrEnd = 0;
00048 int contentStart = 0, contentEnd = 0;
00049 string head = cleanString(str);
00050
00051
00052 for (int i = 0; i < (int)head.length(); i++) {
00053
00054 if ( isupper(head[i]) ) {
00055 descrStart = i;
00056 if ( (descrEnd = head.find(":", descrStart)) == -1)
00057 return(-1);
00058 curLine.descr = head.substr(descrStart, (descrEnd - descrStart));
00059
00060
00061 contentStart = descrEnd + 2;
00062 if ( (contentEnd = head.find("\n", contentStart)) == -1 )
00063 contentEnd = head.length();
00064 curLine.content = head.substr(contentStart, (contentEnd - contentStart));
00065
00066
00067 if (curLine.descr.find("From") == 0)
00068 curHeader.sender = curLine.content.c_str();
00069 else if (curLine.descr.find("Subject") == 0)
00070 curHeader.subject = curLine.content.c_str();
00071 else if (curLine.descr.find("Date") == 0)
00072 curHeader.date = curLine.content.c_str();
00073
00074
00075 i = contentEnd;
00076
00077
00078 curHeader.lines.push_back(curLine);
00079 }
00080 else {
00081 if ( (i = head.find("\n", i)) == -1 )
00082 i = head.length();
00083 }
00084 }
00085
00086
00087 headers.push_back(curHeader);
00088
00089 return 0;
00090 }
00091
00092
00093
00094 string Account::cleanString(string dirty) {
00095 for (int i = 0; i <= (int)dirty.length(); i++) {
00096 if ( (dirty[i] == '\r' && dirty[i+1] == '\n') || (dirty[i] == '\n' && dirty[i+1] == '\r') ) {
00097 dirty.replace(i, 2, "\n");
00098 }
00099 }
00100
00101 return(dirty);
00102 }
00103
00104 }