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