Fix for #7372. Don't use an uninitialized buffer. Some BString replacement of C strings. Replace Mail's ReadAttrString() function with the BNode method. Define a B_MAIL_ATTR_BCC.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41159 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -19,6 +19,7 @@ struct entry_ref;
|
|||||||
#define B_MAIL_ATTR_PRIORITY "MAIL:priority" // indexed string
|
#define B_MAIL_ATTR_PRIORITY "MAIL:priority" // indexed string
|
||||||
#define B_MAIL_ATTR_TO "MAIL:to" // indexed string
|
#define B_MAIL_ATTR_TO "MAIL:to" // indexed string
|
||||||
#define B_MAIL_ATTR_CC "MAIL:cc" // indexed string
|
#define B_MAIL_ATTR_CC "MAIL:cc" // indexed string
|
||||||
|
#define B_MAIL_ATTR_BCC "MAIL:bcc" // string
|
||||||
#define B_MAIL_ATTR_FROM "MAIL:from" // indexed string
|
#define B_MAIL_ATTR_FROM "MAIL:from" // indexed string
|
||||||
#define B_MAIL_ATTR_SUBJECT "MAIL:subject" // indexed string
|
#define B_MAIL_ATTR_SUBJECT "MAIL:subject" // indexed string
|
||||||
#define B_MAIL_ATTR_REPLY "MAIL:reply" // indexed string
|
#define B_MAIL_ATTR_REPLY "MAIL:reply" // indexed string
|
||||||
|
|||||||
+10
-10
@@ -548,11 +548,11 @@ THeaderView::InitGroupCompletion()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
BString groups;
|
BString groups;
|
||||||
if (ReadAttrString(&file, "META:group", &groups) < B_OK || groups.Length() == 0)
|
if (file.ReadAttrString("META:group", &groups) < B_OK || groups.Length() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BString address;
|
BString address;
|
||||||
ReadAttrString(&file, "META:email", &address);
|
file.ReadAttrString("META:email", &address);
|
||||||
|
|
||||||
// avoid adding an empty address
|
// avoid adding an empty address
|
||||||
if (address.Length() == 0)
|
if (address.Length() == 0)
|
||||||
@@ -822,7 +822,7 @@ TTextControl::MessageReceived(BMessage *msg)
|
|||||||
attr = buffer;
|
attr = buffer;
|
||||||
|
|
||||||
BString address;
|
BString address;
|
||||||
ReadAttrString(&node, buffer, &address);
|
node.ReadAttrString(buffer, &address);
|
||||||
if (address.Length() <= 0)
|
if (address.Length() <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -846,13 +846,13 @@ TTextControl::MessageReceived(BMessage *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BString email;
|
BString email;
|
||||||
ReadAttrString(&file,attr.String(),&email);
|
file.ReadAttrString(attr.String(), &email);
|
||||||
|
|
||||||
// we got something...
|
// we got something...
|
||||||
if (email.Length() > 0) {
|
if (email.Length() > 0) {
|
||||||
// see if we can get a username as well
|
// see if we can get a username as well
|
||||||
BString name;
|
BString name;
|
||||||
ReadAttrString(&file, "META:name", &name);
|
file.ReadAttrString("META:name", &name);
|
||||||
|
|
||||||
BString address;
|
BString address;
|
||||||
if (name.Length() == 0) {
|
if (name.Length() == 0) {
|
||||||
@@ -912,7 +912,7 @@ TTextControl::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
display = address;
|
display = address;
|
||||||
|
|
||||||
ReadAttrString(&node, "META:name", &name);
|
node.ReadAttrString("META:name", &name);
|
||||||
if (name.Length() > 0) {
|
if (name.Length() > 0) {
|
||||||
display = "";
|
display = "";
|
||||||
display << "\"" << name << "\" <" << address << ">";
|
display << "\"" << name << "\" <" << address << ">";
|
||||||
@@ -1064,7 +1064,7 @@ QPopupMenu::EntryCreated(const entry_ref &ref, ino_t node)
|
|||||||
// Does the file have a group attribute? OK to have none.
|
// Does the file have a group attribute? OK to have none.
|
||||||
BString groups;
|
BString groups;
|
||||||
const char *kNoGroup = "NoGroup!";
|
const char *kNoGroup = "NoGroup!";
|
||||||
ReadAttrString(&file, "META:group", &groups);
|
file.ReadAttrString("META:group", &groups);
|
||||||
if (groups.Length() <= 0)
|
if (groups.Length() <= 0)
|
||||||
groups = kNoGroup;
|
groups = kNoGroup;
|
||||||
|
|
||||||
@@ -1142,10 +1142,10 @@ QPopupMenu::EntryCreated(const entry_ref &ref, ino_t node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BString name;
|
BString name;
|
||||||
ReadAttrString(&file, "META:name", &name);
|
file.ReadAttrString("META:name", &name);
|
||||||
|
|
||||||
BString email;
|
BString email;
|
||||||
ReadAttrString(&file, "META:email", &email);
|
file.ReadAttrString("META:email", &email);
|
||||||
|
|
||||||
if (email.Length() != 0 || name.Length() != 0)
|
if (email.Length() != 0 || name.Length() != 0)
|
||||||
AddPersonItem(&ref, node, name, email, NULL, groupMenu, superItem);
|
AddPersonItem(&ref, node, name, email, NULL, groupMenu, superItem);
|
||||||
@@ -1154,7 +1154,7 @@ QPopupMenu::EntryCreated(const entry_ref &ref, ino_t node)
|
|||||||
for (int16 i = 2; i < 6; i++) {
|
for (int16 i = 2; i < 6; i++) {
|
||||||
char attr[16];
|
char attr[16];
|
||||||
sprintf(attr, "META:email%d", i);
|
sprintf(attr, "META:email%d", i);
|
||||||
if (ReadAttrString(&file, attr, &email) >= B_OK && email.Length() > 0)
|
if (file.ReadAttrString(attr, &email) >= B_OK && email.Length() > 0)
|
||||||
AddPersonItem(&ref, node, name, email, attr, groupMenu, superItem);
|
AddPersonItem(&ref, node, name, email, attr, groupMenu, superItem);
|
||||||
}
|
}
|
||||||
} while (groups.Length() > 0);
|
} while (groups.Length() > 0);
|
||||||
|
|||||||
@@ -253,10 +253,10 @@ TMailApp::MessageReceived(BMessage *msg)
|
|||||||
{
|
{
|
||||||
msg->FindRef("ref", &ref);
|
msg->FindRef("ref", &ref);
|
||||||
BNode file(&ref);
|
BNode file(&ref);
|
||||||
BString string = "";
|
BString string;
|
||||||
|
|
||||||
if (file.InitCheck() == B_OK)
|
if (file.InitCheck() == B_OK)
|
||||||
ReadAttrString(&file, B_MAIL_ATTR_TO, &string);
|
file.ReadAttrString(B_MAIL_ATTR_TO, &string);
|
||||||
|
|
||||||
window = NewWindow(&ref, string.String(), true);
|
window = NewWindow(&ref, string.String(), true);
|
||||||
break;
|
break;
|
||||||
@@ -1088,10 +1088,10 @@ TMailApp::NewWindow(const entry_ref* ref, const char* to, bool resend,
|
|||||||
BFile file;
|
BFile file;
|
||||||
if (!resend && ref && file.SetTo(ref, O_RDONLY) == B_OK) {
|
if (!resend && ref && file.SetTo(ref, O_RDONLY) == B_OK) {
|
||||||
BString name;
|
BString name;
|
||||||
if (ReadAttrString(&file, B_MAIL_ATTR_NAME, &name) == B_OK) {
|
if (file.ReadAttrString(B_MAIL_ATTR_NAME, &name) == B_OK) {
|
||||||
title << name;
|
title << name;
|
||||||
BString subject;
|
BString subject;
|
||||||
if (ReadAttrString(&file, B_MAIL_ATTR_SUBJECT, &subject) == B_OK)
|
if (file.ReadAttrString(B_MAIL_ATTR_SUBJECT, &subject) == B_OK)
|
||||||
title << " -> " << subject;
|
title << " -> " << subject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,11 +150,11 @@ add_query_menu_items(BMenu* menu, const char* attribute, uint32 what,
|
|||||||
|
|
||||||
message->AddString("attribute", value.String());
|
message->AddString("attribute", value.String());
|
||||||
|
|
||||||
char name[256];
|
BString name;
|
||||||
if (format != NULL)
|
if (format != NULL)
|
||||||
snprintf(name, sizeof(name), format, value.String());
|
name.SetToFormat(format, value.String());
|
||||||
else
|
else
|
||||||
strlcpy(name, value.String(), sizeof(name));
|
name = value;
|
||||||
|
|
||||||
if (index < 9 && !popup)
|
if (index < 9 && !popup)
|
||||||
menu->AddItem(new BMenuItem(name, message, '1' + index));
|
menu->AddItem(new BMenuItem(name, message, '1' + index));
|
||||||
|
|||||||
@@ -47,8 +47,10 @@ of their respective holders. All rights reserved.
|
|||||||
#include <Clipboard.h>
|
#include <Clipboard.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <E-mail.h>
|
#include <E-mail.h>
|
||||||
|
#include <File.h>
|
||||||
#include <InterfaceKit.h>
|
#include <InterfaceKit.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
|
#include <Node.h>
|
||||||
#include <PathMonitor.h>
|
#include <PathMonitor.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
@@ -181,8 +183,6 @@ TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
|
|||||||
if (messenger != NULL)
|
if (messenger != NULL)
|
||||||
fTrackerMessenger = *messenger;
|
fTrackerMessenger = *messenger;
|
||||||
|
|
||||||
char str[256];
|
|
||||||
char status[272];
|
|
||||||
float height;
|
float height;
|
||||||
BMenu* menu;
|
BMenu* menu;
|
||||||
BMenu* subMenu;
|
BMenu* subMenu;
|
||||||
@@ -246,16 +246,18 @@ TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
|
|||||||
if (flag == B_UNREAD) {
|
if (flag == B_UNREAD) {
|
||||||
subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Leave as New"),
|
subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Leave as New"),
|
||||||
new BMessage(kMsgQuitAndKeepAllStatus), 'W', B_SHIFT_KEY));
|
new BMessage(kMsgQuitAndKeepAllStatus), 'W', B_SHIFT_KEY));
|
||||||
#if 0
|
|
||||||
subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Set to Read"),
|
|
||||||
new BMessage(M_CLOSE_READ), 'W'));
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
if (strlen(str))
|
BString status;
|
||||||
sprintf(status, B_TRANSLATE("Leave as '%s'"), str);
|
file.ReadAttrString(B_MAIL_ATTR_STATUS, &status);
|
||||||
|
|
||||||
|
BString label;
|
||||||
|
if (status.Length() > 0)
|
||||||
|
label.SetToFormat(B_TRANSLATE("Leave as '%s'"),
|
||||||
|
status.String());
|
||||||
else
|
else
|
||||||
sprintf(status, B_TRANSLATE("Leave same"));
|
label = B_TRANSLATE("Leave same");
|
||||||
subMenu->AddItem(item = new BMenuItem(status,
|
|
||||||
|
subMenu->AddItem(item = new BMenuItem(label.String(),
|
||||||
new BMessage(B_QUIT_REQUESTED), 'W'));
|
new BMessage(B_QUIT_REQUESTED), 'W'));
|
||||||
AddShortcut('W', B_COMMAND_KEY | B_SHIFT_KEY,
|
AddShortcut('W', B_COMMAND_KEY | B_SHIFT_KEY,
|
||||||
new BMessage(kMsgQuitAndKeepAllStatus));
|
new BMessage(kMsgQuitAndKeepAllStatus));
|
||||||
@@ -1211,7 +1213,7 @@ TMailWindow::MessageReceived(BMessage *msg)
|
|||||||
BString string = "could not read";
|
BString string = "could not read";
|
||||||
BNode node(fRef);
|
BNode node(fRef);
|
||||||
if (node.InitCheck() == B_OK)
|
if (node.InitCheck() == B_OK)
|
||||||
ReadAttrString(&node, B_MAIL_ATTR_STATUS, &string);
|
node.ReadAttrString(B_MAIL_ATTR_STATUS, &string);
|
||||||
|
|
||||||
new TStatusWindow(r, this, string.String());
|
new TStatusWindow(r, this, string.String());
|
||||||
}
|
}
|
||||||
@@ -2029,15 +2031,15 @@ TMailWindow::CopyMessage(entry_ref *ref, TMailWindow *src)
|
|||||||
if (file.InitCheck() == B_OK) {
|
if (file.InitCheck() == B_OK) {
|
||||||
BString string;
|
BString string;
|
||||||
if (fHeaderView->fTo
|
if (fHeaderView->fTo
|
||||||
&& ReadAttrString(&file, B_MAIL_ATTR_TO, &string) == B_OK)
|
&& file.ReadAttrString(B_MAIL_ATTR_TO, &string) == B_OK)
|
||||||
fHeaderView->fTo->SetText(string.String());
|
fHeaderView->fTo->SetText(string.String());
|
||||||
|
|
||||||
if (fHeaderView->fSubject
|
if (fHeaderView->fSubject
|
||||||
&& ReadAttrString(&file, B_MAIL_ATTR_SUBJECT, &string) == B_OK)
|
&& file.ReadAttrString(B_MAIL_ATTR_SUBJECT, &string) == B_OK)
|
||||||
fHeaderView->fSubject->SetText(string.String());
|
fHeaderView->fSubject->SetText(string.String());
|
||||||
|
|
||||||
if (fHeaderView->fCc
|
if (fHeaderView->fCc
|
||||||
&& ReadAttrString(&file, B_MAIL_ATTR_CC, &string) == B_OK)
|
&& file.ReadAttrString(B_MAIL_ATTR_CC, &string) == B_OK)
|
||||||
fHeaderView->fCc->SetText(string.String());
|
fHeaderView->fCc->SetText(string.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2544,7 +2546,7 @@ TMailWindow::SaveAsDraft()
|
|||||||
if (fHeaderView->fCc != NULL)
|
if (fHeaderView->fCc != NULL)
|
||||||
WriteAttrString(&draft, B_MAIL_ATTR_CC, fHeaderView->fCc->Text());
|
WriteAttrString(&draft, B_MAIL_ATTR_CC, fHeaderView->fCc->Text());
|
||||||
if (fHeaderView->fBcc != NULL)
|
if (fHeaderView->fBcc != NULL)
|
||||||
WriteAttrString(&draft, "MAIL:bcc", fHeaderView->fBcc->Text());
|
WriteAttrString(&draft, B_MAIL_ATTR_BCC, fHeaderView->fBcc->Text());
|
||||||
|
|
||||||
// Add the draft attribute for indexing
|
// Add the draft attribute for indexing
|
||||||
uint32 draftAttr = true;
|
uint32 draftAttr = true;
|
||||||
@@ -2569,7 +2571,7 @@ TMailWindow::SaveAsDraft()
|
|||||||
pathStr.Append(path.Path());
|
pathStr.Append(path.Path());
|
||||||
}
|
}
|
||||||
if (pathStr.Length())
|
if (pathStr.Length())
|
||||||
WriteAttrString(&draft, "MAIL:attachments", pathStr.String());
|
draft.WriteAttrString("MAIL:attachments", &pathStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the MIME Type of the file
|
// Set the MIME Type of the file
|
||||||
@@ -2777,17 +2779,17 @@ TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding)
|
|||||||
fContentView->fTextView->SetText(&file, 0, size);
|
fContentView->fTextView->SetText(&file, 0, size);
|
||||||
|
|
||||||
// Restore Fields from attributes
|
// Restore Fields from attributes
|
||||||
if (ReadAttrString(&node, B_MAIL_ATTR_TO, &string) == B_OK)
|
if (node.ReadAttrString(B_MAIL_ATTR_TO, &string) == B_OK)
|
||||||
fHeaderView->fTo->SetText(string.String());
|
fHeaderView->fTo->SetText(string.String());
|
||||||
if (ReadAttrString(&node, B_MAIL_ATTR_SUBJECT, &string) == B_OK)
|
if (node.ReadAttrString(B_MAIL_ATTR_SUBJECT, &string) == B_OK)
|
||||||
fHeaderView->fSubject->SetText(string.String());
|
fHeaderView->fSubject->SetText(string.String());
|
||||||
if (ReadAttrString(&node, B_MAIL_ATTR_CC, &string) == B_OK)
|
if (node.ReadAttrString(B_MAIL_ATTR_CC, &string) == B_OK)
|
||||||
fHeaderView->fCc->SetText(string.String());
|
fHeaderView->fCc->SetText(string.String());
|
||||||
if (ReadAttrString(&node, "MAIL:bcc", &string) == B_OK)
|
if (node.ReadAttrString(B_MAIL_ATTR_BCC, &string) == B_OK)
|
||||||
fHeaderView->fBcc->SetText(string.String());
|
fHeaderView->fBcc->SetText(string.String());
|
||||||
|
|
||||||
// Restore attachments
|
// Restore attachments
|
||||||
if (ReadAttrString(&node, "MAIL:attachments", &string) == B_OK) {
|
if (node.ReadAttrString("MAIL:attachments", &string) == B_OK) {
|
||||||
BMessage msg(REFS_RECEIVED);
|
BMessage msg(REFS_RECEIVED);
|
||||||
entry_ref enc_ref;
|
entry_ref enc_ref;
|
||||||
|
|
||||||
|
|||||||
@@ -58,25 +58,6 @@ WriteAttrString(BNode* node, const char* attr, const char* value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
ReadAttrString(BNode* node, const char* attr, BString* value)
|
|
||||||
{
|
|
||||||
attr_info attrInfo;
|
|
||||||
|
|
||||||
value->SetTo("");
|
|
||||||
status_t status = node->GetAttrInfo(attr, &attrInfo);
|
|
||||||
if (status < B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
ssize_t size = node->ReadAttr(attr, B_STRING_TYPE, 0,
|
|
||||||
value->LockBuffer(attrInfo.size + 1), attrInfo.size);
|
|
||||||
|
|
||||||
value->UnlockBuffer();
|
|
||||||
|
|
||||||
return size >= 0 ? B_OK : size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//====================================================================
|
//====================================================================
|
||||||
// case-insensitive version of strcmp
|
// case-insensitive version of strcmp
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ class BString;
|
|||||||
|
|
||||||
extern status_t WriteAttrString(BNode* node, const char* attr,
|
extern status_t WriteAttrString(BNode* node, const char* attr,
|
||||||
const char* value);
|
const char* value);
|
||||||
extern status_t ReadAttrString(BNode* node, const char* attr, BString* value);
|
|
||||||
|
|
||||||
|
|
||||||
int32 cistrcmp(const char*, const char*);
|
int32 cistrcmp(const char*, const char*);
|
||||||
|
|||||||
Reference in New Issue
Block a user