summaryrefslogtreecommitdiff
path: root/WebMail.c
diff options
context:
space:
mode:
authorDave Hibberd <hibby@debian.org>2025-07-22 20:56:59 +0100
committerDave Hibberd <hibby@debian.org>2025-07-22 20:56:59 +0100
commit1f40ff4a07793ecfa679a1384053451c4f3f536f (patch)
treec0813999c7216f98b4ac66224bd01589baee84d1 /WebMail.c
parentb128f2a43a16acef50de045ae6526772c04c395e (diff)
New upstream version 6.0.24.77+repackupstream/6.0.24.77+repack
Diffstat (limited to 'WebMail.c')
-rw-r--r--WebMail.c215
1 files changed, 194 insertions, 21 deletions
diff --git a/WebMail.c b/WebMail.c
index a3ff5b1..2c97f84 100644
--- a/WebMail.c
+++ b/WebMail.c
@@ -1446,7 +1446,12 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL
// Neither do js or file downloads
- if (_memicmp(NodeURL, "/WebMail/WMFile/", 16) == 0)
+ // This could be a request for a Template file
+ // WebMail/Local_Templates/My Forms/inc/logo_ad63.png
+ // WebMail/Standard Templates/
+
+
+ if (_memicmp(NodeURL, "/WebMail/Local", 14) == 0 || (_memicmp(NodeURL, "/WebMail/Standard", 17) == 0))
{
int FileSize;
char * MsgBytes;
@@ -1456,9 +1461,10 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL
char TimeString[64];
char FileTimeString[64];
struct stat STAT;
- char * FN = &NodeURL[16];
+ char * FN = &NodeURL[9];
char * fileBit = FN;
char * ext;
+ char Type[64] = "Content-Type: text/html\r\n";
UndoTransparency(FN);
ext = strchr(FN, '.');
@@ -1491,27 +1497,112 @@ void ProcessWebMailMessage(struct HTTPConnectionInfo * Session, char * Key, BOOL
FormatTime2(FileTimeString, STAT.st_ctime);
FormatTime2(TimeString, time(NULL));
- if (_stricmp(ext, ".htm") == 0 || _stricmp(ext, ".html") == 0 || _stricmp(ext, ".css") == 0 || _stricmp(ext, ".js") == 0)
- {
- *RLen = sprintf(Reply, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n"
- "Content-Type: text/css\r\n"
+ ext++;
+
+ if (_stricmp(ext, "js") == 0)
+ strcpy(Type, "Content-Type: text/javascript\r\n");
+
+ if (_stricmp(ext, "css") == 0)
+ strcpy(Type, "Content-Type: text/css\r\n");
+
+ if (_stricmp(ext, "pdf") == 0)
+ strcpy(Type, "Content-Type: application/pdf\r\n");
+
+ if (_stricmp(ext, "jpg") == 0 || _stricmp(ext, "jpeg") == 0 || _stricmp(ext, "png") == 0 ||
+ _stricmp(ext, "gif") == 0 || _stricmp(ext, "bmp") == 0 || _stricmp(ext, "ico") == 0)
+ strcpy(Type, "Content-Type: image\r\n");
+
+ // File may be binary so output header then copy in message
+
+ *RLen = sprintf(Reply, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n"
+ "%s"
"Date: %s\r\n"
"Last-Modified: %s\r\n"
- "\r\n%s", FileSize, TimeString, FileTimeString, MsgBytes);
+ "\r\n", FileSize, Type,TimeString, FileTimeString);
+
+ memcpy(&Reply[*RLen], MsgBytes, FileSize);
+ *RLen += FileSize;
+ free (MsgBytes);
+ return;
+ }
+
+ //
+
+ if (_memicmp(NodeURL, "/WebMail/WMFile/", 16) == 0)
+ {
+ int FileSize;
+ char * MsgBytes;
+ char MsgFile[512];
+ FILE * hFile;
+ size_t ReadLen;
+ char TimeString[64];
+ char FileTimeString[64];
+ struct stat STAT;
+ char * FN = &NodeURL[16];
+ char * fileBit = FN;
+ char * ext;
+ char Type[64] = "Content-Type: text/html\r\n";
+
+
+ UndoTransparency(FN);
+ ext = strchr(FN, '.');
+
+ sprintf(MsgFile, "%s/%s", BPQDirectory, FN);
+
+ while (strchr(fileBit, '/'))
+ fileBit = strlop(fileBit, '/');
+
+ if (stat(MsgFile, &STAT) == -1)
+ {
+ *RLen = sprintf(Reply, "HTTP/1.1 404 Not Found\r\nContent-Length: 16\r\n\r\nPage not found\r\n");
+ return;
}
- else
+
+ hFile = fopen(MsgFile, "rb");
+
+ if (hFile == 0)
{
- *RLen = sprintf(Reply, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n"
- "Content-Type: application/octet-stream\r\n"
- "Content-Disposition: attachment; filename=\"%s\"\r\n"
+ *RLen = sprintf(Reply, "HTTP/1.1 404 Not Found\r\nContent-Length: 16\r\n\r\nPage not found\r\n");
+ return;
+ }
+
+ FileSize = STAT.st_size;
+ MsgBytes = malloc(FileSize + 1);
+ ReadLen = fread(MsgBytes, 1, FileSize, hFile);
+
+ fclose(hFile);
+
+ FormatTime2(FileTimeString, STAT.st_ctime);
+ FormatTime2(TimeString, time(NULL));
+
+ ext++;
+
+ if (_stricmp(ext, "js") == 0)
+ strcpy(Type, "Content-Type: text/javascript\r\n");
+
+ if (_stricmp(ext, "css") == 0)
+ strcpy(Type, "Content-Type: text/css\r\n");
+
+ if (_stricmp(ext, "pdf") == 0)
+ strcpy(Type, "Content-Type: application/pdf\r\n");
+
+ if (_stricmp(ext, "jpg") == 0 || _stricmp(ext, "jpeg") == 0 || _stricmp(ext, "png") == 0 ||
+ _stricmp(ext, "gif") == 0 || _stricmp(ext, "bmp") == 0 || _stricmp(ext, "ico") == 0)
+ strcpy(Type, "Content-Type: image\r\n");
+
+ // File may be binary so output header then copy in message
+
+ *RLen = sprintf(Reply, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n"
+ "%s"
"Date: %s\r\n"
"Last-Modified: %s\r\n"
- "\r\n%s", FileSize, fileBit, TimeString, FileTimeString, MsgBytes);
+ "\r\n", FileSize, Type,TimeString, FileTimeString);
- }
+ memcpy(&Reply[*RLen], MsgBytes, FileSize);
+ *RLen += FileSize;
free (MsgBytes);
return;
- }
+ }
Session = NULL;
@@ -2731,6 +2822,18 @@ VOID SaveNewMessage(struct HTTPConnectionInfo * Session, char * MsgPtr, char * R
strcpy(Msg->via, ToUser->HomeBBS);
sprintf(Prompt, "%s added from HomeBBS. Message Saved", Msg->via);
}
+ else
+ {
+ // No HomeBBS - check WP
+
+ WPRecP WP = LookupWP(Msg->to);
+
+ if (WP)
+ {
+ strcpy(Msg->via, WP->first_homebbs);
+ sprintf(Prompt, "%s added from WP", Msg->via);
+ }
+ }
}
else
{
@@ -2883,7 +2986,7 @@ VOID SaveNewMessage(struct HTTPConnectionInfo * Session, char * MsgPtr, char * R
// RMS Express Forms Support
-char * GetHTMLViewerTemplate(char * FN)
+char * GetHTMLViewerTemplate(char * FN, struct HtmlFormDir ** FormDir)
{
int i, j, k, l;
@@ -2897,6 +3000,7 @@ char * GetHTMLViewerTemplate(char * FN)
{
if (strcmp(FN, Dir->Forms[j]->FileName) == 0)
{
+ *FormDir = Dir;
return CheckFile(Dir, FN);
}
}
@@ -2917,6 +3021,7 @@ char * GetHTMLViewerTemplate(char * FN)
{
if (_stricmp(FN, SDir->Forms[k]->FileName) == 0)
{
+ *FormDir = SDir;
return CheckFile(SDir, SDir->Forms[k]->FileName);
}
}
@@ -2980,6 +3085,13 @@ VOID GetPage(struct HTTPConnectionInfo * Session, char * NodeURL)
ptr = strchr(&NodeURL[17], ',');
Dir = HtmlFormDirs[DirNo];
+
+ if (DirNo == -1)
+ {
+ *WebMail->RLen = sprintf(WebMail->Reply, "<html><script>alert(\"No Page Selected. \");window.location.href = '/Webmail/NewMsg?%s';</script></html>", Session->Key);
+ return;
+ }
+
SubDir = strlop(&NodeURL[17], ':');
if (SubDir)
{
@@ -3293,6 +3405,13 @@ BOOL ParseXML(WebMailInfo * WebMail, char * XMLOrig)
// Extract Fields (stuff between < and >. Ignore Whitespace between fields
+ // Add FormFolder Key with our folder
+
+// XMLKeys->Key = "FormFolder";
+// XMLKeys->Value = _strdup(FormDir);
+
+// XMLKeys++;
+
ptr1 = strstr(XML, "<xml_file_version>");
while (ptr1)
@@ -3396,6 +3515,8 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch
size_t varlen, xmllen;
char var[100] = "<";
KeyValues * KeyValue;
+ struct HtmlFormDir * Dir;
+ char FormDir[MAX_PATH];
if (ParseXML(WebMail, XML))
ptr = FindXMLVariable(WebMail, "display_form");
@@ -3409,7 +3530,11 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch
strcpy(FN, ptr);
- Form = GetHTMLViewerTemplate(FN);
+ Form = GetHTMLViewerTemplate(FN, &Dir);
+
+ sprintf(FormDir, "WMFile/%s/%s/", Dir->FormSet, Dir->DirName);
+
+
if (Form == NULL)
{
@@ -3425,6 +3550,15 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch
// Don't know why, but {MsgOriginalBody} is sent instead of {var MsgOriginalBody}
+ // So is {FormFolder} instread of {var FormFolder}
+
+ // As a fiddle replace {FormFolder} with {var Folder} and look for that
+
+ while (varptr = stristr(Form, "{FormFolder}"))
+ {
+ memcpy(varptr, "{var ", 5);
+ }
+
varptr = stristr(Form, "{MsgOriginalBody}");
{
char * temp, * tempsave;
@@ -3564,6 +3698,23 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch
while (KeyValue->Key)
{
+ if (_stricmp(var, "Folder") == 0)
+ {
+ // Local form folder, not senders
+
+ xmllen = strlen(FormDir);
+
+ // Ok, we have the position of the variable and the substitution text.
+ // Copy message up to variable to Result, then copy value
+
+ memcpy(Reply, formptr, varptr - formptr - 5); // omit "{var "
+ Reply += (varptr - formptr - 5);
+
+ strcpy(Reply, FormDir);
+ Reply += xmllen;
+ break;
+ }
+
if (_stricmp(var, KeyValue->Key) == 0)
{
xmllen = strlen(KeyValue->Value);
@@ -3579,6 +3730,8 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch
break;
}
+ KeyValue++;
+
if (KeyValue->Key == NULL)
{
// Not found in XML
@@ -3588,7 +3741,7 @@ int DisplayWebForm(struct HTTPConnectionInfo * Session, struct MsgInfo * Msg, ch
sprintf(Err, VarNotFoundMsg, var, "%s");
return ReturnRawMessage(User, Msg, Key, SaveReply, RawMessage, (int)(XML - RawMessage), Err);
}
- KeyValue++;
+
}
formptr = endptr + 1;
@@ -4098,6 +4251,18 @@ VOID SaveTemplateMessage(struct HTTPConnectionInfo * Session, char * MsgPtr, cha
strcpy(Msg->via, ToUser->HomeBBS);
sprintf(Prompt, "%s added from HomeBBS. Message Saved", Msg->via);
}
+ else
+ {
+ // No HomeBBS - Check WP
+
+ WPRecP WP = LookupWP(Msg->to);
+
+ if (WP)
+ {
+ strcpy(Msg->via, WP->first_homebbs);
+ sprintf(Prompt, "%s added from WP", Msg->via);
+ }
+ }
}
else
{
@@ -4318,6 +4483,18 @@ VOID BuildMessageFromHTMLInput(struct HTTPConnectionInfo * Session, char * Reply
strcpy(Msg->via, ToUser->HomeBBS);
sprintf(Prompt, "%s added from HomeBBS", Msg->via);
}
+ else
+ {
+ // No HomeBBS - Check WP
+
+ WPRecP WP = LookupWP(Msg->to);
+
+ if (WP)
+ {
+ strcpy(Msg->via, WP->first_homebbs);
+ sprintf(Prompt, "%s added from WP", Msg->via);
+ }
+ }
}
else
{
@@ -5448,8 +5625,6 @@ char * CheckFile(struct HtmlFormDir * Dir, char * FN)
#endif
- printf("%s\n", MsgFile);
-
if (stat(MsgFile, &STAT) != -1)
{
hFile = fopen(MsgFile, "rb");
@@ -5466,8 +5641,6 @@ char * CheckFile(struct HtmlFormDir * Dir, char * FN)
MsgBytes[FileSize] = 0;
fclose(hFile);
- printf("%d %s\n", strlen(MsgBytes), MsgBytes);
-
return MsgBytes;
}
return NULL;