Skip to main content

io_gmail/v1/rest/
labels.rs

1//! Gmail labels (`users.labels`): list, get, create, patch, update,
2//! delete.
3//!
4//! <https://developers.google.com/gmail/api/reference/rest/v1/users.labels>
5
6use alloc::string::String;
7
8use serde::{Deserialize, Serialize};
9
10use crate::v1::rest::messages::GmailMessageListVisibility;
11
12pub mod create;
13pub mod delete;
14pub mod get;
15pub mod list;
16pub mod patch;
17pub mod update;
18
19/// A Gmail label resource.
20///
21/// Labels are used to categorize messages and threads within the
22/// user's mailbox.
23#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
24#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
25#[serde(rename_all = "camelCase")]
26pub struct GmailLabel {
27    /// The immutable id of the label.
28    #[serde(default, skip_serializing_if = "String::is_empty")]
29    pub id: String,
30    /// The display name of the label.
31    #[serde(default, skip_serializing_if = "String::is_empty")]
32    pub name: String,
33    /// The owner type of the label, serialized as `type`.
34    #[serde(default, rename = "type", skip_serializing_if = "Option::is_none")]
35    pub label_type: Option<GmailLabelType>,
36    /// The visibility of messages with this label in the message list.
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub message_list_visibility: Option<GmailMessageListVisibility>,
39    /// The visibility of the label in the label list.
40    #[serde(default, skip_serializing_if = "Option::is_none")]
41    pub label_list_visibility: Option<GmailLabelListVisibility>,
42    /// The total number of messages with the label.
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub messages_total: Option<u64>,
45    /// The number of unread messages with the label.
46    #[serde(default, skip_serializing_if = "Option::is_none")]
47    pub messages_unread: Option<u64>,
48    /// The total number of threads with the label.
49    #[serde(default, skip_serializing_if = "Option::is_none")]
50    pub threads_total: Option<u64>,
51    /// The number of unread threads with the label.
52    #[serde(default, skip_serializing_if = "Option::is_none")]
53    pub threads_unread: Option<u64>,
54    /// The color of the label; only available for user labels.
55    #[serde(default, skip_serializing_if = "Option::is_none")]
56    pub color: Option<GmailLabelColor>,
57}
58
59/// Text and background colors of a user label, given as hex strings.
60#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
61#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
62#[serde(rename_all = "camelCase")]
63pub struct GmailLabelColor {
64    /// The text color of the label as a hex string.
65    #[serde(default, skip_serializing_if = "Option::is_none")]
66    pub text_color: Option<String>,
67    /// The background color of the label as a hex string.
68    #[serde(default, skip_serializing_if = "Option::is_none")]
69    pub background_color: Option<String>,
70}
71
72/// Visibility of the label in the label list of the Gmail web client.
73#[derive(Debug, Clone, Copy, Deserialize, Serialize, Eq, PartialEq)]
74#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
75#[serde(rename_all = "camelCase")]
76pub enum GmailLabelListVisibility {
77    /// The label always shows in the label list.
78    LabelShow,
79    /// The label shows in the label list only when unread.
80    LabelShowIfUnread,
81    /// The label never shows in the label list.
82    LabelHide,
83}
84
85/// Owner of the label: created by Gmail or by the user.
86#[derive(Debug, Clone, Copy, Deserialize, Serialize, Eq, PartialEq)]
87#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
88#[serde(rename_all = "camelCase")]
89pub enum GmailLabelType {
90    /// A label created by Gmail, like INBOX or TRASH.
91    System,
92    /// A label created by the user.
93    User,
94}