Fix message ID assignment to use monotonic counter

Co-authored-by: setoelkahfi <1797197+setoelkahfi@users.noreply.github.com>

copilot-swe-agent[bot] committed Oct 13, 2025 at 16:19 UTC 9ef0c075b174d2831acd4902e2ab21fa0c7283f1
1 file changed +8 -1
src/pop3_storage.rs
+8 -1
@@ -24,19 +24,26 @@ impl Pop3Message {
24 #[derive(Debug, Clone)]
25 pub struct Pop3Mailbox {
26 messages: Arc<Mutex<HashMap<String, Vec<Pop3Message>>>>,
27 + next_id: Arc<Mutex<HashMap<String, usize>>>,
28 }
29
30 impl Pop3Mailbox {
31 pub fn new() -> Self {
32 Self {
33 messages: Arc::new(Mutex::new(HashMap::new())),
34 + next_id: Arc::new(Mutex::new(HashMap::new())),
35 }
36 }
37
38 pub fn add_message(&self, username: &str, content: String) {
39 let mut messages = self.messages.lock().unwrap();
40 + let mut next_id = self.next_id.lock().unwrap();
41 +
42 let user_messages = messages.entry(username.to_string()).or_insert_with(Vec::new);
39 - let id = user_messages.len() + 1;
43 + let id_counter = next_id.entry(username.to_string()).or_insert(1);
44 + let id = *id_counter;
45 + *id_counter += 1;
46 +
47 user_messages.push(Pop3Message::new(id, content));
48 }
49