imsg_map/messages.rs
1//! Message listing, retrieval, push, and status operations (`GetMessage`, `PushMessage`, `SetMessageStatus`).
2
3use crate::{params, MapError};
4use bytes::Bytes;
5
6/// Read/unread state filter for `ListMessages`.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ReadStatus {
9 /// Wire value `0x01`; excludes read messages from results.
10 Unread,
11 /// Wire value `0x02`; excludes unread messages from results.
12 Read,
13}
14
15impl ReadStatus {
16 pub(crate) const fn to_wire(self) -> u8 {
17 match self {
18 Self::Unread => 0x01,
19 Self::Read => 0x02,
20 }
21 }
22}
23
24/// Default fetches up to 1024 messages with no filters applied.
25#[derive(Debug, Clone)]
26pub struct ListMessagesFilter {
27 /// Maximum entries to return; capped by the device's own limit.
28 pub max_count: u16,
29 /// Zero-based index of the first entry to return.
30 pub offset: u16,
31 /// Omit to return all messages regardless of read state.
32 pub read_status: Option<ReadStatus>,
33 /// Filter by sender/originator address. Null bytes prohibited.
34 pub originating_address: Option<String>,
35 /// Earliest message timestamp, format `YYYYMMDDTHHMMSS[±HHMM]`. Null bytes prohibited.
36 pub period_begin: Option<String>,
37 /// Latest message timestamp, format `YYYYMMDDTHHMMSS[±HHMM]`. Null bytes prohibited.
38 pub period_end: Option<String>,
39}
40
41impl Default for ListMessagesFilter {
42 fn default() -> Self {
43 Self {
44 max_count: 1024,
45 offset: 0,
46 read_status: None,
47 originating_address: None,
48 period_begin: None,
49 period_end: None,
50 }
51 }
52}
53
54impl ListMessagesFilter {
55 pub(crate) fn to_app_params(&self) -> Result<Bytes, MapError> {
56 Ok(Bytes::from(params::list_messages_params(
57 self.max_count,
58 self.offset,
59 self.read_status.map(ReadStatus::to_wire),
60 self.originating_address.as_deref(),
61 self.period_begin.as_deref(),
62 self.period_end.as_deref(),
63 )?))
64 }
65}
66
67/// One `<msg>` entry in a `MAP-msg-listing` response; absent attributes default to zero/false/empty.
68#[derive(Debug, Clone, PartialEq, Eq)]
69pub struct MessageEntry {
70 /// Opaque device-assigned message handle (hex string).
71 pub handle: String,
72 /// Message subject or first line of body text.
73 pub subject: String,
74 /// Timestamp in MAP format (`YYYYMMDDTHHMMSS[±HHMM]`).
75 pub datetime: String,
76 /// Sender display name; empty if unavailable.
77 pub sender_name: String,
78 /// Sender address (phone number or email).
79 pub sender_addressing: String,
80 /// Recipient display name; empty for received messages.
81 pub recipient_name: String,
82 /// Recipient address; empty for received messages.
83 pub recipient_addressing: String,
84 /// Message type string (`SMS_GSM`, `SMS_CDMA`, `EMAIL`, `MMS`).
85 pub msg_type: String,
86 /// Body size in bytes as reported by the device.
87 pub size: u32,
88 /// Device-reported read state.
89 pub read: bool,
90 /// `true` for outbound messages from this device; `false` for received.
91 pub sent: bool,
92}