static int conv_unicode(char **text, const char *fromChset, const struct unicode_info *toChset) { #if HAVE_UNICODE const struct unicode_info *u=unicode_find(fromChset); if (toChset == NULL) { toChset=unicode_find(unicode_default_chset()); if (!toChset) toChset=&unicode_ISO8859_1; } if (u) { char *p=unicode_xconvert(*text, u, toChset); if (!p) return (-1); free(*text); *text=p; } #endif return (0); }
static int save_unicode(const char *txt, int len, const char *chset, const char *lang, void *arg) { struct decode_unicode_s *p=(struct decode_unicode_s *)arg; char *txts=malloc(len+1); char *s; int i; if (!txts) return (-1); memcpy(txts, txt, len); txts[len]=0; if (!chset) chset=unicode_ISO8859_1.chset; s=unicode_convert_fromchset(txts, chset, p->mychset); if (!s && p->options & RFC2047_DECODE_REPLACE) { const struct unicode_info *uiptr=unicode_find(chset); if (uiptr) s=unicode_xconvert(txts, uiptr, p->mychset); } free(txts); if (s) { save_unicode_text(s, strlen(s), p); free(s); return (0); } if (p->options & RFC2047_DECODE_ABORT) { errno=EINVAL; return (-1); } if (p->options & RFC2047_DECODE_DISCARD) return (0); if (!(p->options & RFC2047_DECODE_NOTAG)) { save_unicode_text(" [", 2, p); save_unicode_text(chset, strlen(chset), p); save_unicode_text("] ", 2, p); if (!(p->options & RFC2047_DECODE_REPLACE)) { save_unicode_text(txt, len, p); return (0); } } if (p->options & RFC2047_DECODE_REPLACE) for (i=0; i < strlen(txt); i++) save_unicode_text("?", 1, p); return (0); }
static char *do_rfc2047_decode_enhanced(const char *text, const char *mychset) { const struct unicode_info *u=unicode_find(mychset); if (!u) u=&unicode_ISO8859_1; return rfc2047_decode_unicode(text, u, 0); }
void gpgcreate() { int linelen; const struct unicode_info *u=unicode_find(sqwebmail_content_charset); const char *newname=cgi("newname"); const char *newaddress=cgi("newaddress"); const char *newcomment=cgi("newcomment"); unsigned skl=atoi(cgi("skeylength")); unsigned ekl=atoi(cgi("ekeylength")); unsigned newexpire=atoi(cgi("newexpire")); char newexpirewhen=*cgi("newexpirewhen"); const char *passphrase, *p; if (!u) u= &unicode_ISO8859_1; if (*newname == 0 || *newaddress == 0 || strchr(newaddress, '@') == 0 || gpgbadarg(newname) || gpgbadarg(newaddress) || gpgbadarg(newcomment) || ekl < 512 || ekl > 2048 || skl < 512 || skl > 1024) { printf("%s\n", getarg("BADARGS")); return; } passphrase=cgi("passphrase"); if (strcmp(passphrase, cgi("passphrase2"))) { printf("%s\n", getarg("PASSPHRASEFAIL")); return; } for (p=passphrase; *p; p++) { if ((int)(unsigned char)*p < ' ') { printf("%s\n", getarg("PASSPHRASEFAIL")); return; } } printf("<PRE CLASS=\"gpgcreate\">"); linelen=0; gpg_genkey(GPGDIR, u, newname, newaddress, newcomment, skl, ekl, newexpire, newexpirewhen, passphrase, &dump_func, &timeout_func, &linelen); printf("</PRE>"); }
int main() { int i; const char *c, *d; for (i=0; unicode_chsetlist[i].chsetname; i++) printf("chset=%s\n", unicode_chsetlist[i].chsetname); c=unicode_default_chset(); d=unicode_find(c)->chset; printf("default_chset=%s\n", c); printf("real_default_chset=%s\n", d); exit(0); return (0); }
static void listpubsec(int flag, int (*callback_func)(const char *, const char *, const char *, int, struct gpg_list_info *), const char *default_key ) { int rc; struct gpg_list_info gli; const struct unicode_info *u=unicode_find(sqwebmail_content_charset); struct listinfo li; if (!u) u= &unicode_ISO8859_1; li.issecret=flag; li.default_key=default_key; memset(&gli, 0, sizeof(gli)); gli.charset=u; gli.disabled_msg=getarg("DISABLED"); gli.revoked_msg=getarg("REVOKED"); gli.expired_msg=getarg("EXPIRED"); gli.voidarg= &li; gpginiterr(); rc=gpg_listkeys(GPGDIR, flag, callback_func, gpg_error, &gli); if (rc) { dump_error(); } }