Commit c948b18a c948b18a102b660bab5a74f4615ea6c7a496419d by Alain Magloire

message add the header count part of the bytes being written.

1 parent 543739df
...@@ -108,7 +108,8 @@ attribute_set_recent (attribute_t attr) ...@@ -108,7 +108,8 @@ attribute_set_recent (attribute_t attr)
108 return EINVAL; 108 return EINVAL;
109 if (attr == NULL) 109 if (attr == NULL)
110 { 110 {
111 attr->flag = 0; 111 attr->flag &= ~MU_ATTRIBUTE_READ;
112 attr->flag &= ~MU_ATTRIBUTE_SEEN;
112 return 0; 113 return 0;
113 } 114 }
114 return EACCES; 115 return EACCES;
...@@ -167,7 +168,10 @@ attribute_is_recent (attribute_t attr) ...@@ -167,7 +168,10 @@ attribute_is_recent (attribute_t attr)
167 { 168 {
168 if (attr == NULL) 169 if (attr == NULL)
169 return 0; 170 return 0;
170 return attr->flag == 0; 171 /* something is recent when it is not read and not seen. */
172 return (attr->flag == 0
173 || ! ((attr->flag & MU_ATTRIBUTE_SEEN)
174 && (attr->flag & MU_ATTRIBUTE_READ));
171 } 175 }
172 176
173 int 177 int
...@@ -229,7 +233,7 @@ attribute_unset_recent (attribute_t attr) ...@@ -229,7 +233,7 @@ attribute_unset_recent (attribute_t attr)
229 { 233 {
230 if (attr == NULL) 234 if (attr == NULL)
231 return 0; 235 return 0;
232 attr->flag |= MU_ATTRIBUTE_SEEN; 236 attr-> |= MU_ATTRIBUTE_SEEN;
233 return 0; 237 return 0;
234 } 238 }
235 239
......
...@@ -37,13 +37,13 @@ struct _attribute ...@@ -37,13 +37,13 @@ struct _attribute
37 size_t flag; 37 size_t flag;
38 }; 38 };
39 39
40 #define MU_ATTRIBUTE_SEEN ((int)1) 40 #define MU_ATTRIBUTE_ANSWERED 0x01
41 #define MU_ATTRIBUTE_ANSWERED (MU_ATTRIBUTE_SEEN << 1) 41 #define MU_ATTRIBUTE_FLAGGED 0x02
42 #define MU_ATTRIBUTE_FLAGGED (MU_ATTRIBUTE_ANSWERED << 1) 42 #define MU_ATTRIBUTE_DELETED 0x04
43 #define MU_ATTRIBUTE_DELETED (MU_ATTRIBUTE_FLAGGED << 1) 43 #define MU_ATTRIBUTE_DRAFT 0x08
44 #define MU_ATTRIBUTE_DRAFT (MU_ATTRIBUTE_DELETED << 1) 44 #define MU_ATTRIBUTE_SEEN 0x10
45 #define MU_ATTRIBUTE_RECENT (MU_ATTRIBUTE_DRAFT << 1) 45 #define MU_ATTRIBUTE_READ 0x20
46 #define MU_ATTRIBUTE_READ (MU_ATTRIBUTE_RECENT << 1) 46 #define MU_ATTRIBUTE_RECENT 0x00
47 47
48 #ifdef __cplusplus 48 #ifdef __cplusplus
49 } 49 }
......
...@@ -559,7 +559,8 @@ message_write (stream_t os, const char *buf, size_t buflen, ...@@ -559,7 +559,8 @@ message_write (stream_t os, const char *buf, size_t buflen,
559 off_t off, size_t *pnwrite) 559 off_t off, size_t *pnwrite)
560 { 560 {
561 message_t msg; 561 message_t msg;
562 int status; 562 int status = 0;
563 size_t bufsize = 0;
563 564
564 if (os == NULL || (msg = os->owner) == NULL) 565 if (os == NULL || (msg = os->owner) == NULL)
565 return EINVAL; 566 return EINVAL;
...@@ -629,11 +630,13 @@ message_write (stream_t os, const char *buf, size_t buflen, ...@@ -629,11 +630,13 @@ message_write (stream_t os, const char *buf, size_t buflen,
629 msg->hdr_buf = thdr; 630 msg->hdr_buf = thdr;
630 memcpy (msg->hdr_buf + msg->hdr_buflen, buf, buflen); 631 memcpy (msg->hdr_buf + msg->hdr_buflen, buf, buflen);
631 msg->hdr_buflen += buflen; 632 msg->hdr_buflen += buflen;
633 buflen = 0;
632 } 634 }
633 else if (buflen > 0) /* in the body */ 635 else if (buflen > 0) /* in the body */
634 { 636 {
635 stream_t bs; 637 stream_t bs;
636 body_t body; 638 body_t body;
639 size_t written = 0;
637 if ((status = message_get_body (msg, &body)) != 0 || 640 if ((status = message_get_body (msg, &body)) != 0 ||
638 (status = body_get_stream (msg->body, &bs)) != 0) 641 (status = body_get_stream (msg->body, &bs)) != 0)
639 { 642 {
...@@ -646,9 +649,12 @@ message_write (stream_t os, const char *buf, size_t buflen, ...@@ -646,9 +649,12 @@ message_write (stream_t os, const char *buf, size_t buflen,
646 off = 0; 649 off = 0;
647 else 650 else
648 off -= msg->hdr_buflen; 651 off -= msg->hdr_buflen;
649 return stream_write (bs, buf, buflen, off, pnwrite); 652 status = stream_write (bs, buf, buflen, off, &written);
653 buflen -= written;
650 } 654 }
651 return 0; 655 if (pnwrite)
656 *pnwrite = busize - buflen;
657 return status;
652 } 658 }
653 659
654 static int 660 static int
......