Home Backend Development PHP Tutorial 'In-depth understanding of Nginx' notes: ngx_mail related structures

'In-depth understanding of Nginx' notes: ngx_mail related structures

Jul 30, 2016 pm 01:30 PM
mail protocol str

Nginx mail related module structure

ngx_mail_module_t

This is the abstract interface of the mail module, that is, the mail module-specific interface pointed to by the ctx member in ngx_module_t. Each mail module implements its own ngx_mail_module_t structure.

<code><span>typedef</span><span>struct</span> {
     <span>// POP3 STMP IMAP邮件模块提取出的通用接口</span>
    ngx_mail_protocol_t        *protocol;

     <span>// 用于创建main级别配置项的结构体</span><span>void</span>                       *(*create_main_conf)(ngx_conf_t *cf);

    <span>// 解析完main级别配置项后被回调的函数</span><span>char</span>                       *(*init_main_conf)(ngx_conf_t *cf, <span>void</span> *conf);

     <span>// 用于创建srv级别配置项的结构体</span><span>void</span>                       *(*create_srv_conf)(ngx_conf_t *cf);

    <span>// 根据具体模块处理srv下和main下同名的配置项</span><span>char</span>                       *(*merge_srv_conf)(ngx_conf_t *cf, <span>void</span> *prev,
                                      <span>void</span> *conf);
} ngx_mail_module_t;</code>
Copy after login

ngx_protocol_s

<code><span>typedef</span><span>struct</span> ngx_mail_protocol_s ngx_mail_protocol_t;

<span>// 四个POP3 SMTP IMAP等应用级别的邮件模块所需要实现的接口方法</span><span>typedef</span><span>void</span> (*ngx_mail_init_session_pt)(ngx_mail_session_t *s,
    ngx_connection_t *c);
<span>typedef</span><span>void</span> (*ngx_mail_init_protocol_pt)(ngx_event_t *rev);
<span>typedef</span><span>void</span> (*ngx_mail_auth_state_pt)(ngx_event_t *rev);
<span>typedef</span> ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s);


<span>struct</span> ngx_mail_protocol_s {
     <span>// 邮件模块名称</span>
    ngx_str_t                   name;

    <span>// 当前邮件模块中所要监听的最常用4个端口</span>
    in_port_t                   port[<span>4</span>];

    <span>// 邮件模块类型</span>
    ngx_uint_t                  type;

     <span>// 与客户端建立起TCP连接后的初始化方法</span>
    ngx_mail_init_session_pt    init_session;

    <span>// 接收、解析客户端请求的方法</span>
    ngx_mail_init_protocol_pt   init_protocol;

    <span>// 解析客户端邮件协议的接口方法</span>
    ngx_mail_parse_command_pt   parse_command;
    ngx_mail_auth_state_pt      auth_state;

     <span>// 当处理中没有遇到错误时,返回internal_server_error指定的响应给客户端</span>
    ngx_str_t                   internal_server_error;
    ngx_str_t                   cert_error;
    ngx_str_t                   no_cert;
};</code>
Copy after login

ngx_mail_session_t

After Nginx establishes a TCP connection with the client, it will call back the ngx_mail_init_connection function to initialize the email protocol. At this time, a core structure similar to ngx_http_request_t in HTTP requests will be created: ngx_mail_session_s.

