BMailMessage object and configures it based on the user's inputs by setting the "To," "Subject," and other header fields appropriately, and by storing the message content into the BMailMessage.BMailMessage object's Send() function to tell the mail daemon to send the message.check_for_mail() function is called (either automatically or explicitly), the daemon sends the message via SMTP, then changes the message's status attribute to "Sent". This is done for all mail messages whose status is "Pending".Constant | Attribute Name | Description |
|---|---|---|
B_MAIL_ATTR_NAME | MAIL:name | Name of the mail file. |
B_MAIL_ATTR_STATUS | MAIL:status | Message status. |
B_MAIL_ATTR_PRIOIRITY | MAIL:priority | "Priority" field value. |
B_MAIL_ATTR_TO | MAIL:to | "To" field value. |
B_MAIL_ATTR_CC | MAIL:cc | "Cc" field value. |
B_MAIL_ATTR_FROM | MAIL:from | "From" field value. |
B_MAIL_ATTR_SUBJECT | MAIL:subject | "Subject" field value. |
B_MAIL_ATTR_REPLY | MAIL:reply | "Reply-to" field value. |
B_MAIL_ATTR_WHEN | MAIL:when | "When" field value. |
B_MAIL_ATTR_FLAGS | MAIL:flags | Message flags. |
B_MAIL_ATTR_RECIPIENTS | MAIL:recipients | List of message recipients. |
B_MAIL_ATTR_MIME | MAIL:mime | The MIME version used. |
B_MAIL_ATTR_HEADER | MAIL:header_length | Length of the message header. |
B_MAIL_ATTR_CONTENT | MAIL:content_length | Length of the message content. |
B_MAIL_ATTR_NAME is a string that identifies the name of the sender.B_MAIL_ATTR_STATUS is a string that identifies the status of the message. Possible values are:| Status String | Description |
|---|---|
| "Error" | An error occurred trying to send the message. |
| "New" | The message has not been read yet. |
| "Pending" | The message has not been sent yet. |
| "Read" | The message has been read. |
| "Sent" | The message has been sent. |
B_MAIL_ATTR_PRIORITY is a string that contains the value of the Priority field in the message.B_MAIL_ATTR_TO, B_MAIL_ATTR_FROM, and B_MAIL_ATTR_REPLY are strings that contain the primary recipient's e-mail address, the sender's e-mail address, and the sender's reply-to address.B_MAIL_ATTR_CC contains the addresses to whom the message is carbon copied.B_MAIL_ATTR_SUBJECT is a string containing the subject of the message.B_MAIL_ATTR_WHEN is a BeOS time field (B_TIME_TYPE) containing the message's "When" field.B_MAIL_ATTR_FLAGS contains 32-bit integer (int32) flags which can be any combination of the following values:| Flag | Description |
|---|---|
B_MAIL_PENDING | Message is waiting to be sent. |
B_MAIL_SENT | Message has been sent. |
B_MAIL_SAVE | Mail will be saved after being sent. |
B_MAIL_ATTR_FLAGS attribute is BeOS-specific.B_MAIL_ATTR_RECIPIENTS contains a list of all recipients of the message (primary, cc, and bcc), but is only valid for outgoing messages (this attribute doesn't exist on incoming messages).B_MAIL_ATTR_MIME contains a string that defines the version number of the MIME specification used to transmit any enclosures attached to the file. This attribute is only present if the file has one or more enclosures.B_MAIL_ATTR_HEADER and B_MAIL_ATTR_CONTENT contain the lengths, in bytes, of the header and content portions of the message. They're both int32 type data.void main(void) { BQuery query; BNode node; BVolume vol; BVolumeRoster vroster; entry_ref ref; char buf[256]; int32 message_count = 0; vroster.GetBootVolume(&vol); query.SetVolume(&vol);
if (query.SetPredicate("MAIL:status = New") != B_OK) { printf("Error: can't set query predicate.n"); return; }
B_MAIL_ATTR_STATUS attribute (called "MAIL:status") having a string value of "New". If an error occurs, the program prints an error end returns.if (query.Fetch() != B_OK) { printf("Error: new mail query failed.n"); return; }
while (query.GetNextRef(&ref) == B_OK) { message_count++; // Increment message counter
if (node.SetTo(&ref) != B_OK) { printf("Error: error scanning new messages.n"); return; }
buf[0] = '0'; // If error, use empty string node.ReadAttr(B_MAIL_ATTR_FROM, B_STRING_TYPE, 0, buf, 255); buf[20] = '0'; // Truncate to 20 characters printf("%3d From: %-20s", message_count, buf);
ReadAttr() function to read the B_MAIL_ATTR_FROM attribute into the buffer. We then truncate the read string to 20 characters for display purposes (to make it fit into the table we're outputting) and print the message number and sender information.buf[0] = '0'; // If error, use empty string node.ReadAttr(B_MAIL_ATTR_SUBJECT, B_STRING_TYPE, 0, buf, 255); buf[40] = '0'; // Truncate to 40 characters printf(" Sub: %sn", buf); }
B_MAIL_ATTR_SUBJECT attribute is read into it. This string is truncated to 40 characters, then printed.GetNextRef() returns an error.if (message_count) { printf("%d new messages.n", message_count); } else { printf("No new messages.n"); } }
GetAttrInfo() function:BMimeType mime; BMessage message; mime.SetTo(B_MAIL_TYPE); mime.GetAttrInfo(&message);
| Message Item | Description |
|---|---|
| "attr:public_name" | The user-readable name of the attribute. |
| "attr:name" | The attribute name used for BNode and fs_attr_* calls. |
| "attr:type" | The type of data the attribute contains. |
printf("Public name: %sn", FindString("attr:public_name", 1)); printf("Name: %sn", FindString("attr:name", 1));
Public name: Subject Name: MAIL:subject
BMessage:Find...() function returns NULL or B_BAD_INDEX.BMimeType class and the File Type database, see BMimeType in The Storage Kit.