imap-utf7.c revision fbfbd2c08d117dde4ba130350bf446d4438cd1ec
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde/* Copyright (c) 2008-2009 Dovecot authors, see the included COPYING file */
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde#include "lib.h"
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen#include "str.h"
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen#include "imap-utf7.h"
c5a6a6565be93224fc26522eda855b0990f256e8Timo Sirainen
c5a6a6565be93224fc26522eda855b0990f256e8Timo Sirainen#include <stdio.h>
c5a6a6565be93224fc26522eda855b0990f256e8Timo Sirainen
c5a6a6565be93224fc26522eda855b0990f256e8Timo Sirainenint main(int argc ATTR_UNUSED, const char *argv[])
c5a6a6565be93224fc26522eda855b0990f256e8Timo Sirainen{
c5a6a6565be93224fc26522eda855b0990f256e8Timo Sirainen string_t *dest;
c5a6a6565be93224fc26522eda855b0990f256e8Timo Sirainen bool reverse = FALSE;
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen int ret;
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen lib_init();
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen if (argv[1] != NULL && strcmp(argv[1], "-r") == 0) {
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen reverse = TRUE;
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde argv++;
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde }
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde
9f10cc61ec303351b43e54155c86699ef53cb8beTimo Sirainen if (argv[1] == NULL) {
aba994a4e79a020b4748e0ceffc194e5a18e1d1aTimo Sirainen fprintf(stderr, "Usage: %s [-r] <string>\n", argv[0]);
e438c85a6b0f77889e25913bbbba808d6078282dStephan Bosch return 1;
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde }
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde
64bfe7b4a42512971db154937905dfa2bdb9cf2cTimo Sirainen dest = t_str_new(256);
c5a6a6565be93224fc26522eda855b0990f256e8Timo Sirainen ret = reverse ?
64bfe7b4a42512971db154937905dfa2bdb9cf2cTimo Sirainen imap_utf8_to_utf7(argv[1], dest) :
fc71e94957d0c2959a609450a2f303640d681858Sascha Wilde imap_utf7_to_utf8(argv[1], dest);
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen if (ret < 0) {
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen fprintf(stderr, "Invalid input\n");
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen return 1;
64bfe7b4a42512971db154937905dfa2bdb9cf2cTimo Sirainen }
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen printf("%s\n", str_c(dest));
9f10cc61ec303351b43e54155c86699ef53cb8beTimo Sirainen return 0;
9f10cc61ec303351b43e54155c86699ef53cb8beTimo Sirainen}
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen