smtp_client.c
for (size_t i = 1; /* always true */ 1;)
{
printf("Attachment [%zu] or nil: ", i); // Чтение названия файла с консоли read_string_from_console(attachment,
sizeof(attachment) / sizeof(attachment[0])); if (strlen(attachment) <= 3)
break; // Если длина пути файла <= 3, то прерывание цикла
r = smtp_attachment_add_path(smtp, get_filename_from_path(attachment), attachment);
if (check_status(r)) // Если ОК, то
++i; // Переходим к следующему потенциальному вложению else // Иначе сбрасываем состояние и повторяем цикл
smtp_status_code_clear(smtp);
}
// Ввод тела письма с консоли
printf("Body (3 blank lines mean the end):\n"); read_text_from_console(body, sizeof(body) / sizeof(body[0]),
/* max_blank_lines */ 3); r = smtp_mail(smtp, body); // Отправление письма if (!check_status(r))
break; // Если не получилось, то выход в начало
//Завершение соединения r = smtp_close(smtp); if (!check_status(r))
break; // Если не получилось, то выход в начало
//Нужно ли отослать ещё одно письмо (y)
printf("Send another email? [y/n]: "); read_string_from_console(&continue_y_n[0],
sizeof(continue_y_n) / sizeof(continue_y_n[0])); if (continue_y_n[0] != 'y' && continue_y_n[0] != 'Y')
break;
} |
|
printf("---------------------------------------------- |
\n"); |
printf("---------------------------------------------- |
\n"); |
} |
|
else |
|
printf("Unknown command\n"); |
|
} |
|
return EXIT_SUCCESS; |
|
}
56
Таблица 6. Общий сборочный файл «WinMakefile» / «LinuxMakefile»
WinMakefile
.PHONY : clean remake CC = gcc
CFLAGS = -O2 -std=c99 -Waggregate-return -Wall -Wbad-function-cast -Wcast-align -Wcast-qual \ -Wdeclaration-after-statement -Wdisabled-optimization -Wdouble-promotion -Werror \ -Wextra -Wfatal-errors -Wfloat-equal -Wframe-larger-than=5000 -Winit-self \ -Winline -Winvalid-pch -Wlarger-than=10000 -Wno-deprecated-declarations \ -Wmissing-include-dirs -Wnested-externs -Wno-aggressive-loop-optimizations \
-Wold-style-definition -Wpacked -Wpedantic -pedantic-errors -Wredundant-decls -Wshadow \ -Wstack-protector -Wstrict-aliasing -Wstrict-overflow=5 -Wstrict-prototypes \ -Wswitch-default -Wswitch-enum -Wundef -Wuninitialized -Wunknown-pragmas \ -Wunused-parameter -Wvla -Wwrite-strings -Wstack-usage=5000 -Wno-format \ -Wjump-misses-init -Wlogical-op -Wnormalized=nfkc -Wtrampolines \
-Wsync-nand -Wunsuffixed-float-constants -Wvector-operation-performance \ -fstack-protector-all -fstrict-overflow -MD -DSMTP_OPENSSL
all: ./smtp_lib/smtp_lib.o smtp_client.o
./smtp_lib/smtp_lib.o: ./smtp_lib/smtp_lib.h ./smtp_lib/smtp_lib.c
cd smtp_lib && make --file=WinMakefile && cd ../ && make remake --file=WinMakefile
.c.o: .c
$(CC) $(CFLAGS) -c -o $(?:.c=.o) $? -I./smtp_lib/
$(CC) $(CFLAGS) -o $(?:.c=.exe) $(?:.c=.o) ./smtp_lib/smtp_lib.o \ -L"C:\Program Files\OpenSSL-Win64\lib" -llibssl -llibcrypto -lWs2_32
clean:
del /s /q smtp_client.o smtp_client.d smtp_client.exe remake: clean all
LinuxMakefile
.PHONY : clean remake CC = gcc
CFLAGS = -O2 -std=c99 -Waggregate-return -Wall -Wbad-function-cast -Wcast-align -Wcast-qual \ -Wdeclaration-after-statement -Wdisabled-optimization -Wdouble-promotion -Werror \ -Wextra -Wfatal-errors -Wfloat-equal -Wframe-larger-than=5000 -Winit-self \ -Winline -Winvalid-pch -Wlarger-than=10000 -Wno-deprecated-declarations \ -Wmissing-include-dirs -Wnested-externs -Wno-aggressive-loop-optimizations \
-Wold-style-definition -Wpacked -Wpedantic -pedantic-errors -Wredundant-decls -Wshadow \ -Wstack-protector -Wstrict-aliasing -Wstrict-overflow=5 -Wstrict-prototypes \ -Wswitch-default -Wswitch-enum -Wundef -Wuninitialized -Wunknown-pragmas \ -Wunused-parameter -Wvla -Wwrite-strings -Wstack-usage=5000 -Wno-format \ -Wjump-misses-init -Wlogical-op -Wnormalized=nfkc -Wtrampolines \
-Wsync-nand -Wunsuffixed-float-constants -Wvector-operation-performance \ -fstack-protector-all -fstrict-overflow -MD -DSMTP_OPENSSL
all: ./smtp_lib/smtp_lib.o smtp_client.o
./smtp_lib/smtp_lib.o: ./smtp_lib/smtp_lib.h ./smtp_lib/smtp_lib.c
cd smtp_lib && make --file=LinuxMakefile && cd ../ && make remake --file=LinuxMakefile
.c.o: .c
$(CC) $(CFLAGS) -c -o $(?:.c=.o) $? -I./smtp_lib/
$(CC) $(CFLAGS) -o $(?:.c=) $(?:.c=.o) ./smtp_lib/smtp_lib.o -lssl -lcrypto
clean:
rm -rf smtp_client.o smtp_client.d smtp_client remake: clean all
57