mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
Make dc_extract_grpid_from_rfc724_mid take/return &str instead of String
This commit is contained in:
committed by
Floris Bruynooghe
parent
b74a86f617
commit
45eec35e6e
@@ -949,7 +949,7 @@ unsafe fn create_or_lookup_group(
|
|||||||
let fld_message_id: *mut mailimf_message_id = (*field).fld_data.fld_message_id;
|
let fld_message_id: *mut mailimf_message_id = (*field).fld_data.fld_message_id;
|
||||||
if !fld_message_id.is_null() {
|
if !fld_message_id.is_null() {
|
||||||
if let Some(_grpid) =
|
if let Some(_grpid) =
|
||||||
dc_extract_grpid_from_rfc724_mid(to_string((*fld_message_id).mid_value))
|
dc_extract_grpid_from_rfc724_mid(as_str((*fld_message_id).mid_value))
|
||||||
{
|
{
|
||||||
grpid = to_cstring(_grpid);
|
grpid = to_cstring(_grpid);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -803,7 +803,7 @@ pub unsafe fn dc_create_outgoing_rfc724_mid(
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dc_extract_grpid_from_rfc724_mid(mid: String) -> Option<String> {
|
pub fn dc_extract_grpid_from_rfc724_mid(mid: &str) -> Option<&str> {
|
||||||
/* extract our group ID from Message-IDs as `Gr.12345678901.morerandom@domain.de`; "12345678901" is the wanted ID in this example. */
|
/* extract our group ID from Message-IDs as `Gr.12345678901.morerandom@domain.de`; "12345678901" is the wanted ID in this example. */
|
||||||
if !(mid.len() > 8 && mid.starts_with("Gr.")) {
|
if !(mid.len() > 8 && mid.starts_with("Gr.")) {
|
||||||
return None;
|
return None;
|
||||||
@@ -813,7 +813,7 @@ pub fn dc_extract_grpid_from_rfc724_mid(mid: String) -> Option<String> {
|
|||||||
if let Some(grpid_len) = mid_without_offset.find('.') {
|
if let Some(grpid_len) = mid_without_offset.find('.') {
|
||||||
/* strict length comparison, the 'Gr.' magic is weak enough */
|
/* strict length comparison, the 'Gr.' magic is weak enough */
|
||||||
if grpid_len == 11 || grpid_len == 16 {
|
if grpid_len == 11 || grpid_len == 16 {
|
||||||
return Some(mid_without_offset.get(0..grpid_len).unwrap().to_string());
|
return Some(mid_without_offset.get(0..grpid_len).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -826,9 +826,9 @@ pub unsafe fn dc_extract_grpid_from_rfc724_mid_list(list: *const clist) -> *mut
|
|||||||
let mut cur: *mut clistiter = (*list).first;
|
let mut cur: *mut clistiter = (*list).first;
|
||||||
while !cur.is_null() {
|
while !cur.is_null() {
|
||||||
let mid = if !cur.is_null() {
|
let mid = if !cur.is_null() {
|
||||||
to_string((*cur).data as *const libc::c_char)
|
as_str((*cur).data as *const libc::c_char)
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(grpid) = dc_extract_grpid_from_rfc724_mid(mid) {
|
if let Some(grpid) = dc_extract_grpid_from_rfc724_mid(mid) {
|
||||||
@@ -2114,24 +2114,24 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_dc_extract_grpid_from_rfc724_mid() {
|
fn test_dc_extract_grpid_from_rfc724_mid() {
|
||||||
// Should return 0 if we pass invalid mid
|
// Should return 0 if we pass invalid mid
|
||||||
let str = "foobar".to_string();
|
let str = "foobar";
|
||||||
let grpid = dc_extract_grpid_from_rfc724_mid(str);
|
let grpid = dc_extract_grpid_from_rfc724_mid(str);
|
||||||
assert_eq!(grpid, None);
|
assert_eq!(grpid, None);
|
||||||
|
|
||||||
// Should return 0 if grpid has a length which is not 11 or 16
|
// Should return 0 if grpid has a length which is not 11 or 16
|
||||||
let str = "Gr.12345678.morerandom@domain.de".to_string();
|
let str = "Gr.12345678.morerandom@domain.de";
|
||||||
let grpid = dc_extract_grpid_from_rfc724_mid(str);
|
let grpid = dc_extract_grpid_from_rfc724_mid(str);
|
||||||
assert_eq!(grpid, None);
|
assert_eq!(grpid, None);
|
||||||
|
|
||||||
// Should return extracted grpid for grpid with length of 11
|
// Should return extracted grpid for grpid with length of 11
|
||||||
let str = "Gr.12345678901.morerandom@domain.de".to_string();
|
let str = "Gr.12345678901.morerandom@domain.de";
|
||||||
let grpid = dc_extract_grpid_from_rfc724_mid(str);
|
let grpid = dc_extract_grpid_from_rfc724_mid(str);
|
||||||
assert_eq!(grpid, Some("12345678901".to_string()));
|
assert_eq!(grpid, Some("12345678901".to_string()));
|
||||||
|
|
||||||
// Should return extracted grpid for grpid with length of 11
|
// Should return extracted grpid for grpid with length of 11
|
||||||
let str = "Gr.1234567890123456.morerandom@domain.de".to_string();
|
let str = "Gr.1234567890123456.morerandom@domain.de";
|
||||||
let grpid = dc_extract_grpid_from_rfc724_mid(str);
|
let grpid = dc_extract_grpid_from_rfc724_mid(str);
|
||||||
assert_eq!(grpid, Some("1234567890123456".to_string()));
|
assert_eq!(grpid, Some("1234567890123456"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user