<code><span>typedef</span><span>struct</span> {
    uint32_t                signature;         <span>/* "MAIL" */</span><span>// 下游客户端和Nginx之间的连接</span>
    ngx_connection_t       *connection;

     <span>// 可存需要向下游客户端发送的内容</span>
    ngx_str_t               out;

    <span>// 用于接收来自客户端的请求</span>
    ngx_buf_t              *buffer;

     <span>// 指向一个指针数组,保存着这个请求中各个邮件模块的上下文建构体指针</span><span>void</span>                  **ctx;

    <span>// main级别配置结构体组成的指针数组</span><span>void</span>                  **main_conf;

    <span>// srv级别配置结构体组成的指针数组</span><span>void</span>                  **srv_conf;

     <span>// 解析主机域名</span>
    ngx_resolver_ctx_t     *resolver_ctx;

     <span>// proxy上下文,用于Nginx双向透传客户端与邮件服务器间的通信</span>
    ngx_mail_proxy_ctx_t   *proxy;

     <span>// 表示与邮件服务器交互时,当前处于哪种状态</span>
    ngx_uint_t              mail_state;

     <span>// 邮件协议类型</span><span>unsigned</span>                protocol:<span>3</span>;

    <span>// 1:表示当前读或写操作需要被阻塞</span><span>unsigned</span>                blocked:<span>1</span>;

    <span>// 1:请求需要结束</span><span>unsigned</span>                quit:<span>1</span>;

    <span>// 一下三个标志位仅在解析具体邮件协议时由邮件框架使用</span><span>unsigned</span>                quoted:<span>1</span>;
    <span>unsigned</span>                backslash:<span>1</span>;
    <span>unsigned</span>                no_sync_literal:<span>1</span>;

    <span>// 当使用SSL协议时才有意义</span><span>unsigned</span>                starttls:<span>1</span>;
    <span>unsigned</span>                esmtp:<span>1</span>;

    <span>// 表示与认证服务器交互时的记录认证方式</span><span>unsigned</span>                auth_method:<span>3</span>;

    <span>// 1:表示认证服务器要求暂缓接收响应,Nginx会继续等待认证服务器的后续响应</span><span>unsigned</span>                auth_wait:<span>1</span>;

     <span>// 验证时的用户名</span>
    ngx_str_t               login;

    <span>// 验证时的密码</span>
    ngx_str_t               passwd;

     <span>// 作为Auth-Salt验证的信息</span>
    ngx_str_t               salt;

    <span>// 一下三个成员仅用于IMAP通信</span>
    ngx_str_t               tag;
    ngx_str_t               tagged_line;
    ngx_str_t               text;

     <span>// 当前连接上对应的Nginx服务器地址</span>
    ngx_str_t              *addr_text;

    <span>// 主机地址</span>
    ngx_str_t               host;

    <span>//一下四个成员仅用于SMTP通信</span>
    ngx_str_t               smtp_helo;
    ngx_str_t               smtp_from;
    ngx_str_t               smtp_to;

    ngx_str_t               cmd;

     <span>// 在于邮件服务器交互时,表示解析自邮件服务器的消息类型</span>
    ngx_uint_t              command;

    <span>// 存放来自下游客户端的邮件协议中的参数</span>
    ngx_array_t             args;

     <span>// 当前请求尝试访问服务器验证的次数</span>
    ngx_uint_t              login_attempt;

    <span>/* used to parse POP3/IMAP/SMTP command */</span>    ngx_uint_t              state;
    u_char                 *cmd_start;
    u_char                 *arg_start;
    u_char                 *arg_end;
    ngx_uint_t              literal_len;
} ngx_mail_session_t;</code>
Copy after login

Copyright Statement: Pain is just in your mind.

The above introduces the ngx_mail related structure in the notes of "In-depth Understanding of Nginx", including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to configure and use proxy protocol in nginx How to configure and use proxy protocol in nginx May 18, 2023 am 08:47 AM

When proxyprotocol is used in nginx, we know that nginx is a web server and proxy server. It generally works behind proxyserver or load balancing software (Haproxy, Amazon Elastic LoadBalancer (ELB)). The client first requests proxyserver or LSB load balancing software, and then to nginx Perform real web access. Because it has gone through multiple layers of software, some client information such as IP address, port number, etc. may be hidden, which is detrimental to our problem analysis and data statistics. Because for nginx, We want to be able to get real clients

PHP Mail Usage Guide: Simple and easy-to-understand tutorial for sending emails PHP Mail Usage Guide: Simple and easy-to-understand tutorial for sending emails Mar 28, 2024 pm 12:12 PM

