Skip to content

Commit

Permalink
Merge pull request #10 from julienXX/add-user-agent
Browse files Browse the repository at this point in the history
Add User-Agent header
  • Loading branch information
miakizz authored Nov 14, 2023
2 parents 567bc21 + cc3512a commit efe2b34
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use string_concat::*;

static USER_AGENT: &str = "mop3";

#[derive(Debug)]
struct Cred {
username: String,
Expand Down Expand Up @@ -212,11 +214,12 @@ fn handle_pop_connection(
let account: CredentialAccount = client
.get(format!("{account_url}/api/v1/accounts/verify_credentials"))
.header("Authorization", "Bearer ".to_owned() + &new_cred.password)
.header("User-Agent", USER_AGENT)
.send()
.expect("Could not verify credentials")
.json()
.expect("Could not parse credentials, your token is likely invalid, or your are sending a token from one server on another one.");

let account_addr = format!("{}@{}", account.username, account_domain);

//Get timeline
Expand All @@ -228,6 +231,7 @@ fn handle_pop_connection(
"{account_url}/api/v1/timelines/home?limit=40{since_id}"
))
.header("Authorization", "Bearer ".to_owned() + &new_cred.password)
.header("User-Agent", USER_AGENT)
.send()
.expect("Could not retrieve timeline")
.text()
Expand Down Expand Up @@ -278,6 +282,7 @@ fn handle_pop_connection(
//Extract info from the JSON response and fetch image
let img = client
.get(get_str(&media["url"]))
.header("User-Agent", USER_AGENT)
.send()
.expect("Couldn't get image");
let filename = get_str(&media["url"])
Expand Down Expand Up @@ -562,6 +567,7 @@ fn handle_smtp_connection(mut stream: TcpStream, args: &Args) {
let upload_res = client
.post(account_url.clone() + "/api/v2/media")
.header("Authorization", auth.clone())
.header("User-Agent", USER_AGENT)
.multipart(form)
.send()
.expect("Error uploading image")
Expand Down Expand Up @@ -594,6 +600,7 @@ fn handle_smtp_connection(mut stream: TcpStream, args: &Args) {
client
.post(account_url + "/api/v1/statuses")
.header("Authorization", auth.clone())
.header("User-Agent", USER_AGENT)
.json(&form)
.send()
);
Expand Down

0 comments on commit efe2b34

Please sign in to comment.