mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core/SMTP: Fixed header duplicates with AddHeader, remove reference/CoPipe
This commit is contained in:
parent
b1617ed3d3
commit
39fa92c1d7
6 changed files with 50 additions and 78 deletions
|
|
@ -1,63 +0,0 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
struct ReadIds {
|
||||
CoWork co;
|
||||
Index<String> out;
|
||||
|
||||
enum {
|
||||
PROCESSLINE,
|
||||
PROCESSID,
|
||||
};
|
||||
|
||||
void Do(const char *path)
|
||||
{
|
||||
FileIn in(path);
|
||||
if(!in)
|
||||
return;
|
||||
while(!in.IsEof()) {
|
||||
String line = in.GetLine();
|
||||
co.Pipe(PROCESSLINE, [=] { SplitLine(line); });
|
||||
}
|
||||
co.Finish();
|
||||
}
|
||||
|
||||
void SplitLine(const String& l)
|
||||
{
|
||||
const char *s = l;
|
||||
while(*s)
|
||||
if(IsAlpha(*s)) {
|
||||
const char *b = s++;
|
||||
while(IsAlNum(*s))
|
||||
s++;
|
||||
String w(b, s);
|
||||
co.Pipe(PROCESSID, [=] { ProcessId(w); });
|
||||
}
|
||||
else
|
||||
s++;
|
||||
}
|
||||
|
||||
void ProcessId(const String& w)
|
||||
{
|
||||
out.FindAdd(w);
|
||||
}
|
||||
};
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
|
||||
String fn;
|
||||
int argc = CommandLine().GetCount();
|
||||
const Vector<String>& argv = CommandLine();
|
||||
if(argc < 1)
|
||||
fn = GetDataFile("CoPipe.cpp");
|
||||
else
|
||||
fn = argv[0];
|
||||
|
||||
ReadIds h;
|
||||
h.Do(fn);
|
||||
|
||||
LOG(h.out);
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
description "Demonstrates using CoWork pipe for pipeline threaded processing\377";
|
||||
|
||||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
CoPipe.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "MT";
|
||||
|
||||
|
|
@ -58,6 +58,7 @@ class Smtp : public TcpSocket {
|
|||
void Authenticate();
|
||||
void Quit();
|
||||
|
||||
bool NoAdd(const char *id);
|
||||
String GetMessage(bool chunks);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -303,6 +303,11 @@ String Smtp::GetMessageID()
|
|||
return message_id + (q >= 0 ? sender.Mid(q) : "@unknown_host.org");
|
||||
}
|
||||
|
||||
bool Smtp::NoAdd(const char *id)
|
||||
{
|
||||
return !(add_header.StartsWith(id + String(":")) || add_header.Find(String("\n") + id + ":") >= 0);
|
||||
}
|
||||
|
||||
String Smtp::GetMessage(bool chunks)
|
||||
{
|
||||
String delimiter = "?";
|
||||
|
|
@ -343,11 +348,12 @@ String Smtp::GetMessage(bool chunks)
|
|||
if(pos)
|
||||
msg << "\r\n";
|
||||
}
|
||||
if(!IsNull(subject))
|
||||
if(!IsNull(subject) && NoAdd("Subject"))
|
||||
msg << "Subject: " << Encode(subject) << "\r\n";
|
||||
if(!IsNull(reply_to))
|
||||
if(!IsNull(reply_to) && NoAdd("Reply-To"))
|
||||
msg << "Reply-To: " << FormatAddr(reply_to, reply_to_name) << "\r\n";
|
||||
msg << "Message-ID: <" << GetMessageID() << ">\r\n";
|
||||
if(NoAdd("Message-ID"))
|
||||
msg << "Message-ID: <" << GetMessageID() << ">\r\n";
|
||||
if(!IsNull(time_sent)) {
|
||||
static const char *dayofweek[] =
|
||||
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
|
|
@ -360,7 +366,7 @@ String Smtp::GetMessage(bool chunks)
|
|||
time_sent.hour, time_sent.minute, time_sent.second)
|
||||
<< "\r\n";
|
||||
}
|
||||
if(multi || alter)
|
||||
if((multi || alter) && NoAdd("Content-Type"))
|
||||
msg << "Content-Type: multipart/" << (alter ? "alternative" : "mixed")
|
||||
<< "; boundary=\"" << delimiter << "\"\r\n"
|
||||
"\r\n";
|
||||
|
|
@ -448,6 +454,8 @@ String Smtp::GetMessage(bool chunks)
|
|||
|
||||
bool Smtp::Send(const String& msg_)
|
||||
{
|
||||
DDUMP(GetMessage(true));
|
||||
|
||||
smtp_code = 0;
|
||||
smtp_msg.Clear();
|
||||
|
||||
|
|
|
|||
24
upptst/SMTP/SMTP.cpp
Normal file
24
upptst/SMTP/SMTP.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include <Core/SMTP/SMTP.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
// This example requires OpenSSL library installed in win32!
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
Smtp::Trace();
|
||||
String to = "to@test";
|
||||
String user = "test";
|
||||
String pwd = "test";
|
||||
Smtp mail;
|
||||
mail.Host("smtp.gmail.com")
|
||||
.Port(465)
|
||||
.SSL()
|
||||
.Auth(user, pwd)
|
||||
.AddHeader("Test", String().Cat() << "<ua.aa>")
|
||||
.AddHeader("Message-ID", String().Cat() << "<ua.aa>")
|
||||
.To(to)
|
||||
.Subject("Test message")
|
||||
.Body("Hello world!")
|
||||
.Send();
|
||||
}
|
||||
13
upptst/SMTP/SMTP.upp
Normal file
13
upptst/SMTP/SMTP.upp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
description "Using Core/SMTP to send email via gmail\377";
|
||||
|
||||
uses
|
||||
Core,
|
||||
Core/SMTP,
|
||||
Core/SSL;
|
||||
|
||||
file
|
||||
SMTP.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue