Coverage Report

Created: 2026-09-01 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/lib-sieve/sieve-smtp.c
Line
Count
Source
1
/* Copyright (c) Pigeonhole authors, see top-level COPYING file */
2
#include "lib.h"
3
#include "smtp-address.h"
4
5
#include "sieve-common.h"
6
#include "sieve-smtp.h"
7
8
struct sieve_smtp_context {
9
  const struct sieve_script_env *senv;
10
  void *handle;
11
12
  bool sent:1;
13
};
14
15
bool sieve_smtp_available(const struct sieve_script_env *senv)
16
0
{
17
0
  return (senv->smtp_start != NULL && senv->smtp_add_rcpt != NULL &&
18
0
    senv->smtp_send != NULL && senv->smtp_finish != NULL);
19
0
}
20
21
struct sieve_smtp_context *
22
sieve_smtp_start(const struct sieve_script_env *senv,
23
     const struct smtp_address *mail_from)
24
0
{
25
0
  struct sieve_smtp_context *sctx;
26
0
  void *handle;
27
28
0
  if (!sieve_smtp_available(senv))
29
0
    return NULL;
30
31
0
  handle = senv->smtp_start(senv, mail_from);
32
0
  i_assert( handle != NULL );
33
34
0
  sctx = i_new(struct sieve_smtp_context, 1);
35
0
  sctx->senv = senv;
36
0
  sctx->handle = handle;
37
38
0
  return sctx;
39
0
}
40
41
void sieve_smtp_add_rcpt(struct sieve_smtp_context *sctx,
42
       const struct smtp_address *rcpt_to)
43
0
{
44
0
  i_assert(!sctx->sent);
45
0
  sctx->senv->smtp_add_rcpt(sctx->senv, sctx->handle, rcpt_to);
46
0
}
47
48
struct ostream *sieve_smtp_send(struct sieve_smtp_context *sctx)
49
0
{
50
0
  i_assert(!sctx->sent);
51
0
  sctx->sent = TRUE;
52
53
0
  return sctx->senv->smtp_send(sctx->senv, sctx->handle);
54
0
}
55
56
struct sieve_smtp_context *
57
sieve_smtp_start_single(const struct sieve_script_env *senv,
58
      const struct smtp_address *rcpt_to,
59
      const struct smtp_address *mail_from,
60
      struct ostream **output_r)
61
0
{
62
0
  struct sieve_smtp_context *sctx;
63
64
0
  sctx = sieve_smtp_start(senv, mail_from);
65
0
  sieve_smtp_add_rcpt(sctx, rcpt_to);
66
0
  *output_r = sieve_smtp_send(sctx);
67
68
0
  return sctx;
69
0
}
70
71
void sieve_smtp_abort(struct sieve_smtp_context *sctx)
72
0
{
73
0
  const struct sieve_script_env *senv = sctx->senv;
74
0
  void *handle = sctx->handle;
75
76
0
  i_free(sctx);
77
0
  i_assert(senv->smtp_abort != NULL);
78
0
  senv->smtp_abort(senv, handle);
79
0
}
80
81
int sieve_smtp_finish(struct sieve_smtp_context *sctx, const char **error_r)
82
0
{
83
0
  const struct sieve_script_env *senv = sctx->senv;
84
0
  void *handle = sctx->handle;
85
86
  i_free(sctx);
87
0
  return senv->smtp_finish(senv, handle, error_r);
88
0
}