summary refs log tree commit diff stats
path: root/plugins/mailcheck/mailcheck.c
blob: ad197eaeb7ee40614da37344cc73c511909f64eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* HexChat 2.0 plugin: Mail checker */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "hexchat-plugin.h"


static hexchat_plugin *ph;	/* plugin handle */

static int
mail_items(char *file)
{
	FILE *fp;
	int items;
	char buf[512];

	fp = fopen(file, "r");
	if(!fp)
		return 1;

	items = 0;
	while(fgets(buf, sizeof buf, fp))
	{
		if(!strncmp(buf, "From ", 5))
			items++;
	}
	fclose(fp);

	return items;
}

static void
xchat_mail_check (void)
{
	static int last_size = -1;
	int size;
	struct stat st;
	char buf[512];
	char *maildir;

	maildir = getenv("MAIL");
	if(!maildir)
	{
		snprintf (buf, sizeof(buf), "/var/spool/mail/%s", getenv("USER"));
		maildir = buf;
	}

	if(stat(maildir, &st) < 0)
		return;

	size = st.st_size;

	if(last_size == -1)
	{
		last_size = size;
		return;
	}

	if(size > last_size)
	{
		hexchat_printf(ph,
	"-\0033-\0039-\017\tYou have new mail (%d messages, %d bytes total).",
				mail_items(maildir), size);
	}

	last_size = size;
}

static int timeout_cb(void *userdata)
{
	xchat_mail_check();

	return 1;
}

int hexchat_plugin_init(hexchat_plugin *plugin_handle,
				char **plugin_name, char **plugin_desc, char **plugin_version,
				char *arg)
{
	ph = plugin_handle;

	*plugin_name = "MailCheck";
	*plugin_desc = "Checks your mailbox every 30 seconds";
	*plugin_version = "0.1";

	hexchat_hook_timer(ph, 30000, timeout_cb, 0);

	return 1;
}
href='#n66'>66 67 68 69 70 71 72 73 74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113






                                                                                                                



                                                 










                                                                                                    
                                            
                   






                                                                                                  




                                                                                                                                                                                    
                                          
                 

                                                                                                                                                                                    
                                          
                 
                                       
                                                                              

                                                                             
                   
                                                                            

                                                                             
                   












                                                                                    









                                                                                                    

                         












                                                                                  









                                                                                                    

                         
              



                                                     

                                            




                                                              
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{5A0F4962-E670-4DA2-9E45-52CC47F26E2F}</ProjectGuid>
    <RootNamespace>installer</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
    <PlatformToolset>WDK7</PlatformToolset>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
    <PlatformToolset>WDK7</PlatformToolset>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    <Import Project="..\hexchat.props" />
  </ImportGroup>
  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    <Import Project="..\hexchat.props" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <OutDir>$(SolutionDir)build\$(PlatformName)\bin\</OutDir>
    <IntDir>$(SolutionDir)build\$(PlatformName)\obj\$(ProjectName)\</IntDir>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <OutDir>$(SolutionDir)build\$(PlatformName)\bin\</OutDir>
    <IntDir>$(SolutionDir)build\$(PlatformName)\obj\$(ProjectName)\</IntDir>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <PreBuildEvent>
      <Command>echo [Setup] &gt; "$(OutDir)\hexchat-x86.iss"
echo WizardImageFile="$(ProjectDir)\wizardimage.bmp" &gt;&gt; "$(OutDir)\hexchat-x86.iss"
echo WizardSmallImageFile="$(ProjectDir)\wizardsmallimage.bmp" &gt;&gt; "$(OutDir)\hexchat-x86.iss"
"$(OutDir)\version" -a &gt;&gt; "$(OutDir)\hexchat-x86.iss"
"$(OutDir)\version" -v &gt;&gt; "$(OutDir)\hexchat-x86.iss"
"$(OutDir)\version" -i &gt;&gt; "$(OutDir)\hexchat-x86.iss"
"$(OutDir)\version" -o &gt;&gt; "$(OutDir)\hexchat-x86.iss"
echo SetupIconFile="$(SolutionDir)\..\hexchat.ico" &gt;&gt; "$(OutDir)\hexchat-x86.iss"
type hexchat-x86.skel.iss &gt;&gt; "$(OutDir)\hexchat-x86.iss"
"$(ProgramFiles)\Inno Setup 5\compil32" /cc "$(OutDir)\hexchat-x86.iss"</Command>
    </PreBuildEvent>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
    <PreBuildEvent>
      <Command>echo [Setup] &gt; "$(OutDir)\hexchat-x64.iss"
echo WizardImageFile="$(ProjectDir)\wizardimage.bmp" &gt;&gt; "$(OutDir)\hexchat-x64.iss"
echo WizardSmallImageFile="$(ProjectDir)\wizardsmallimage.bmp" &gt;&gt; "$(OutDir)\hexchat-x64.iss"
"$(OutDir)\version" -a &gt;&gt; "$(OutDir)\hexchat-x64.iss"
"$(OutDir)\version" -v &gt;&gt; "$(OutDir)\hexchat-x64.iss"
"$(OutDir)\version" -i &gt;&gt; "$(OutDir)\hexchat-x64.iss"
"$(OutDir)\version" -o &gt;&gt; "$(OutDir)\hexchat-x64.iss"
echo SetupIconFile="$(SolutionDir)\..\hexchat.ico" &gt;&gt; "$(OutDir)\hexchat-x64.iss"
type hexchat-x64.skel.iss &gt;&gt; "$(OutDir)\hexchat-x64.iss"
"$(ProgramFiles)\Inno Setup 5\compil32" /cc "$(OutDir)\hexchat-x64.iss"</Command>
    </PreBuildEvent>
  </ItemDefinitionGroup>
  <ItemGroup>
    <None Include="watercolorlite-blue.cjstyles" />
    <None Include="watercolorlite-green.cjstyles" />
    <None Include="wizardimage.bmp" />
    <None Include="wizardsmallimage.bmp" />
    <None Include="hexchat-x64.skel.iss" />
    <None Include="hexchat-x86.skel.iss" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>