PHP is a scripting language widely used for developing web applications. It provides many functions for handling email sending. This article will introduce you to how to use the email sending function in PHP and provide specific code examples. 1. Preparation Before using PHP to send emails, you first need to ensure that your server has been configured to send emails. Generally speaking, you need an SMTP server to send emails. You can use the SMTP server provided by your email provider, such as Gmail's SMTP

Python built-in type str source code analysis Python built-in type str source code analysis May 09, 2023 pm 02:16 PM

1The basic unit of Unicode computer storage is the byte, which is composed of 8 bits. Since English only consists of 26 letters plus a number of symbols, English characters can be stored directly in bytes. But other languages ​​(such as Chinese, Japanese, Korean, etc.) have to use multiple bytes for encoding due to the large number of characters. With the spread of computer technology, non-Latin character encoding technology continues to develop, but there are still two major limitations: no multi-language support: the encoding scheme of one language cannot be used in another language and there is no unified standard: for example There are many encoding standards in Chinese such as GBK, GB2312, GB18030, etc. Since the encoding methods are not unified, developers need to convert back and forth between different encodings, and many errors will inevitably occur.

How to use Java's built-in mail API to implement email sending function How to use Java's built-in mail API to implement email sending function May 11, 2023 pm 12:49 PM

Requirements: To send emails, use the jdk native API - java.mail to implement the email function. The following code can send emails, taking qq mailbox as an example packagecom.example.demo.emailInfo; importjavax.mail.Message; importjavax.mail.MessagingException; importjavax.mail.Session;importjavax.mail.Transport;importjavax.mail.internet.Inte

How to configure SpringBoot Mail mail task How to configure SpringBoot Mail mail task May 12, 2023 pm 10:37 PM

1. Introduction Sending emails should be one of the essential functions of the website, such as registration verification, forgotten password or sending marketing information to users. In the early days, we would use JavaMail related APIs to write relevant codes for sending emails. Later, spring withdrew from JavaMailSender, which simplified the process of sending emails. Later, springboot encapsulated this and now spring-boot-starter- mail. 2. Simple use 1. Add the spring-boot-starter-mail package to the pom package to configure the pom package to reference org.springframework.bootspring-

What are the similarities and differences between __str__ and __repr__ in Python? What are the similarities and differences between __str__ and __repr__ in Python? Apr 29, 2023 pm 07:58 PM

What are the similarities and differences between __str__ and __repr__? We all know the representation of strings. Python's built-in function repr() can express objects in the form of strings to facilitate our identification. This is the "string representation". repr() obtains the string representation of an object through the special method __repr__. If __repr__ is not implemented, when we print an instance of a vector to the console, the resulting string may be. >>>classExample:pass>>>print(str(Example()))>>>

Detailed explanation of how to use the mail command mail in CentOS Detailed explanation of how to use the mail command mail in CentOS Jan 05, 2024 pm 10:57 PM

1. Basic syntax of mail h|headers displays the current mail list l|list displays the currently supported command list?|help displays multiple command parameters for viewing the mail list Usage d Delete the current mail and move the pointer down. d1-100 delete emails 1 to 100 t|type|more|p|pagenum read a certain email n|next|{fill in nothing} read the content of the next email where the current pointer is; when reading, press space key is to turn the page, and pressing the Enter key is to move down one line n|next|{fill in nothing}num read a certain email f|fromnum view the email header top display the email header of the email where the current pointer is located file|folder display

Understanding PHP Mail: Workflow Analysis of Email Sending Understanding PHP Mail: Workflow Analysis of Email Sending Mar 28, 2024 am 08:39 AM

PHPMail: Analysis of the workflow of email sending, specific code examples are needed. With the popularity of the Internet and the widespread use of email, email sending has become an indispensable part of our daily life and work. In website development, we often need to send emails through code to allow users to receive important notifications or verification information. As a scripting language widely used in website development, PHP also provides a convenient email sending function. This article will introduce the workflow of PHPMail and give specific code examples.

See all articles