MOBI_RET mobi_get_opf_from_exth(OPFmetadata *metadata, const MOBIData *m) {
    if (m == NULL) {
        debug_print("%s", "Mobi structure not initialized\n");
        return MOBI_INIT_FAILED;
    }
    if (m->eh == NULL) {
        return MOBI_INIT_FAILED;
    }
    MOBIExthHeader *curr = m->eh;
    /* iterate through EXTH records */
    while (curr != NULL) {
        switch (curr->tag) {
                /* <dc-metadata/> */
            case EXTH_DESCRIPTION:
                mobi_opf_fill_tag(m, curr, &metadata->dc_meta->description);
                break;
            case EXTH_LANGUAGE:
                mobi_opf_fill_tag(m, curr, &metadata->dc_meta->language);
                break;
            case EXTH_PUBLISHER:
                mobi_opf_fill_tag(m, curr, &metadata->dc_meta->publisher);
                break;
            case EXTH_RIGHTS:
                mobi_opf_fill_tag(m, curr, &metadata->dc_meta->rights);
                break;
            case EXTH_SOURCE:
                mobi_opf_fill_tag(m, curr, &metadata->dc_meta->source);
                break;
            case EXTH_TITLE:
            case EXTH_UPDATEDTITLE:
                mobi_opf_fill_tag(m, curr, &metadata->dc_meta->title);
                break;
            case EXTH_TYPE:
                mobi_opf_fill_tag(m, curr, &metadata->dc_meta->type);
                break;
            case EXTH_AUTHOR:
                mobi_opf_copy_tagtype(m, OPFcreator, metadata->dc_meta->creator, value);
                break;
            case EXTH_CONTRIBUTOR:
                mobi_opf_copy_tagtype(m, OPFcreator, metadata->dc_meta->contributor, value);
                break;
            case EXTH_SUBJECT:
                mobi_opf_copy_tagtype(m, OPFsubject, metadata->dc_meta->subject, value);
                break;
            case EXTH_SUBJECTCODE:
                mobi_opf_copy_tagtype(m, OPFsubject, metadata->dc_meta->subject, basic_code);
                break;
            case EXTH_ISBN:
                mobi_opf_copy_tagtype(m, OPFidentifier, metadata->dc_meta->identifier, value);
                mobi_opf_set_tagtype(OPFidentifier, metadata->dc_meta->identifier, scheme, "ISBN");
                break;
            case EXTH_PUBLISHINGDATE:
                mobi_opf_copy_tagtype(m, OPFdate, metadata->dc_meta->date, value);
                mobi_opf_set_tagtype(OPFdate, metadata->dc_meta->date, event, "publication");
                break;
                /* <x-metadata/> */
            case EXTH_ADULT:
                mobi_opf_fill_tag(m, curr, &metadata->x_meta->adult);
                break;
            case EXTH_DICTNAME:
                mobi_opf_fill_tag(m, curr, &metadata->x_meta->dict_short_name);
                break;
            case EXTH_DICTLANGIN:
                mobi_opf_fill_tag(m, curr, &metadata->x_meta->dictionary_in_lang);
                break;
            case EXTH_DICTLANGOUT:
                mobi_opf_fill_tag(m, curr, &metadata->x_meta->dictionary_out_lang);
                break;
            case EXTH_IMPRINT:
                mobi_opf_fill_tag(m, curr, &metadata->x_meta->imprint);
                break;
            case EXTH_REVIEW:
                mobi_opf_fill_tag(m, curr, &metadata->x_meta->review);
                break;
            case EXTH_PRICE:
                mobi_opf_copy_tagtype(m, OPFsrp, metadata->x_meta->srp, value);
                break;
            case EXTH_CURRENCY:
                mobi_opf_copy_tagtype(m, OPFsrp, metadata->x_meta->srp, currency);
                break;
                /* <meta/> */
            case EXTH_FIXEDLAYOUT:
                mobi_opf_copy_meta(m, curr, metadata->meta, "fixed-layout");
                break;
            case EXTH_BOOKTYPE:
                mobi_opf_copy_meta(m, curr, metadata->meta, "book-type");
                break;
            case EXTH_ORIENTATIONLOCK:
                mobi_opf_copy_meta(m, curr, metadata->meta, "orientation-lock");
                break;
            case EXTH_ORIGRESOLUTION:
                mobi_opf_copy_meta(m, curr, metadata->meta, "original-resolution");
                break;
            case EXTH_ZEROGUTTER:
                mobi_opf_copy_meta(m, curr, metadata->meta, "zero-gutter");
                break;
            case EXTH_ZEROMARGIN:
                mobi_opf_copy_meta(m, curr, metadata->meta, "zero-margin");
                break;
            case EXTH_REGIONMAGNI:
                mobi_opf_copy_meta(m, curr, metadata->meta, "region-mag");
                break;
            case EXTH_ALIGNMENT:
                mobi_opf_copy_meta(m, curr, metadata->meta, "primary-writing-mode");
                break;
            case EXTH_OVERRIDEFONTS:
                mobi_opf_copy_meta(m, curr, metadata->meta, "override-kindle-fonts");
                break;
            case EXTH_COVEROFFSET:
                mobi_opf_copy_meta(m, curr, metadata->meta, "cover");
                break;
            default:
                break;
        }
        curr = curr->next;
    }
    return MOBI_SUCCESS;
}