text
stringlengths
0
357
/* got enough receipts :-) */
dc_update_msg_state(context, *ret_msg_id, DC_STATE_OUT_MDN_RCVD);
read_by_all = 1;
cleanup:
sqlite3_finalize(stmt);
return read_by_all;
}
```
Filename: dc_oauth2.c
```c
#include "dc_context.h"
#include "dc_oauth2.h"
#include "dc_jsmn.h"
typedef struct oauth2_t {
char* client_id;
char* get_code;
char* init_token;
char* refresh_token;
char* get_userinfo;
} oauth2_t;
static oauth2_t* get_info(const char* addr)
{
oauth2_t* oauth2 = NULL;
char* addr_normalized = NULL;
const char* domain = NULL;
addr_normalized = dc_addr_normalize(addr);
domain = strchr(addr_normalized, '@');
if (domain==NULL || domain[0]==0) {
goto cleanup;
}
domain++;
if (strcasecmp(domain, "gmail.com")==0
|| strcasecmp(domain, "googlemail.com")==0)
{
// see https://developers.google.com/identity/protocols/OAuth2InstalledApp
oauth2 = calloc(1, sizeof(oauth2_t));
oauth2->client_id = "959970109878-4mvtgf6feshskf7695nfln6002mom908.apps.googleusercontent.com";
oauth2->get_code = "https://accounts.google.com/o/oauth2/auth"
"?client_id=$CLIENT_ID"
"&redirect_uri=$REDIRECT_URI"
"&response_type=code"
"&scope=https%3A%2F%2Fmail.google.com%2F%20email"
"&access_type=offline";
oauth2->init_token = "https://accounts.google.com/o/oauth2/token"
"?client_id=$CLIENT_ID"
"&redirect_uri=$REDIRECT_URI"
"&code=$CODE"
"&grant_type=authorization_code";
oauth2->refresh_token = "https://accounts.google.com/o/oauth2/token"
"?client_id=$CLIENT_ID"
"&redirect_uri=$REDIRECT_URI"
"&refresh_token=$REFRESH_TOKEN"
"&grant_type=refresh_token";
oauth2->get_userinfo = "https://www.googleapis.com/oauth2/v1/userinfo"
"?alt=json"
"&access_token=$ACCESS_TOKEN";
}
else if (strcasecmp(domain, "yandex.com")==0
|| strcasecmp(domain, "yandex.ru")==0
|| strcasecmp(domain, "yandex.ua")==0)
{
// see https://tech.yandex.com/oauth/doc/dg/reference/auto-code-client-docpage/
oauth2 = calloc(1, sizeof(oauth2_t));
oauth2->client_id = "c4d0b6735fc8420a816d7e1303469341";
oauth2->get_code = "https://oauth.yandex.com/authorize"
"?client_id=$CLIENT_ID"
"&response_type=code"
"&scope=mail%3Aimap_full%20mail%3Asmtp"
"&force_confirm=true";
oauth2->init_token = "https://oauth.yandex.com/token"
"?grant_type=authorization_code"
"&code=$CODE"
"&client_id=$CLIENT_ID"
"&client_secret=58b8c6e94cf44fbe952da8511955dacf";
oauth2->refresh_token = "https://oauth.yandex.com/token"
"?grant_type=refresh_token"
"&refresh_token=$REFRESH_TOKEN"
"&client_id=$CLIENT_ID"
"&client_secret=58b8c6e94cf44fbe952da8511955dacf";
}
cleanup:
free(addr_normalized);
return oauth2;
}
static void replace_in_uri(char** uri, const char* key, const char* value)
{
if (uri && key && value) {