Author: kirilla Date: 2011-04-01 08:18:49 +0200 (Fri, 01 Apr 2011) New Revision: 41159 Changeset: https://dev.haiku-os.org/changeset/41159 Ticket: https://dev.haiku-os.org/ticket/7372 Modified: haiku/trunk/headers/os/mail/E-mail.h haiku/trunk/src/apps/mail/Header.cpp haiku/trunk/src/apps/mail/MailApp.cpp haiku/trunk/src/apps/mail/MailSupport.cpp haiku/trunk/src/apps/mail/MailWindow.cpp haiku/trunk/src/apps/mail/Utilities.cpp haiku/trunk/src/apps/mail/Utilities.h Log: 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. Modified: haiku/trunk/headers/os/mail/E-mail.h =================================================================== --- haiku/trunk/headers/os/mail/E-mail.h 2011-04-01 02:07:48 UTC (rev 41158) +++ haiku/trunk/headers/os/mail/E-mail.h 2011-04-01 06:18:49 UTC (rev 41159) @@ -19,6 +19,7 @@ #define B_MAIL_ATTR_PRIORITY "MAIL:priority" // indexed string #define B_MAIL_ATTR_TO "MAIL:to" // 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_SUBJECT "MAIL:subject" // indexed string #define B_MAIL_ATTR_REPLY "MAIL:reply" // indexed string Modified: haiku/trunk/src/apps/mail/Header.cpp =================================================================== --- haiku/trunk/src/apps/mail/Header.cpp 2011-04-01 02:07:48 UTC (rev 41158) +++ haiku/trunk/src/apps/mail/Header.cpp 2011-04-01 06:18:49 UTC (rev 41159) @@ -548,11 +548,11 @@ continue; 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; BString address; - ReadAttrString(&file, "META:email", &address); + file.ReadAttrString("META:email", &address); // avoid adding an empty address if (address.Length() == 0) @@ -822,7 +822,7 @@ attr = buffer; BString address; - ReadAttrString(&node, buffer, &address); + node.ReadAttrString(buffer, &address); if (address.Length() <= 0) continue; @@ -846,13 +846,13 @@ } BString email; - ReadAttrString(&file,attr.String(),&email); + file.ReadAttrString(attr.String(), &email); // we got something... if (email.Length() > 0) { // see if we can get a username as well BString name; - ReadAttrString(&file, "META:name", &name); + file.ReadAttrString("META:name", &name); BString address; if (name.Length() == 0) { @@ -912,7 +912,7 @@ display = address; - ReadAttrString(&node, "META:name", &name); + node.ReadAttrString("META:name", &name); if (name.Length() > 0) { display = ""; display << "\"" << name << "\" <" << address << ">"; @@ -1064,7 +1064,7 @@ // Does the file have a group attribute? OK to have none. BString groups; const char *kNoGroup = "NoGroup!"; - ReadAttrString(&file, "META:group", &groups); + file.ReadAttrString("META:group", &groups); if (groups.Length() <= 0) groups = kNoGroup; @@ -1142,10 +1142,10 @@ } BString name; - ReadAttrString(&file, "META:name", &name); + file.ReadAttrString("META:name", &name); BString email; - ReadAttrString(&file, "META:email", &email); + file.ReadAttrString("META:email", &email); if (email.Length() != 0 || name.Length() != 0) AddPersonItem(&ref, node, name, email, NULL, groupMenu, superItem); @@ -1154,7 +1154,7 @@ for (int16 i = 2; i < 6; i++) { char attr[16]; 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); } } while (groups.Length() > 0); Modified: haiku/trunk/src/apps/mail/MailApp.cpp =================================================================== --- haiku/trunk/src/apps/mail/MailApp.cpp 2011-04-01 02:07:48 UTC (rev 41158) +++ haiku/trunk/src/apps/mail/MailApp.cpp 2011-04-01 06:18:49 UTC (rev 41159) @@ -253,10 +253,10 @@ { msg->FindRef("ref", &ref); BNode file(&ref); - BString string = ""; + BString string; 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); break; @@ -1088,10 +1088,10 @@ BFile file; if (!resend && ref && file.SetTo(ref, O_RDONLY) == B_OK) { BString name; - if (ReadAttrString(&file, B_MAIL_ATTR_NAME, &name) == B_OK) { + if (file.ReadAttrString(B_MAIL_ATTR_NAME, &name) == B_OK) { title << name; BString subject; - if (ReadAttrString(&file, B_MAIL_ATTR_SUBJECT, &subject) == B_OK) + if (file.ReadAttrString(B_MAIL_ATTR_SUBJECT, &subject) == B_OK) title << " -> " << subject; } } Modified: haiku/trunk/src/apps/mail/MailSupport.cpp =================================================================== --- haiku/trunk/src/apps/mail/MailSupport.cpp 2011-04-01 02:07:48 UTC (rev 41158) +++ haiku/trunk/src/apps/mail/MailSupport.cpp 2011-04-01 06:18:49 UTC (rev 41159) @@ -150,11 +150,11 @@ message->AddString("attribute", value.String()); - char name[256]; + BString name; if (format != NULL) - snprintf(name, sizeof(name), format, value.String()); + name.SetToFormat(format, value.String()); else - strlcpy(name, value.String(), sizeof(name)); + name = value; if (index < 9 && !popup) menu->AddItem(new BMenuItem(name, message, '1' + index)); Modified: haiku/trunk/src/apps/mail/MailWindow.cpp =================================================================== --- haiku/trunk/src/apps/mail/MailWindow.cpp 2011-04-01 02:07:48 UTC (rev 41158) +++ haiku/trunk/src/apps/mail/MailWindow.cpp 2011-04-01 06:18:49 UTC (rev 41159) @@ -47,8 +47,10 @@ #include <Clipboard.h> #include <Debug.h> #include <E-mail.h> +#include <File.h> #include <InterfaceKit.h> #include <Locale.h> +#include <Node.h> #include <PathMonitor.h> #include <Roster.h> #include <Screen.h> @@ -181,8 +183,6 @@ if (messenger != NULL) fTrackerMessenger = *messenger; - char str[256]; - char status[272]; float height; BMenu* menu; BMenu* subMenu; @@ -246,16 +246,18 @@ if (flag == B_UNREAD) { subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Leave as New"), 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 { - if (strlen(str)) - sprintf(status, B_TRANSLATE("Leave as '%s'"), str); + BString status; + file.ReadAttrString(B_MAIL_ATTR_STATUS, &status); + + BString label; + if (status.Length() > 0) + label.SetToFormat(B_TRANSLATE("Leave as '%s'"), + status.String()); else - sprintf(status, B_TRANSLATE("Leave same")); - subMenu->AddItem(item = new BMenuItem(status, + label = B_TRANSLATE("Leave same"); + + subMenu->AddItem(item = new BMenuItem(label.String(), new BMessage(B_QUIT_REQUESTED), 'W')); AddShortcut('W', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kMsgQuitAndKeepAllStatus)); @@ -1211,7 +1213,7 @@ BString string = "could not read"; BNode node(fRef); 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()); } @@ -2029,15 +2031,15 @@ if (file.InitCheck() == B_OK) { BString string; 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()); 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()); 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()); } @@ -2544,7 +2546,7 @@ if (fHeaderView->fCc != NULL) WriteAttrString(&draft, B_MAIL_ATTR_CC, fHeaderView->fCc->Text()); 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 uint32 draftAttr = true; @@ -2569,7 +2571,7 @@ pathStr.Append(path.Path()); } if (pathStr.Length()) - WriteAttrString(&draft, "MAIL:attachments", pathStr.String()); + draft.WriteAttrString("MAIL:attachments", &pathStr); } // Set the MIME Type of the file @@ -2777,17 +2779,17 @@ fContentView->fTextView->SetText(&file, 0, size); // 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()); - 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()); - 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()); - if (ReadAttrString(&node, "MAIL:bcc", &string) == B_OK) + if (node.ReadAttrString(B_MAIL_ATTR_BCC, &string) == B_OK) fHeaderView->fBcc->SetText(string.String()); // Restore attachments - if (ReadAttrString(&node, "MAIL:attachments", &string) == B_OK) { + if (node.ReadAttrString("MAIL:attachments", &string) == B_OK) { BMessage msg(REFS_RECEIVED); entry_ref enc_ref; Modified: haiku/trunk/src/apps/mail/Utilities.cpp =================================================================== --- haiku/trunk/src/apps/mail/Utilities.cpp 2011-04-01 02:07:48 UTC (rev 41158) +++ haiku/trunk/src/apps/mail/Utilities.cpp 2011-04-01 06:18:49 UTC (rev 41159) @@ -58,25 +58,6 @@ } -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 // Modified: haiku/trunk/src/apps/mail/Utilities.h =================================================================== --- haiku/trunk/src/apps/mail/Utilities.h 2011-04-01 02:07:48 UTC (rev 41158) +++ haiku/trunk/src/apps/mail/Utilities.h 2011-04-01 06:18:49 UTC (rev 41159) @@ -44,7 +44,6 @@ extern status_t WriteAttrString(BNode* node, const char* attr, const char* value); -extern status_t ReadAttrString(BNode* node, const char* attr, BString* value); int32 cistrcmp(const char*, const char*);