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