From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/mime/mailbox.cc | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 src/mime/mailbox.cc (limited to 'src/mime/mailbox.cc') diff --git a/src/mime/mailbox.cc b/src/mime/mailbox.cc new file mode 100644 index 0000000..69f8140 --- /dev/null +++ b/src/mime/mailbox.cc @@ -0,0 +1,137 @@ +/************************************************************************* + * + * HTCd - Copyright (C) 1998-2006 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +static int FromHead(const sref& body) +{ + sref tag,from,rest=body; + Split(tag,rest); + Split(from,rest); + return tag==from_tag&&htcTime(0,rest)>=0; +} + +///////////////////////////////////////////////////////////////////// + +const mstring nextmsg_tag="\nFrom "; +const mstring sep_tag="--"; + +Message::Message() +{ +} + +int Message::Special(sref line) +{ + line=Rest(line); + from=from0=First(line); + date=Rest(line); + idate=htcTime(0,date); + return idate>=0; +} + +int Message::Handle(const sref& name, + const sref& rawval, + const sref& val, + const rrpile& opts) +{ + mstring mime; + if(Mime::Handle(name,rawval,val,opts)) return 1; + else if(eqn(name,from_tag)) { + swrite sw(from); + decodeHeader(sw,mime,rawval); + } + else if(eqn(name,subject_tag)) { + swrite sw(subject); + decodeHeader(sw,mime,rawval); + } + else if(eqn(name,to_tag)) { + swrite sw(to); + decodeHeader(sw,mime,rawval); + } + else if(eqn(name,msgid_tag)) msgid=rawval; + else if(eqn(name,received_tag)) received.push_back(rawval); + else return 0; + return 1; +} + +void Message::putHead(mstream& out) const +{ + if(from0.nempty()) { out<<"From "<