static gboolean found_in_addressbook(const gchar *address) { gchar *addr = NULL; gboolean found = FALSE; gint num_addr = 0; if (!address) return FALSE; addr = g_strdup(address); extract_address(addr); num_addr = complete_address(addr); if (num_addr > 1) { /* skip first item (this is the search string itself) */ int i = 1; for (; i < num_addr && !found; i++) { gchar *caddr = get_complete_address(i); extract_address(caddr); if (strcasecmp(caddr, addr) == 0) found = TRUE; g_free(caddr); } } g_free(addr); return found; }
CORE_ADDR generic_read_register_dummy (CORE_ADDR pc, CORE_ADDR fp, int regno) { char *dummy_regs = generic_find_dummy_frame (pc, fp); if (dummy_regs) return extract_address (&dummy_regs[REGISTER_BYTE (regno)], REGISTER_RAW_SIZE (regno)); else return 0; }
enum nss_status _nss_netresolve_gethostbyname3_r(const char *nodename, int family, struct hostent *he, char *bufptr, size_t buflen, int *errnop, int *h_errnop, int32_t *ttlp, char **canonp) { struct addrinfo hints = { .ai_family = family, .ai_socktype = SOCK_RAW, .ai_flags = AI_CANONNAME }; struct buffer_t buffer = { .data = bufptr, .length = buflen, .errnop = errnop }; int status; struct addrinfo *list; int count; status = _nss_netresolve_getaddrinfo(NULL, nodename, NULL, &hints, &list, ttlp); if (status) return NSS_STATUS_UNAVAIL; /* address family */ he->h_addrtype = family; he->h_length = (family == AF_INET) ? 4 : 16; /* pointers to addresses */ count = 0; for (struct addrinfo *item = list; item; item = item->ai_next) count++; if (!(he->h_addr_list = buffer_append(NULL, (count + 1) * sizeof *he->h_addr_list, &buffer))) return NSS_STATUS_TRYAGAIN; /* addresses */ count = 0; for (struct addrinfo *item = list; item; item = item->ai_next) { if (item->ai_family != family) continue; if (!(he->h_addr_list[count] = buffer_append(NULL, he->h_length, &buffer))) return NSS_STATUS_TRYAGAIN; extract_address(item, he->h_addr_list[count]); count++; } /* canonical name */ if (list->ai_canonname) if (!(he->h_name = buffer_append(list->ai_canonname, 0, &buffer))) return NSS_STATUS_TRYAGAIN; return NSS_STATUS_SUCCESS; }
static void select_btn_cb (GtkWidget *widget, gpointer data) { struct select_keys_s *sk = data; int row; gboolean use_key; gpgme_key_t key; cm_return_if_fail (sk); if (!sk->clist->selection) { debug_print ("** nothing selected"); return; } row = GPOINTER_TO_INT(sk->clist->selection->data); key = gtk_cmclist_get_row_data(sk->clist, row); if (key) { gpgme_user_id_t uid; for (uid = key->uids; uid; uid = uid->next) { gchar *raw_mail = NULL; if (!uid->email) continue; raw_mail = g_strdup(uid->email); extract_address(raw_mail); if (sk->pattern && !strcasecmp(sk->pattern, raw_mail)) { g_free(raw_mail); break; } g_free(raw_mail); } if (!uid) uid = key->uids; if ( uid->validity < GPGME_VALIDITY_FULL ) { use_key = use_untrusted(key, uid, sk->proto); if (!use_key) { debug_print ("** Key untrusted, will not encrypt"); return; } } sk->kset = g_realloc(sk->kset, sizeof(gpgme_key_t) * (sk->num_keys + 1)); gpgme_key_ref(key); sk->kset[sk->num_keys] = key; sk->num_keys++; sk->okay = 1; sk->result = KEY_SELECTION_OK; gtk_main_quit (); } }
int get_longjmp_target (CORE_ADDR *pc) { CORE_ADDR jb_addr; char *buf; buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); jb_addr = read_register (A0_REGNUM); if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf, TARGET_PTR_BIT / TARGET_CHAR_BIT)) return 0; *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); return 1; }
static gboolean qr_avatar_update_hook(gpointer source, gpointer data) { AvatarCaptureData *acd = (AvatarCaptureData *)source; debug_print("qr-avatar qr_avatar_update_hook() invoked\n"); if (!strcmp(acd->header, "From:")) { gchar *addr; addr = g_strdup(acd->content); extract_address(addr); debug_print("qr-avatar added '%s'\n", addr); procmsg_msginfo_add_avatar(acd->msginfo, QR_AVATAR_QR_AVATAR, addr); } return FALSE; /* keep getting */ }
enum nss_status _nss_netresolve_gethostbyname4_r(const char *nodename, struct gaih_addrtuple **result, char *bufptr, size_t buflen, int *errnop, int *h_errnop, int32_t *ttlp) { struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_RAW, .ai_flags = AI_CANONNAME }; struct buffer_t buffer = { .data = bufptr, .length = buflen, .errnop = errnop }; int status; struct addrinfo *list; status = _nss_netresolve_getaddrinfo(NULL, nodename, NULL, &hints, &list, ttlp); if (status) return NSS_STATUS_UNAVAIL; /* addresses */ for (struct addrinfo *item = list; item; item = item->ai_next) { if (!(*result = buffer_append(NULL, sizeof **result, &buffer))) return NSS_STATUS_TRYAGAIN; (*result)->family = item->ai_family; extract_address(item, &(*result)->addr); /* canonical name piggybacking on the first address */ if (item == list && list->ai_canonname) if (!((*result)->name = buffer_append(list->ai_canonname, 0, &buffer))) return NSS_STATUS_TRYAGAIN; result = &(*result)->next; } return NSS_STATUS_SUCCESS; }
static gboolean libravatar_header_update_hook(gpointer source, gpointer data) { AvatarCaptureData *acd = (AvatarCaptureData *)source; debug_print("libravatar avatar_header_update invoked\n"); if (!strcmp(acd->header, "From:")) { gchar *a, *lower; a = g_strdup(acd->content); extract_address(a); /* string to lower */ for (lower = a; *lower; lower++) *lower = g_ascii_tolower(*lower); debug_print("libravatar added '%s'\n", a); procmsg_msginfo_add_avatar(acd->msginfo, AVATAR_LIBRAVATAR, a); g_free(a); } return FALSE; /* keep getting */ }
static gpgme_key_t fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t proto) { GtkCMCList *clist; gpgme_ctx_t ctx; gpgme_error_t err; gpgme_key_t key; int running=0; int num_results = 0; gboolean exact_match = FALSE; gpgme_key_t last_key = NULL; gpgme_user_id_t last_uid = NULL; cm_return_val_if_fail (sk, NULL); clist = sk->clist; cm_return_val_if_fail (clist, NULL); debug_print ("select_keys:fill_clist: pattern '%s' proto %d\n", pattern, proto); /*gtk_cmclist_freeze (select_keys.clist);*/ err = gpgme_new (&ctx); g_assert (!err); gpgme_set_protocol(ctx, proto); sk->select_ctx = ctx; update_progress (sk, ++running, pattern); while (gtk_events_pending ()) gtk_main_iteration (); err = gpgme_op_keylist_start (ctx, pattern, 0); if (err) { debug_print ("** gpgme_op_keylist_start(%s) failed: %s", pattern, gpgme_strerror (err)); sk->select_ctx = NULL; gpgme_release(ctx); return NULL; } update_progress (sk, ++running, pattern); while ( !(err = gpgme_op_keylist_next ( ctx, &key )) ) { gpgme_user_id_t uid = key->uids; if (!key->can_encrypt || key->revoked || key->expired || key->disabled) continue; debug_print ("%% %s:%d: insert\n", __FILE__ ,__LINE__ ); set_row (clist, key, proto ); for (; uid; uid = uid->next) { gchar *raw_mail = NULL; if (!uid->email) continue; if (uid->revoked || uid->invalid) continue; raw_mail = g_strdup(uid->email); extract_address(raw_mail); if (!strcasecmp(pattern, raw_mail)) { exact_match = TRUE; last_uid = uid; g_free(raw_mail); break; } g_free(raw_mail); } num_results++; last_key = key; key = NULL; update_progress (sk, ++running, pattern); while (gtk_events_pending ()) gtk_main_iteration (); } if (exact_match == TRUE && num_results == 1) { if (last_key->uids->validity < GPGME_VALIDITY_FULL && !use_untrusted(last_key, last_uid, proto)) exact_match = FALSE; } debug_print ("%% %s:%d: ready\n", __FILE__ ,__LINE__ ); if (gpgme_err_code(err) != GPG_ERR_EOF) { debug_print ("** gpgme_op_keylist_next failed: %s", gpgme_strerror (err)); gpgme_op_keylist_end(ctx); } if (!exact_match || num_results != 1) { sk->select_ctx = NULL; gpgme_release (ctx); } /*gtk_cmclist_thaw (select_keys.clist);*/ return (exact_match == TRUE && num_results == 1 ? last_key:NULL); }
static CORE_ADDR arm_linux_push_arguments (int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr) { char *fp; int argnum, argreg, nstack_size; /* Walk through the list of args and determine how large a temporary stack is required. Need to take care here as structs may be passed on the stack, and we have to to push them. */ nstack_size = -4 * REGISTER_SIZE; /* Some arguments go into A1-A4. */ if (struct_return) /* The struct address goes in A1. */ nstack_size += REGISTER_SIZE; /* Walk through the arguments and add their size to nstack_size. */ for (argnum = 0; argnum < nargs; argnum++) { int len; struct type *arg_type; arg_type = check_typedef (VALUE_TYPE (args[argnum])); len = TYPE_LENGTH (arg_type); /* ANSI C code passes float arguments as integers, K&R code passes float arguments as doubles. Correct for this here. */ if (TYPE_CODE_FLT == TYPE_CODE (arg_type) && REGISTER_SIZE == len) nstack_size += FP_REGISTER_VIRTUAL_SIZE; else nstack_size += len; } /* Allocate room on the stack, and initialize our stack frame pointer. */ fp = NULL; if (nstack_size > 0) { sp -= nstack_size; fp = (char *) sp; } /* Initialize the integer argument register pointer. */ argreg = ARM_A1_REGNUM; /* The struct_return pointer occupies the first parameter passing register. */ if (struct_return) write_register (argreg++, struct_addr); /* Process arguments from left to right. Store as many as allowed in the parameter passing registers (A1-A4), and save the rest on the temporary stack. */ for (argnum = 0; argnum < nargs; argnum++) { int len; char *val; CORE_ADDR regval; enum type_code typecode; struct type *arg_type, *target_type; arg_type = check_typedef (VALUE_TYPE (args[argnum])); target_type = TYPE_TARGET_TYPE (arg_type); len = TYPE_LENGTH (arg_type); typecode = TYPE_CODE (arg_type); val = (char *) VALUE_CONTENTS (args[argnum]); /* ANSI C code passes float arguments as integers, K&R code passes float arguments as doubles. The .stabs record for for ANSI prototype floating point arguments records the type as FP_INTEGER, while a K&R style (no prototype) .stabs records the type as FP_FLOAT. In this latter case the compiler converts the float arguments to double before calling the function. */ if (TYPE_CODE_FLT == typecode && REGISTER_SIZE == len) { DOUBLEST dblval; dblval = extract_floating (val, len); len = TARGET_DOUBLE_BIT / TARGET_CHAR_BIT; val = alloca (len); store_floating (val, len, dblval); } /* If the argument is a pointer to a function, and it is a Thumb function, set the low bit of the pointer. */ if (TYPE_CODE_PTR == typecode && NULL != target_type && TYPE_CODE_FUNC == TYPE_CODE (target_type)) { CORE_ADDR regval = extract_address (val, len); if (arm_pc_is_thumb (regval)) store_address (val, len, MAKE_THUMB_ADDR (regval)); } /* Copy the argument to general registers or the stack in register-sized pieces. Large arguments are split between registers and stack. */ while (len > 0) { int partial_len = len < REGISTER_SIZE ? len : REGISTER_SIZE; if (argreg <= ARM_LAST_ARG_REGNUM) { /* It's an argument being passed in a general register. */ regval = extract_address (val, partial_len); write_register (argreg++, regval); } else { /* Push the arguments onto the stack. */ write_memory ((CORE_ADDR) fp, val, REGISTER_SIZE); fp += REGISTER_SIZE; } len -= partial_len; val += partial_len; } } /* Return adjusted stack pointer. */ return sp; }
gint lock_mbox(const gchar *base, LockType type) { #ifdef G_OS_UNIX gint retval = 0; if (type == LOCK_FILE) { gchar *lockfile, *locklink; gint retry = 0; FILE *lockfp; lockfile = g_strdup_printf("%s.%d", base, getpid()); if ((lockfp = g_fopen(lockfile, "wb")) == NULL) { FILE_OP_ERROR(lockfile, "fopen"); g_warning("can't create lock file %s\n", lockfile); g_warning("use 'flock' instead of 'file' if possible.\n"); g_free(lockfile); return -1; } if (fprintf(lockfp, "%d\n", getpid()) < 0) { FILE_OP_ERROR(lockfile, "fprintf"); g_free(lockfile); fclose(lockfp); return -1; } if (fclose(lockfp) == EOF) { FILE_OP_ERROR(lockfile, "fclose"); g_free(lockfile); return -1; } locklink = g_strconcat(base, ".lock", NULL); while (link(lockfile, locklink) < 0) { FILE_OP_ERROR(lockfile, "link"); if (retry >= 5) { g_warning("can't create %s\n", lockfile); claws_unlink(lockfile); g_free(lockfile); return -1; } if (retry == 0) g_warning("mailbox is owned by another" " process, waiting...\n"); retry++; sleep(5); } claws_unlink(lockfile); g_free(lockfile); } else if (type == LOCK_FLOCK) { gint lockfd; gboolean fcntled = FALSE; #if HAVE_FCNTL_H && !defined(G_OS_WIN32) struct flock fl; fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; #endif #if HAVE_FLOCK if ((lockfd = g_open(base, O_RDWR, 0)) < 0) { #else if ((lockfd = g_open(base, O_RDWR, 0)) < 0) { #endif FILE_OP_ERROR(base, "open"); return -1; } #if HAVE_FCNTL_H && !defined(G_OS_WIN32) if (fcntl(lockfd, F_SETLK, &fl) == -1) { g_warning("can't fnctl %s (%s)", base, strerror(errno)); return -1; } else { fcntled = TRUE; } #endif #if HAVE_FLOCK if (flock(lockfd, LOCK_EX|LOCK_NB) < 0 && !fcntled) { perror("flock"); #else #if HAVE_LOCKF if (lockf(lockfd, F_TLOCK, 0) < 0 && !fcntled) { perror("lockf"); #else { #endif #endif /* HAVE_FLOCK */ g_warning("can't lock %s\n", base); if (close(lockfd) < 0) perror("close"); return -1; } retval = lockfd; } else { g_warning("invalid lock type\n"); return -1; } return retval; #else return -1; #endif /* G_OS_UNIX */ } gint unlock_mbox(const gchar *base, gint fd, LockType type) { if (type == LOCK_FILE) { gchar *lockfile; lockfile = g_strconcat(base, ".lock", NULL); if (claws_unlink(lockfile) < 0) { FILE_OP_ERROR(lockfile, "unlink"); g_free(lockfile); return -1; } g_free(lockfile); return 0; } else if (type == LOCK_FLOCK) { gboolean fcntled = FALSE; #if HAVE_FCNTL_H && !defined(G_OS_WIN32) struct flock fl; fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; if (fcntl(fd, F_SETLK, &fl) == -1) { g_warning("can't fnctl %s", base); } else { fcntled = TRUE; } #endif #if HAVE_FLOCK if (flock(fd, LOCK_UN) < 0 && !fcntled) { perror("flock"); #else #if HAVE_LOCKF if (lockf(fd, F_ULOCK, 0) < 0 && !fcntled) { perror("lockf"); #else { #endif #endif /* HAVE_FLOCK */ g_warning("can't unlock %s\n", base); if (close(fd) < 0) perror("close"); return -1; } if (close(fd) < 0) { perror("close"); return -1; } return 0; } g_warning("invalid lock type\n"); return -1; } gint copy_mbox(gint srcfd, const gchar *dest) { FILE *dest_fp; ssize_t n_read; gchar buf[BUFSIZ]; gboolean err = FALSE; int save_errno = 0; if (srcfd < 0) { return -1; } if ((dest_fp = g_fopen(dest, "wb")) == NULL) { FILE_OP_ERROR(dest, "fopen"); return -1; } if (change_file_mode_rw(dest_fp, dest) < 0) { FILE_OP_ERROR(dest, "chmod"); g_warning("can't change file mode\n"); } while ((n_read = read(srcfd, buf, sizeof(buf))) > 0) { if (n_read == -1 && errno != 0) { save_errno = errno; break; } if (fwrite(buf, 1, n_read, dest_fp) < n_read) { g_warning("writing to %s failed.\n", dest); fclose(dest_fp); claws_unlink(dest); return -1; } } if (save_errno != 0) { g_warning("error %d reading mbox: %s\n", save_errno, strerror(save_errno)); err = TRUE; } if (fclose(dest_fp) == EOF) { FILE_OP_ERROR(dest, "fclose"); err = TRUE; } if (err) { claws_unlink(dest); return -1; } return 0; } void empty_mbox(const gchar *mbox) { FILE *fp; if ((fp = g_fopen(mbox, "wb")) == NULL) { FILE_OP_ERROR(mbox, "fopen"); g_warning("can't truncate mailbox to zero.\n"); return; } fclose(fp); } gint export_list_to_mbox(GSList *mlist, const gchar *mbox) /* return values: -2 skipped, -1 error, 0 OK */ { GSList *cur; MsgInfo *msginfo; FILE *msg_fp; FILE *mbox_fp; gchar buf[BUFFSIZE]; int err = 0; gint msgs = 1, total = g_slist_length(mlist); if (g_file_test(mbox, G_FILE_TEST_EXISTS) == TRUE) { if (alertpanel_full(_("Overwrite mbox file"), _("This file already exists. Do you want to overwrite it?"), GTK_STOCK_CANCEL, _("Overwrite"), NULL, FALSE, NULL, ALERT_WARNING, G_ALERTDEFAULT) != G_ALERTALTERNATE) { return -2; } } if ((mbox_fp = g_fopen(mbox, "wb")) == NULL) { FILE_OP_ERROR(mbox, "fopen"); alertpanel_error(_("Could not create mbox file:\n%s\n"), mbox); return -1; } #ifdef HAVE_FGETS_UNLOCKED flockfile(mbox_fp); #endif statuswindow_print_all(_("Exporting to mbox...")); for (cur = mlist; cur != NULL; cur = cur->next) { int len; gchar buft[BUFFSIZE]; msginfo = (MsgInfo *)cur->data; msg_fp = procmsg_open_message(msginfo); if (!msg_fp) { continue; } #ifdef HAVE_FGETS_UNLOCKED flockfile(msg_fp); #endif strncpy2(buf, msginfo->from ? msginfo->from : cur_account && cur_account->address ? cur_account->address : "unknown", sizeof(buf)); extract_address(buf); if (fprintf(mbox_fp, "From %s %s", buf, ctime_r(&msginfo->date_t, buft)) < 0) { err = -1; #ifdef HAVE_FGETS_UNLOCKED funlockfile(msg_fp); #endif fclose(msg_fp); goto out; } buf[0] = '\0'; /* write email to mboxrc */ while (SC_FGETS(buf, sizeof(buf), msg_fp) != NULL) { /* quote any From, >From, >>From, etc., according to mbox format specs */ int offset; offset = 0; /* detect leading '>' char(s) */ while ((buf[offset] == '>')) { offset++; } if (!strncmp(buf+offset, "From ", 5)) { if (SC_FPUTC('>', mbox_fp) == EOF) { err = -1; #ifdef HAVE_FGETS_UNLOCKED funlockfile(msg_fp); #endif fclose(msg_fp); goto out; } } if (SC_FPUTS(buf, mbox_fp) == EOF) { err = -1; #ifdef HAVE_FGETS_UNLOCKED funlockfile(msg_fp); #endif fclose(msg_fp); goto out; } } /* force last line to end w/ a newline */ len = strlen(buf); if (len > 0) { len--; if ((buf[len] != '\n') && (buf[len] != '\r')) { if (SC_FPUTC('\n', mbox_fp) == EOF) { err = -1; #ifdef HAVE_FGETS_UNLOCKED funlockfile(msg_fp); #endif fclose(msg_fp); goto out; } } } /* add a trailing empty line */ if (SC_FPUTC('\n', mbox_fp) == EOF) { err = -1; #ifdef HAVE_FGETS_UNLOCKED funlockfile(msg_fp); #endif fclose(msg_fp); goto out; } #ifdef HAVE_FGETS_UNLOCKED funlockfile(msg_fp); #endif fclose(msg_fp); statusbar_progress_all(msgs++,total, 500); if (msgs%500 == 0) GTK_EVENTS_FLUSH(); } out: statusbar_progress_all(0,0,0); statuswindow_pop_all(); #ifdef HAVE_FGETS_UNLOCKED funlockfile(mbox_fp); #endif fclose(mbox_fp); return err; }
gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, gboolean keep_session) { Session *session; SMTPSession *smtp_session; gushort port = 0; gchar buf[BUFFSIZE]; gint ret = 0; gboolean was_inited = FALSE; MsgInfo *tmp_msginfo = NULL; MsgFlags flags = {0, 0}; long fp_pos = 0; gchar spec_from[BUFFSIZE]; ProxyInfo *proxy_info = NULL; cm_return_val_if_fail(ac_prefs != NULL, -1); cm_return_val_if_fail(ac_prefs->address != NULL, -1); cm_return_val_if_fail(ac_prefs->smtp_server != NULL, -1); cm_return_val_if_fail(to_list != NULL, -1); cm_return_val_if_fail(fp != NULL, -1); /* get the From address used, not necessarily the ac_prefs', * because it's editable. */ fp_pos = ftell(fp); if (fp_pos < 0) { perror("ftell"); return -1; } tmp_msginfo = procheader_parse_stream(fp, flags, TRUE, FALSE); if (fseek(fp, fp_pos, SEEK_SET) < 0) { perror("fseek"); return -1; } if (tmp_msginfo && tmp_msginfo->extradata && tmp_msginfo->extradata->resent_from) { strncpy2(spec_from, tmp_msginfo->extradata->resent_from, BUFFSIZE-1); extract_address(spec_from); } else if (tmp_msginfo && tmp_msginfo->from) { strncpy2(spec_from, tmp_msginfo->from, BUFFSIZE-1); extract_address(spec_from); } else { strncpy2(spec_from, ac_prefs->address, BUFFSIZE-1); } if (tmp_msginfo) { procmsg_msginfo_free(&tmp_msginfo); } if (!ac_prefs->session) { /* we can't reuse a previously initialised session */ session = smtp_session_new(ac_prefs); session->ssl_cert_auto_accept = ac_prefs->ssl_certs_auto_accept; smtp_session = SMTP_SESSION(session); if (ac_prefs->set_domain && ac_prefs->domain && strlen(ac_prefs->domain)) { smtp_session->hostname = g_strdup(ac_prefs->domain); } else { smtp_session->hostname = NULL; } #ifdef USE_GNUTLS port = ac_prefs->set_smtpport ? ac_prefs->smtpport : ac_prefs->ssl_smtp == SSL_TUNNEL ? SSMTP_PORT : SMTP_PORT; session->ssl_type = ac_prefs->ssl_smtp; if (ac_prefs->ssl_smtp != SSL_NONE) session->nonblocking = ac_prefs->use_nonblocking_ssl; if (ac_prefs->set_gnutls_priority && ac_prefs->gnutls_priority && strlen(ac_prefs->gnutls_priority)) session->gnutls_priority = g_strdup(ac_prefs->gnutls_priority); session->use_tls_sni = ac_prefs->use_tls_sni; #else if (ac_prefs->ssl_smtp != SSL_NONE) { if (alertpanel_full(_("Insecure connection"), _("This connection is configured to be secured " "using SSL/TLS, but SSL/TLS is not available " "in this build of Claws Mail. \n\n" "Do you want to continue connecting to this " "server? The communication would not be " "secure."), GTK_STOCK_CANCEL, _("Con_tinue connecting"), NULL, ALERTFOCUS_FIRST, FALSE, NULL, ALERT_WARNING) != G_ALERTALTERNATE) { session_destroy(session); return -1; } } port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT; #endif if (ac_prefs->use_smtp_auth) { smtp_session->forced_auth_type = ac_prefs->smtp_auth_type; if (ac_prefs->smtp_userid && strlen(ac_prefs->smtp_userid)) { smtp_session->user = g_strdup(ac_prefs->smtp_userid); if (password_get(smtp_session->user, ac_prefs->smtp_server, "smtp", port, &(smtp_session->pass))) { /* NOP */; } else if ((smtp_session->pass = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_SEND)) == NULL) { smtp_session->pass = input_dialog_query_password_keep (ac_prefs->smtp_server, smtp_session->user, &(ac_prefs->session_smtp_passwd)); if (!smtp_session->pass) { session_destroy(session); return -1; } } } else { smtp_session->user = g_strdup(ac_prefs->userid); if (password_get(smtp_session->user, ac_prefs->smtp_server, "smtp", port, &(smtp_session->pass))) { /* NOP */; } else if ((smtp_session->pass = passwd_store_get_account( ac_prefs->account_id, PWS_ACCOUNT_RECV)) == NULL) { smtp_session->pass = input_dialog_query_password_keep (ac_prefs->smtp_server, smtp_session->user, &(ac_prefs->session_smtp_passwd)); if (!smtp_session->pass) { session_destroy(session); return -1; } } } } else { smtp_session->user = NULL; smtp_session->pass = NULL; } send_dialog = send_progress_dialog_create(); send_dialog->session = session; smtp_session->dialog = send_dialog; progress_dialog_list_set(send_dialog->dialog, 0, NULL, ac_prefs->smtp_server, _("Connecting")); if (ac_prefs->pop_before_smtp && (ac_prefs->protocol == A_POP3) && (time(NULL) - ac_prefs->last_pop_login_time) > (60 * ac_prefs->pop_before_smtp_timeout)) { g_snprintf(buf, sizeof(buf), _("Doing POP before SMTP...")); log_message(LOG_PROTOCOL, "%s\n", buf); progress_dialog_set_label(send_dialog->dialog, buf); progress_dialog_list_set_status(send_dialog->dialog, 0, _("POP before SMTP")); GTK_EVENTS_FLUSH(); inc_pop_before_smtp(ac_prefs); } g_snprintf(buf, sizeof(buf), _("Account '%s': Connecting to SMTP server: %s:%d..."), ac_prefs->account_name, ac_prefs->smtp_server, port); progress_dialog_set_label(send_dialog->dialog, buf); log_message(LOG_PROTOCOL, "%s\n", buf); session_set_recv_message_notify(session, send_recv_message, send_dialog); session_set_send_data_progressive_notify (session, send_send_data_progressive, send_dialog); session_set_send_data_notify(session, send_send_data_finished, send_dialog); } else { /* everything is ready to start at MAIL FROM:, just * reinit useful variables. */ session = SESSION(ac_prefs->session); ac_prefs->session = NULL; smtp_session = SMTP_SESSION(session); smtp_session->state = SMTP_HELO; send_dialog = (SendProgressDialog *)smtp_session->dialog; was_inited = TRUE; } /* This has to be initialised for every mail sent */ smtp_session->from = g_strdup(spec_from); smtp_session->to_list = to_list; smtp_session->cur_to = to_list; smtp_session->send_data = (guchar *)get_outgoing_rfc2822_str(fp); smtp_session->send_data_len = strlen((gchar *)smtp_session->send_data); if (ac_prefs->use_proxy && ac_prefs->use_proxy_for_send) { if (ac_prefs->use_default_proxy) { proxy_info = (ProxyInfo *)&(prefs_common.proxy_info); if (proxy_info->use_proxy_auth) proxy_info->proxy_pass = passwd_store_get(PWS_CORE, PWS_CORE_PROXY, PWS_CORE_PROXY_PASS); } else { proxy_info = (ProxyInfo *)&(ac_prefs->proxy_info); if (proxy_info->use_proxy_auth) proxy_info->proxy_pass = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_PROXY_PASS); } } SESSION(smtp_session)->proxy_info = proxy_info; session_set_timeout(session, prefs_common.io_timeout_secs * 1000); /* connect if necessary */ if (!was_inited && session_connect(session, ac_prefs->smtp_server, port) < 0) { session_destroy(session); send_progress_dialog_destroy(send_dialog); ac_prefs->session = NULL; return -1; } debug_print("send_message_smtp(): begin event loop\n"); if (was_inited) { /* as the server is quiet, start sending ourselves */ smtp_from(smtp_session); } while (session_is_running(session) && send_dialog->cancelled == FALSE && SMTP_SESSION(session)->state != SMTP_MAIL_SENT_OK) gtk_main_iteration(); if (SMTP_SESSION(session)->error_val == SM_AUTHFAIL) { if (ac_prefs->session_smtp_passwd) { g_free(ac_prefs->session_smtp_passwd); ac_prefs->session_smtp_passwd = NULL; } ret = -1; } else if (SMTP_SESSION(session)->state == SMTP_MAIL_SENT_OK) { log_message(LOG_PROTOCOL, "%s\n", _("Mail sent successfully.")); ret = 0; } else if (session->state == SESSION_EOF && SMTP_SESSION(session)->state == SMTP_QUIT) { /* consider EOF right after QUIT successful */ log_warning(LOG_PROTOCOL, "%s\n", _("Connection closed by the remote host.")); ret = 0; } else if (session->state == SESSION_ERROR || session->state == SESSION_EOF || session->state == SESSION_TIMEOUT || SMTP_SESSION(session)->state == SMTP_ERROR || SMTP_SESSION(session)->error_val != SM_OK) ret = -1; else if (send_dialog->cancelled == TRUE) ret = -1; if (ret == -1) { manage_window_focus_in(send_dialog->dialog->window, NULL, NULL); send_put_error(session); manage_window_focus_out(send_dialog->dialog->window, NULL, NULL); } /* if we should close the connection, let's do it. * Close it in case of error, too, as it helps reinitializing things * easier. */ if (!keep_session || ret != 0) { if (session_is_connected(session)) smtp_quit(smtp_session); while (session_is_connected(session) && !send_dialog->cancelled) gtk_main_iteration(); session_destroy(session); ac_prefs->session = NULL; send_progress_dialog_destroy(send_dialog); } else { g_free(smtp_session->from); g_free(smtp_session->send_data); g_free(smtp_session->error_msg); } if (keep_session && ret == 0 && ac_prefs->session == NULL) ac_prefs->session = SMTP_SESSION(session); statusbar_pop_all(); statusbar_verbosity_set(FALSE); return ret; }
BEmailMessage * BEmailMessage::ReplyMessage(mail_reply_to_mode replyTo, bool accountFromMail, const char *quoteStyle) { BEmailMessage *reply = new BEmailMessage; // Set ReplyTo: if (replyTo == B_MAIL_REPLY_TO_ALL) { reply->SetTo(From()); BList list; get_address_list(list, CC(), extract_address); get_address_list(list, To(), extract_address); // Filter out the sender BMailAccounts accounts; BMailAccountSettings* account = accounts.AccountByID(Account()); BString sender; if (account) sender = account->ReturnAddress(); extract_address(sender); BString cc; for (int32 i = list.CountItems(); i-- > 0;) { char *address = (char *)list.RemoveItem((int32)0); // add everything which is not the sender and not already in the list if (sender.ICompare(address) && cc.FindFirst(address) < 0) { if (cc.Length() > 0) cc << ", "; cc << address; } free(address); } if (cc.Length() > 0) reply->SetCC(cc.String()); } else if (replyTo == B_MAIL_REPLY_TO_SENDER || ReplyTo() == NULL) reply->SetTo(From()); else reply->SetTo(ReplyTo()); // Set special "In-Reply-To:" header (used for threading) const char *messageID = _body ? _body->HeaderField("Message-Id") : NULL; if (messageID != NULL) reply->SetHeaderField("In-Reply-To", messageID); // quote body text reply->SetBodyTextTo(BodyText()); if (quoteStyle) reply->Body()->Quote(quoteStyle); // Set the subject (and add a "Re:" if needed) BString string = Subject(); if (string.ICompare("re:", 3) != 0) string.Prepend("Re: "); reply->SetSubject(string.String()); // set the matching outbound chain if (accountFromMail) reply->SendViaAccountFrom(this); return reply; }
CORE_ADDR microblaze_extract_struct_value_address (char *regbuf) { return extract_address (regbuf + REGISTER_BYTE (FIRST_ARGREG), REGISTER_SIZE); }
int java_val_print (struct type *type, char *valaddr, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int format, int deref_ref, int recurse, enum val_prettyprint pretty) { register unsigned int i = 0; /* Number of characters printed */ struct type *target_type; CORE_ADDR addr; CHECK_TYPEDEF (type); switch (TYPE_CODE (type)) { case TYPE_CODE_PTR: if (format && format != 's') { print_scalar_formatted (valaddr, type, format, 0, stream); break; } #if 0 if (vtblprint && cp_is_vtbl_ptr_type (type)) { /* Print the unmangled name if desired. */ /* Print vtable entry - we only get here if we ARE using -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ print_address_demangle (extract_address (valaddr, TYPE_LENGTH (type)), stream, demangle); break; } #endif addr = unpack_pointer (type, valaddr); if (addr == 0) { fputs_filtered ("null", stream); return i; } target_type = check_typedef (TYPE_TARGET_TYPE (type)); if (TYPE_CODE (target_type) == TYPE_CODE_FUNC) { /* Try to print what function it points to. */ print_address_demangle (addr, stream, demangle); /* Return value is irrelevant except for string pointers. */ return (0); } if (addressprint && format != 's') { fputs_filtered ("@", stream); print_longest (stream, 'x', 0, (ULONGEST) addr); } return i; case TYPE_CODE_CHAR: case TYPE_CODE_INT: /* Can't just call c_val_print because that prints bytes as C chars. */ format = format ? format : output_format; if (format) print_scalar_formatted (valaddr, type, format, 0, stream); else if (TYPE_CODE (type) == TYPE_CODE_CHAR || (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_LENGTH (type) == 2 && strcmp (TYPE_NAME (type), "char") == 0)) LA_PRINT_CHAR ((int) unpack_long (type, valaddr), stream); else val_print_type_code_int (type, valaddr, stream); break; case TYPE_CODE_STRUCT: java_print_value_fields (type, valaddr, address, stream, format, recurse, pretty); break; default: return c_val_print (type, valaddr, embedded_offset, address, stream, format, deref_ref, recurse, pretty); } return 0; }
int java_value_print (struct value *val, struct ui_file *stream, int format, enum val_prettyprint pretty) { struct type *type; CORE_ADDR address; int i; char *name; type = VALUE_TYPE (val); address = VALUE_ADDRESS (val) + VALUE_OFFSET (val); if (is_object_type (type)) { CORE_ADDR obj_addr; /* Get the run-time type, and cast the object into that */ obj_addr = unpack_pointer (type, VALUE_CONTENTS (val)); if (obj_addr != 0) { type = type_from_class (java_class_from_object (val)); type = lookup_pointer_type (type); val = value_at (type, address, NULL); } } if (TYPE_CODE (type) == TYPE_CODE_PTR && !value_logical_not (val)) type_print (TYPE_TARGET_TYPE (type), "", stream, -1); name = TYPE_TAG_NAME (type); if (TYPE_CODE (type) == TYPE_CODE_STRUCT && name != NULL && (i = strlen (name), name[i - 1] == ']')) { char buf4[4]; long length; unsigned int things_printed = 0; int reps; struct type *el_type = java_primitive_type_from_name (name, i - 2); i = 0; read_memory (address + JAVA_OBJECT_SIZE, buf4, 4); length = (long) extract_signed_integer (buf4, 4); fprintf_filtered (stream, "{length: %ld", length); if (el_type == NULL) { CORE_ADDR element; CORE_ADDR next_element = -1; /* dummy initial value */ address += JAVA_OBJECT_SIZE + 4; /* Skip object header and length. */ while (i < length && things_printed < print_max) { char *buf; buf = alloca (TARGET_PTR_BIT / HOST_CHAR_BIT); fputs_filtered (", ", stream); wrap_here (n_spaces (2)); if (i > 0) element = next_element; else { read_memory (address, buf, sizeof (buf)); address += TARGET_PTR_BIT / HOST_CHAR_BIT; element = extract_address (buf, sizeof (buf)); } for (reps = 1; i + reps < length; reps++) { read_memory (address, buf, sizeof (buf)); address += TARGET_PTR_BIT / HOST_CHAR_BIT; next_element = extract_address (buf, sizeof (buf)); if (next_element != element) break; } if (reps == 1) fprintf_filtered (stream, "%d: ", i); else fprintf_filtered (stream, "%d..%d: ", i, i + reps - 1); if (element == 0) fprintf_filtered (stream, "null"); else fprintf_filtered (stream, "@%s", paddr_nz (element)); things_printed++; i += reps; } } else { struct value *v = allocate_value (el_type); struct value *next_v = allocate_value (el_type); VALUE_ADDRESS (v) = address + JAVA_OBJECT_SIZE + 4; VALUE_ADDRESS (next_v) = VALUE_ADDRESS (v); while (i < length && things_printed < print_max) { fputs_filtered (", ", stream); wrap_here (n_spaces (2)); if (i > 0) { struct value *tmp; tmp = next_v; next_v = v; v = tmp; } else { VALUE_LAZY (v) = 1; VALUE_OFFSET (v) = 0; } VALUE_OFFSET (next_v) = VALUE_OFFSET (v); for (reps = 1; i + reps < length; reps++) { VALUE_LAZY (next_v) = 1; VALUE_OFFSET (next_v) += TYPE_LENGTH (el_type); if (memcmp (VALUE_CONTENTS (v), VALUE_CONTENTS (next_v), TYPE_LENGTH (el_type)) != 0) break; } if (reps == 1) fprintf_filtered (stream, "%d: ", i); else fprintf_filtered (stream, "%d..%d: ", i, i + reps - 1); val_print (VALUE_TYPE (v), VALUE_CONTENTS (v), 0, 0, stream, format, 2, 1, pretty); things_printed++; i += reps; } } if (i < length) fprintf_filtered (stream, "..."); fprintf_filtered (stream, "}"); return 0; } /* If it's type String, print it */ if (TYPE_CODE (type) == TYPE_CODE_PTR && TYPE_TARGET_TYPE (type) && TYPE_NAME (TYPE_TARGET_TYPE (type)) && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "java.lang.String") == 0 && (format == 0 || format == 's') && address != 0 && value_as_address (val) != 0) { struct value *data_val; CORE_ADDR data; struct value *boffset_val; unsigned long boffset; struct value *count_val; unsigned long count; struct value *mark; mark = value_mark (); /* Remember start of new values */ data_val = value_struct_elt (&val, NULL, "data", NULL, NULL); data = value_as_address (data_val); boffset_val = value_struct_elt (&val, NULL, "boffset", NULL, NULL); boffset = value_as_address (boffset_val); count_val = value_struct_elt (&val, NULL, "count", NULL, NULL); count = value_as_address (count_val); value_free_to_mark (mark); /* Release unnecessary values */ val_print_string (data + boffset, count, 2, stream); return 0; } return (val_print (type, VALUE_CONTENTS (val), 0, address, stream, format, 1, 0, pretty)); }
static CORE_ADDR mn10300_extract_struct_value_address (char *regbuf) { return extract_address (regbuf + REGISTER_BYTE (4), REGISTER_RAW_SIZE (4)); }
static void message_receive(int32_t s) { size_t l = 0; time_t date = time(NULL); /* send greeting, wait for response */ socket_send(s, MESSAGE_220); char *r = socket_read(s, &l); validate(MESSAGE_LHLO, r); char *cname = strdup(r + strlen(MESSAGE_LHLO)); free(r); /* send welcome, wait for sender */ { char *x = NULL; for (int i = strlen(cname); i > 0; i--) if (isspace(cname[i])) cname[i] = '\0'; asprintf(&x, MESSAGE_250A, cname); if (!x) die("out of memory @ %s:%i", __FILE__, __LINE__ - 2); free(cname); socket_send(s, x); free(x); } r = socket_read(s, &l); validate(MESSAGE_FROM, r); char *from = extract_address(r); free(r); /* ok, wait for recipients (loop until DATA) */ list_t *rcpt = list_create(NULL); while (true) { socket_send(s, MESSAGE_250); r = socket_read(s, &l); if (!strncmp(MESSAGE_DATA, r, strlen(MESSAGE_DATA))) break; validate(MESSAGE_RCPT, r); list_append(&rcpt, extract_address(r)); free(r); } free(r); /* send 352, wait for .\n\r */ socket_send(s, MESSAGE_354); char *data = NULL; uint64_t dl = 1; while (true) { r = socket_read(s, &l); if (!strcmp(MESSAGE_STOP, r)) break; char *x = realloc(data, l + dl); if (!x) die("out of memory @ %s:%i", __FILE__, __LINE__ - 2); data = x; if ((x = convert_from_prefix(r))) { free(r); r = x; l++; } uint8_t dd = convert_double_dot(r); if (dd) l--; memcpy(data + dl, r + dd, l); dl += l; free(r); } free(r); if (data) convert_new_line(data); data[dl - 1] = '\0'; /* ok, wait for QUIT */ uint64_t rcpts = list_size(rcpt); for (unsigned i = 0; i < rcpts; i++) { char *x = NULL; asprintf(&x, MESSAGE_250C, (char *)list_get(rcpt, i)); socket_send(s, x); free(x); } r = socket_read(s, &l); validate(MESSAGE_QUIT, r); free(r); /* bye, close */ socket_send(s, MESSAGE_221); /* * TODO if To: address contains @domain.example.com * forward the message to an actual outbound mail hander * -- and-- * check if the domain/host is localhost (or local hostname) */ for (unsigned i = 0; i < rcpts; i++) { char *emadr = (char *)list_get(rcpt, i); char *at = strchrnul(emadr, '@'); char *usr = strndup(emadr, at - emadr); /* lookup the user; if root, find alias instead */ if (!strcmp(ROOT, usr)) usr = root_alias; struct passwd *pw = getpwnam(usr); if (!pw) continue; uid_t uid = pw->pw_uid; gid_t gid = pw->pw_gid; /* write the message to the mail box */ char *mesg = NULL; asprintf(&mesg, "From %s %s%s\n", from, ctime(&date), data); char *mbn = NULL; asprintf(&mbn, "%s/%s", mbox_dir, usr); int64_t mbox = open(mbn, O_WRONLY | O_APPEND | O_CREAT | F_WRLCK); if (mbox < 0) die("could not access mail box %s", mbn); free(mbn); write(mbox, mesg, strlen(mesg)); fchown(mbox, uid, gid); fchmod(mbox, S_IRUSR | S_IWUSR); close(mbox); free(mesg); } list_delete(&rcpt, true); free(from); free(data); }