Rust Requires Chilkat v11.0.0+
Rust
Outlook -- Copy Mail Folder and Contents to another Mail Folder
See more Outlook Examples
Copy a mailfolder and its contents to another mailfolder.This example applies to: Exchange Online | Office 365 | Hotmail.com | Live.com | MSN.com | Outlook.com | Passport.com
Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Use your previously obtained access token here:
http.set_auth_token("MICROSOFT_GRAPH_ACCESS_TOKEN");
// This example will copy /Inbox/abc/subFolderA and its contents to /Inbox/xyz
// We'll need the folder ids for both source and destination folders..
// Get the folder IDs from the folder map created by this example
let ht_folder_map = chilkat::Hashtable::new();
let sb_map = chilkat::StringBuilder::new();
let _ = sb_map.load_file("qa_data/outlook/folderMap.xml", "utf-8");
let _ = ht_folder_map.add_from_xml_sb(&sb_map);
// Get the IDs for the source and destination folders.
let Ok(src_folder_id) = ht_folder_map.lookup_str("/Inbox/abc/subFolderA") else {
println!("Folder ID not found");
return;
};
let Ok(dst_folder_id) = ht_folder_map.lookup_str("/Inbox/xyz") else {
println!("Destination folder ID not found");
return;
};
// Create a JSON request body with this content:
//
// {
// "DestinationId": "destinationId-value"
// }
let json_request_body = chilkat::JsonObject::new();
let _ = json_request_body.update_string("DestinationId", &dst_folder_id);
let _ = http.set_url_var("src_folder_id", &src_folder_id);
// Copy the source folder to the new location
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://graph.microsoft.com/v1.0/me/mailFolders/{$src_folder_id}/copy", &json_request_body, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
// A 201 response indicates success.
if resp.status_code() == 201 {
println!("Folder copied.");
} else {
println!("Response status code = {}", resp.status_code());
println!("Error: Folder not copied.");
}
// Show the response in both cases..
let json_response = chilkat::JsonObject::new();
json_response.set_emit_compact(false);
let _ = json_response.load(&resp.body_str());
println!("{}", json_response.emit().unwrap_or_default());
// A sample successful JSON response looks like this:
// {
// "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#mailFolder",
// "@odata.type": "#microsoft.graph.mailFolder",
// "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAuAAADsVyfxjDU406Ic4X7ill8xAEA5_vF7TKKdE6bGCRqXyl2PQAAAM6JqMAAAAA=",
// "displayName": "subFolderA",
// "parentFolderId": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgAuAAADsVyfxjDU406Ic4X7ill8xAEA5_vF7TKKdE6bGCRqXyl2PQAAAL8huwEAAAA=",
// "childFolderCount": 1,
// "unreadItemCount": 0,
// "totalItemCount": 0
// }