mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-10-06 00:30:10 -06:00
Core/POP3 (thanks Oblivion!)
git-svn-id: svn://ultimatepp.org/upp/trunk@7091 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
69291a131d
commit
4e7a10108a
8 changed files with 690 additions and 0 deletions
86
uppsrc/Core/POP3/InetMessage.cpp
Normal file
86
uppsrc/Core/POP3/InetMessage.cpp
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#include "POP3.h"
|
||||
|
||||
bool InetMessage::ReadHeader(VectorMap<String, String>& hdr, StringStream& ss)
|
||||
{
|
||||
for(;;) {
|
||||
if(ss.IsEof())
|
||||
return false;
|
||||
String s = ss.GetLine();
|
||||
if(s.IsEmpty())
|
||||
return true;
|
||||
if(s[0] == ' ' || s[0] == '\t') {
|
||||
if(hdr.GetCount())
|
||||
hdr.Top().Cat(TrimLeft(s.Mid(1)));
|
||||
}
|
||||
else {
|
||||
int q = s.Find(':');
|
||||
if(q >= 0)
|
||||
hdr.Add(ToLower(s.Mid(0, q)), TrimLeft(s.Mid(q + 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool InetMessage::ReadHeader(const String& s)
|
||||
{
|
||||
part.Clear();
|
||||
header.Clear();
|
||||
StringStream ss(s);
|
||||
return ReadHeader(header, ss);
|
||||
}
|
||||
|
||||
bool InetMessage::Read(const String& s)
|
||||
{
|
||||
part.Clear();
|
||||
header.Clear();
|
||||
StringStream ss(s);
|
||||
if(!ReadHeader(header, ss))
|
||||
return false;
|
||||
|
||||
String type = header.Get("content-type");
|
||||
if(!type.StartsWith("multipart")) {
|
||||
part.Add().body = LoadStream(ss);
|
||||
return true;
|
||||
}
|
||||
|
||||
String boundary;
|
||||
int q = type.Find("boundary=");
|
||||
if(q < 0)
|
||||
return false;
|
||||
q += strlen("boundary=");
|
||||
int qq = type.Find(";", q);
|
||||
if(qq >= 0)
|
||||
boundary = type.Mid(q, qq);
|
||||
else
|
||||
boundary = type.Mid(q);
|
||||
|
||||
if(*boundary == '\"')
|
||||
boundary = boundary.Mid(1);
|
||||
if(*boundary.Last() == '\"')
|
||||
boundary.Trim(boundary.GetCount() - 1);
|
||||
|
||||
boundary = "--" + boundary;
|
||||
String end_boundary = boundary + "--";
|
||||
|
||||
for(;;) {
|
||||
String ln = ss.GetLine();
|
||||
if(ln == boundary)
|
||||
break;
|
||||
if(ss.IsEof())
|
||||
return false;
|
||||
}
|
||||
for(;;) {
|
||||
Part& p = part.Add();
|
||||
if(!ReadHeader(p.header, ss))
|
||||
return false;
|
||||
for(;;) {
|
||||
if(ss.IsEof())
|
||||
return false;
|
||||
String ln = ss.GetLine();
|
||||
if(ln == boundary)
|
||||
break;
|
||||
if(ln == end_boundary)
|
||||
return true;
|
||||
p.body << ln << "\r\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue