1 /* **************************************************************
2 Copyright (C) 2018 Siemens AG
3 Author: Gaurav Mishra <mishra.gaurav@siemens.com>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 ************************************************************** */
18 /**
19 * \file
20 * \brief Format email body for a list of agents and their status
21 *
22 * The file can further be enhanced for different formats like HTML, XML, etc.
23 */
24
25 #include <agent.h>
26 #include <emailformatter.h>
27
28 /**
29 * @brief Format rows as plain text
30 *
31 * @param rows rows of type agent_info
32 * @param fossy_url host url of fossology
33 * @return rows in plain text format
34 */
email_format_text(GPtrArray * rows,gchar * fossy_url)35 const gchar* email_format_text(GPtrArray *rows, gchar *fossy_url)
36 {
37 guint i;
38 GString* ret = g_string_new("");
39 if(rows == NULL)
40 {
41 return "";
42 }
43 g_string_append(ret, "Agents run:\n");
44 g_string_append(ret, " Job ID => Agent Name => Status => Link\n");
45 for (i = 0; i < rows->len; i++)
46 {
47 agent_info *data = (agent_info *)g_ptr_array_index(rows, i);
48 g_string_append_printf(ret, "%10d => %15s => ", data->id, data->agent->str);
49 if (data->status == TRUE)
50 {
51 g_string_append(ret, " COMPLETED\n");
52 }
53 else
54 {
55 g_string_append_printf(ret, "%10s => http://%s?mod=showjobs&job=%d\n",
56 "FAILED", fossy_url, data->id);
57 }
58 g_string_free(data->agent, TRUE);
59 }
60 return ret->str;
61 }
62
63