void RegisterAccount::checkStatus() { CustomButton *button = qobject_cast<CustomButton*>(sender()); if (button->text() == "Ok") validAccount(1); else validAccount(0); }
static bool sendMailSMTP(const struct MACCOUNT *account, const char *reply, const char **recipients, const char *message) { CURLcode res = CURLE_OK; bool smtp_success = false; char *smtp_url = buildSMTPURL(account); struct curl_slist *recipient_slist = buildRecipientSList(recipients); struct smtp_upload upload = { .data = message,.length = strlen(message),.pos = 0 }; CURL *handle = newSendmailHandle(account, smtp_url, reply, recipient_slist); if (!handle) goto smtp_cleanup; curl_easy_setopt(handle, CURLOPT_READFUNCTION, smtp_upload_callback); curl_easy_setopt(handle, CURLOPT_READDATA, &upload); curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); res = curl_easy_perform(handle); if (res == CURLE_OK) smtp_success = true; smtp_cleanup: if (res != CURLE_OK) ebcurl_setError(res, smtp_url); if (handle) curl_easy_cleanup(handle); curl_slist_free_all(recipient_slist); nzFree(smtp_url); return smtp_success; } /* sendMailSMTP */ /* Send mail to the smtp server. */ bool sendMail(int account, const char **recipients, const char *body, int subjat, const char **attachments, const char *refline, int nalt, bool dosig) { char *from, *fromiso, *reply, *login, *smlogin, *pass; const struct MACCOUNT *a, *ao, *localMail; const char *s, *boundary; char reccc[MAXRECAT]; char *t; int nat, cx, i, j; char *out = 0; bool sendmail_success = false; bool mustmime = false; bool firstgreet = true; bool firstrec; const char *ct, *ce; char *encoded = 0; if (!validAccount(account)) return false; mailAccount = account; localMail = accounts + localAccount - 1; a = accounts + account - 1; from = a->from; reply = a->reply; ao = a->outssl ? a : localMail; doSignature = dosig; nat = 0; /* number of attachments */ if (attachments) { while (attachments[nat]) ++nat; } if (nat) mustmime = true; if (nalt && nalt < nat) { setError(MSG_AttAlternate); return false; } if (!loadAddressBook()) return false; /* set copy flags */ for (j = 0; s = recipients[j]; ++j) { char cc = 0; if (*s == '^' || *s == '?') cc = *s++; if (j == MAXRECAT) { setError(MSG_RecipMany, MAXRECAT); return false; } recipients[j] = s; reccc[j] = cc; } /* Look up aliases in the address book */ for (j = 0; s = recipients[j]; ++j) { if (strchr(s, '@')) continue; t = 0; for (i = 0; i < nads; ++i) { const char *a = addressList[i].name; if (*a == '-' || *a == '!') ++a; if (!stringEqual(s, a)) continue; t = addressList[i].email; debugPrint(3, " %s becomes %s", s, t); break; } if (t) { recipients[j] = t; continue; } if (!addressFile) { setError(MSG_ABMissing); return false; } setError(MSG_ABNoAlias2, s); return false; } /* recipients */ if (!j) { setError(MSG_RecipNone); return false; } /* verify attachments are readable */ for (j = 0; s = attachments[j]; ++j) { if (!ismc && (cx = stringIsNum(s)) >= 0) { if (!cxCompare(cx) || !cxActive(cx)) return false; if (!sessionList[cx].lw->dol) { setError(MSG_AttSessionEmpty, cx); return false; } } else { char ftype = fileTypeByName(s, false); if (!ftype) { setError(MSG_AttAccess, s); return false; } if (ftype != 'f') { setError(MSG_AttRegular, s); return false; } if (!fileSizeByName(s)) { setError(MSG_AttEmpty2, s); return false; } } } /* loop over attachments */ if (!encodeAttachment(body, subjat, false, &ct, &ce, &encoded)) return false; if (ce[0] == 'q') mustmime = true; boundary = makeBoundary(); /* Build the outgoing mail, as one string. */ out = initString(&j); firstrec = true; for (i = 0; s = recipients[i]; ++i) { if (reccc[i]) continue; stringAndString(&out, &j, firstrec ? "To:" : ",\r\n "); stringAndString(&out, &j, s); firstrec = false; } if (!firstrec) stringAndString(&out, &j, eol); firstrec = true; for (i = 0; s = recipients[i]; ++i) { if (reccc[i] != '^') continue; stringAndString(&out, &j, firstrec ? "CC:" : ",\r\n "); stringAndString(&out, &j, s); firstrec = false; } if (!firstrec) stringAndString(&out, &j, eol); firstrec = true; for (i = 0; s = recipients[i]; ++i) { if (reccc[i] != '?') continue; stringAndString(&out, &j, firstrec ? "BCC:" : ",\r\n "); stringAndString(&out, &j, s); firstrec = false; } if (!firstrec) stringAndString(&out, &j, eol); fromiso = isoEncode(from, from + strlen(from)); if (!fromiso) fromiso = from; sprintf(serverLine, "From: %s <%s>%s", fromiso, reply, eol); stringAndString(&out, &j, serverLine); sprintf(serverLine, "Reply-to: %s <%s>%s", fromiso, reply, eol); stringAndString(&out, &j, serverLine); if (fromiso != from) nzFree(fromiso); if (refline) { s = strchr(refline, '\n'); if (!s) /* should never happen */ s = refline + strlen(refline); stringAndBytes(&out, &j, refline, s - refline); stringAndString(&out, &j, eol); } sprintf(serverLine, "User-Agent: %s%s", currentAgent, eol); stringAndString(&out, &j, serverLine); if (subjectLine[0]) { sprintf(serverLine, "Subject: %s%s", subjectLine, eol); stringAndString(&out, &j, serverLine); } sprintf(serverLine, "Date: %s%sMessage-ID: <%s.%s>%sMime-Version: 1.0%s", mailTimeString(), eol, messageTimeID(), reply, eol, eol); stringAndString(&out, &j, serverLine); if (!mustmime) { /* no mime components required, we can just send the mail. */ sprintf(serverLine, "Content-Type: %s%s%sContent-Transfer-Encoding: %s%s%s", ct, charsetString(ct, ce), eol, ce, eol, eol); stringAndString(&out, &j, serverLine); } else { sprintf(serverLine, "Content-Type: multipart/%s; boundary=%s%sContent-Transfer-Encoding: 7bit%s%s", nalt ? "alternative" : "mixed", boundary, eol, eol, eol); stringAndString(&out, &j, serverLine); stringAndString(&out, &j, "This message is in MIME format. Since your mail reader does not understand\r\n\ this format, some or all of this message may not be legible.\r\n\r\n--"); stringAndString(&out, &j, boundary); sprintf(serverLine, "%sContent-Type: %s%s%sContent-Transfer-Encoding: %s%s%s", eol, ct, charsetString(ct, ce), eol, ce, eol, eol); stringAndString(&out, &j, serverLine); } /* Now send the body, line by line. */ appendAttachment(encoded, &out, &j); nzFree(encoded); encoded = 0; if (mustmime) { for (i = 0; s = attachments[i]; ++i) { if (!encodeAttachment (s, 0, false, &ct, &ce, &encoded)) return false; sprintf(serverLine, "%s--%s%sContent-Type: %s%s", eol, boundary, eol, ct, charsetString(ct, ce)); stringAndString(&out, &j, serverLine); /* If the filename has a quote in it, forget it. */ /* Also, suppress filename if this is an alternate presentation. */ if (!nalt && !strchr(s, '"') && (ismc || stringIsNum(s) < 0)) { sprintf(serverLine, "; name=\"%s\"", s); stringAndString(&out, &j, serverLine); } sprintf(serverLine, "%sContent-Transfer-Encoding: %s%s%s", eol, ce, eol, eol); stringAndString(&out, &j, serverLine); appendAttachment(encoded, &out, &j); nzFree(encoded); encoded = 0; } /* loop over attachments */ /* The last boundary */ sprintf(serverLine, "%s--%s--%s", eol, boundary, eol); stringAndString(&out, &j, serverLine); } /* mime format */ sendmail_success = sendMailSMTP(ao, reply, recipients, out); nzFree(out); return sendmail_success; } /* sendMail */
bool sendMailCurrent(int sm_account, bool dosig) { const char *reclist[MAXRECAT + 1]; char *recmem; const char *atlist[MAXRECAT + 1]; char *atmem; char *s, *t; char cxbuf[4]; int lr, la, ln; char *refline = 0; int nrec = 0, nat = 0, nalt = 0; int account = localAccount; int j; bool rc = false; bool subj = false; if (cw->browseMode) { setError(MSG_MailBrowse); return false; } if (cw->sqlMode) { setError(MSG_MailDB); return false; } if (cw->dirMode) { setError(MSG_MailDir); return false; } if (cw->binMode) { setError(MSG_MailBinary2); return false; } if (!cw->dol) { setError(MSG_MailEmpty); return false; } if (!validAccount(account)) return false; recmem = initString(&lr); atmem = initString(&la); /* Gather recipients and attachments, until we reach subject: */ for (ln = 1; ln <= cw->dol; ++ln) { char *line = (char *)fetchLine(ln, -1); if (memEqualCI(line, "to:", 3) || memEqualCI(line, "mailto:", 7) || memEqualCI(line, "cc:", 3) || memEqualCI(line, "bcc:", 4) || memEqualCI(line, "reply to:", 9) || memEqualCI(line, "reply to ", 9)) { char cc = 0; if (toupper(line[0]) == 'C') cc = '^'; if (toupper(line[0]) == 'B') cc = '?'; if (toupper(line[0]) == 'R') line += 9; else line = strchr(line, ':') + 1; while (*line == ' ' || *line == '\t') ++line; if (*line == '\n') { setError(MSG_RecipNone2, ln); goto done; } if (nrec == MAXRECAT) { setError(MSG_RecipMany, MAXRECAT); goto done; } ++nrec; for (t = line; *t != '\n'; ++t) ; if (cc) { if (!lr) { setError(MSG_MailFirstCC); goto done; } stringAndChar(&recmem, &lr, cc); } stringAndBytes(&recmem, &lr, line, t + 1 - line); continue; } if (memEqualCI(line, "attach:", 7) || memEqualCI(line, "alt:", 4)) { if (toupper(line[1]) == 'T') line += 7; else line += 4, ++nalt; while (*line == ' ' || *line == '\t') ++line; if (*line == '\n') { setError(MSG_AttLineX, ln); goto done; } if (nat == MAXRECAT) { setError(MSG_RecipMany, MAXRECAT); goto done; } ++nat; for (t = line; *t != '\n'; ++t) ; stringAndBytes(&atmem, &la, line, t + 1 - line); continue; } if (memEqualCI(line, "account:", 8)) { line += 8; while (*line == ' ' || *line == '\t') ++line; if (!isdigitByte(*line) || (account = strtol(line, &line, 10)) == 0 || account > maxAccount || *line != '\n') { setError(MSG_MailAccountBadLineX, ln); goto done; } continue; } if (memEqualCI(line, "references:", 11)) { if (!refline) refline = line; continue; } if (memEqualCI(line, "subject:", 8)) { while (*line == ' ' || *line == '\t') ++line; subj = true; } break; } /* loop over lines */ if (sm_account) account = sm_account; if (!subj) { setError(((ln > cw->dol) + MSG_MailFirstLine), ln); goto done; } if (nrec == 0) { setError(MSG_RecipNone3); goto done; } for (s = recmem, j = 0; *s; s = t + 1, ++j) { t = strchr(s, '\n'); *t = 0; reclist[j] = s; } reclist[j] = 0; for (s = atmem, j = 0; *s; s = t + 1, ++j) { t = strchr(s, '\n'); *t = 0; atlist[j] = s; } atlist[j] = 0; sprintf(cxbuf, "%d", context); rc = sendMail(account, reclist, cxbuf, ln, atlist, refline, nalt, dosig); done: nzFree(recmem); nzFree(atmem); if (!rc && intFlag) setError(MSG_Interrupted); if (rc) i_puts(MSG_OK); return rc; } /* sendMailCurrent */