2265{
2267 gpgme_data_t keydata = NULL;
2268 gpgme_import_result_t impres = NULL;
2269 gpgme_import_status_t st = NULL;
2270 bool any;
2271
2273 if (!fp_in)
2274 {
2276 goto leave;
2277 }
2278
2279
2280 gpgme_error_t err = gpgme_data_new_from_stream(&keydata, fp_in);
2281 if (err != GPG_ERR_NO_ERROR)
2282 {
2283 mutt_error(
_(
"error allocating data object: %s"), gpgme_strerror(err));
2284 goto leave;
2285 }
2286
2287 err = gpgme_op_import(ctx, keydata);
2288 if (err != 0)
2289 {
2290 mutt_error(
_(
"Error importing key: %s"), gpgme_strerror(err));
2291 goto leave;
2292 }
2293
2294
2295 impres = gpgme_op_import_result(ctx);
2296 if (!impres)
2297 {
2298 fputs("oops: no import result returned\n", stdout);
2299 goto leave;
2300 }
2301
2302 for (st = impres->imports; st; st = st->next)
2303 {
2304 if (st->result)
2305 continue;
2306 printf(
"key %s imported (",
NONULL(st->fpr));
2307
2308
2309 any = false;
2310 if (st->status & GPGME_IMPORT_SECRET)
2311 {
2312 printf("secret parts");
2313 any = true;
2314 }
2315 if ((st->status & GPGME_IMPORT_NEW))
2316 {
2317 printf("%snew key", any ? ", " : "");
2318 any = true;
2319 }
2320 if ((st->status & GPGME_IMPORT_UID))
2321 {
2322 printf("%snew uid", any ? ", " : "");
2323 any = true;
2324 }
2325 if ((st->status & GPGME_IMPORT_SIG))
2326 {
2327 printf("%snew sig", any ? ", " : "");
2328 any = true;
2329 }
2330 if ((st->status & GPGME_IMPORT_SUBKEY))
2331 {
2332 printf("%snew subkey", any ? ", " : "");
2333 any = true;
2334 }
2335 printf("%s)\n", any ? "" : "not changed");
2336
2337 }
2338
2339
2340
2341
2342
2343
2344 for (st = impres->imports; st; st = st->next)
2345 {
2346 if (st->result == 0)
2347 continue;
2348 printf(
"key %s import failed: %s\n",
NONULL(st->fpr), gpgme_strerror(st->result));
2349 }
2350 fflush(stdout);
2351
2352leave:
2353 gpgme_release(ctx);
2354 gpgme_data_release(keydata);
2356}
gpgme_ctx_t create_gpgme_context(bool for_smime)
Create a new GPGME context.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)